Fails the measurement for this device.
        :param measurementId: the measurement name.
        :param deviceId: the device name.
        :return: 200 if
321664
def put(self, measurementId, deviceId):
        
        payload = request.get_json()
        failureReason = json.loads(payload).get('failureReason') if payload is not None else None
        logger.warning('Failing measurement ' + measurementId + ' for ' + deviceId + ' because ' + str(failureReason))
        if self._measurementController.failMeasurement(measurementId, deviceId, failureReason=failureReason):
            logger.warning('Failed measurement ' + measurementId + ' for ' + deviceId)
            return None, 200
        else:
            logger.error('Unable to fail measurement ' + measurementId + ' for ' + deviceId)
            return None, 404
860217
def id(self, id):
        

        if id is None:
            raise ValueError("Invalid value for `id`, must not be `None`")
        if len(id) > 255:
            raise ValueError("Invalid value for `id`, length must be less than `255`")

        self._id = id
1291892
def getDataHandler(self, measurementId, deviceId):
        
        am = next((m for m in self.activeMeasurements if m.id == measurementId), None)
        if am is None:
            return None, None
        else:
            device = self.deviceController.getDevice(deviceId)
            if device is None:
                return None, None
            else:
                return am, device.dataHandler
1149693
def _check_device_number(self, devices):
        '''
        '''

        if len(devices) < 2 or len(devices) > 4:
            msg = 'The number of devices to cluster is not supported.'
            raise ClusterNotSupported(msg)
1001620
def should_send(measure)
      op = op_for_measurement(measure)
      return measure.value > 0 if op == ADD_OP
      return !measure.value.nan? if op == MAX_OP

      false
    end
1373258
def store(self, measurement):
        
        os.makedirs(self._getPathToMeasurementMetaDir(measurement.idAsPath), exist_ok=True)
        output = marshal(measurement, measurementFields)
        with open(self._getPathToMeasurementMetaFile(measurement.idAsPath), 'w') as outfile:
            json.dump(output, outfile)
        return output
165485
def _validate_measure_count(self, times):
        
        if not self.min_measures <= times <= self.max_measures:
            raise ParameterValidationError(
                "{times} is not within the borders defined in the class".format(
                    times=times
                )
            )
1084622
def set_value(self, value):
        
        v = 0
        measure_unit = 'px'
        try:
            v = int(float(value.replace('px', '')))
        except ValueError:
            try:
                v = int(float(value.replace('%', '')))
                measure_unit = '%'
            except ValueError:
                pass
        self.numInput.set_value(v)
        self.dropMeasureUnit.set_value(measure_unit)
337928
def delete(self, measurementId):
        
        message, count, deleted = self._measurementController.delete(measurementId)
        if count == 0:
            return message, 404
        elif deleted is None:
            return message, 500
        else:
            return deleted, 200
1003638
def start(self, measurementId, durationInSeconds=None):
        
        logger.info(">> measurement " + measurementId +
                    ((" for " + str(durationInSeconds)) if durationInSeconds is not None else " until break"))
        self.failureCode = None
        self.measurementOverflowed = False
        self.dataHandler.start(measurementId)
        self.breakRead = False
        self.startTime = time.time()
        self.doInit()
        # this must follow doInit because doInit sets status to INITIALISED
        self.status = RecordingDeviceStatus.RECORDING
        elapsedTime = 0
        try:
            self._sampleIdx = 0
            while True:
                logger.debug(measurementId + " provideData ")
                self.dataHandler.handle(self.provideData())
                elapsedTime = time.time() - self.startTime
                if self.breakRead or durationInSeconds is not None and elapsedTime > durationInSeconds:
                    logger.debug(measurementId + " breaking provideData")
                    self.startTime = 0
                    break
        except:
            self.status = RecordingDeviceStatus.FAILED
            self.failureCode = str(sys.exc_info())
            logger.exception(measurementId + " failed")
        finally:
            expectedSamples = self.fs * (durationInSeconds if durationInSeconds is not None else elapsedTime)
            if self._sampleIdx < expectedSamples:
                self.status = RecordingDeviceStatus.FAILED
                self.failureCode = "Insufficient samples " + str(self._sampleIdx) + " for " + \
                                   str(elapsedTime) + " second long run, expected " + str(expectedSamples)
            self._sampleIdx = 0
            if self.measurementOverflowed:
                self.status = RecordingDeviceStatus.FAILED
                self.failureCode = "Measurement overflow detected"
            if self.status == RecordingDeviceStatus.FAILED:
                logger.error("<< measurement " + measurementId + " - FAILED - " + self.failureCode)
            else:
                self.status = RecordingDeviceStatus.INITIALISED
                logger.info("<< measurement " + measurementId + " - " + self.status.name)
            self.dataHandler.stop(measurementId, self.failureCode)
            if self.status == RecordingDeviceStatus.FAILED:
                logger.warning("Reinitialising device after measurement failure")
                self.doInit()
119
def validate(self):
    """"""
    # PASS if all our validators return True, otherwise FAIL.
    try:
      if all(v(self.measured_value.value) for v in self.validators):
        self.outcome = Outcome.PASS
      else:
        self.outcome = Outcome.FAIL
      return self
    except Exception as e:  # pylint: disable=bare-except
      _LOG.error('Validation for measurement %s raised an exception %s.',
                 self.name, e)
      self.outcome = Outcome.FAIL
      raise
    finally:
      if self._cached:
        self._cached['outcome'] = self.outcome.name
363633
def async_get_measurements(self, uid, fields='*'):
        """"""
        return (yield from self._get('/pods/{}/measurements'.format(uid),
                                     fields=fields))[0]
144677
public boolean notifyMeasurementEnding(Iterable<Measurement> measurements) throws IOException {
    println(controlLogMessageRenderer.render(new StopMeasurementLogMessage(measurements)));
    for (Measurement measurement : measurements) {
      println(String.format("I got a result! %s: %f%s%n", measurement.description(),
          measurement.value().magnitude() / measurement.weight(), measurement.value().unit()));
    }
    writer.flush();
    return shouldKeepMeasuring();
  }
1028698
def device_state(device_id):
    
    if device_id not in devices:
        return jsonify(success=False)
    return jsonify(state=devices[device_id].state)
1045650
def patch(self, measurementId):
        
        data = request.get_json()
        if data is not None:
            logger.debug('Received payload for ' + measurementId + ' - ' + str(data))
            if self._measurementController.editMeasurement(measurementId, data):
                return None, 200
            else:
                logger.warning('Unable to edit payload ' + measurementId)
                return None, 404
        else:
            logger.error('Invalid data payload received ' + measurementId)
            return None, 400
629461
def enrolled_device_id(self, enrolled_device_id):
        
        if enrolled_device_id is None:
            raise ValueError("Invalid value for `enrolled_device_id`, must not be `None`")
        if enrolled_device_id is not None and not re.search('^[A-Za-z0-9]{32}', enrolled_device_id):
            raise ValueError("Invalid value for `enrolled_device_id`, must be a follow pattern or equal to `/^[A-Za-z0-9]{32}/`")

        self._enrolled_device_id = enrolled_device_id
727506
def get(self, measurementId):
        
        logger.info('Loading raw data for ' + measurementId)
        measurement = self._measurementController.getMeasurement(measurementId, MeasurementStatus.COMPLETE)
        if measurement is not None:
            if measurement.inflate():
                data = {
                    name: {
                        'raw': {
                            'x': self._jsonify(data.raw('x')),
                            'y': self._jsonify(data.raw('y')),
                            'z': self._jsonify(data.raw('z'))
                        },
                        'vibration': {
                            'x': self._jsonify(data.vibration('x')),
                            'y': self._jsonify(data.vibration('y')),
                            'z': self._jsonify(data.vibration('z'))
                        },
                        'tilt': {
                            'x': self._jsonify(data.tilt('x')),
                            'y': self._jsonify(data.tilt('y')),
                            'z': self._jsonify(data.tilt('z'))
                        }
                    }
                    for name, data in measurement.data.items()
                }
                return data, 200
            else:
                return None, 404
        else:
            return None, 404