Пример #1
0
    def process_data(self, data, bucket):

        # Main transformation data container
        bucket.tdata = Bunch()

        # Merge request parameters (GET and POST) and url matches, in this order
        bucket.tdata.update(flatten_request_args(bucket.request.args))
        bucket.tdata.update(self.options.match)

        # When receiving a firmware request, run forwarding callback immediately
        is_firmware_request = 'slot' in bucket.tdata and bucket.tdata.slot == 'firmware'
        if is_firmware_request:
            bucket.data = data
            return self.options.callback(bucket)

        # Without any data received, run forwarding callback immediately
        if data is None:
            return self.options.callback(bucket)

        if type(data) is not types.ListType:
            data = [data]

        for item in data:
            # TODO: Apply this to telemetry values only!
            # FIXME: This is a hack
            if not bucket.request.path.endswith('event') and not bucket.request.path.endswith('firmware'):
                convert_floats(item, integers=['time'])
            self.propagate_single(item, bucket)

        message = 'Received #{number} readings'.format(number=len(data))
        bucket.request.messages.append({'type': 'info', 'message': message})
Пример #2
0
    def data_to_float(self, data):
        return convert_floats(data)

        for key, value in data.iteritems():

            # Sanity checks
            if type(value) in types.StringTypes:
                continue

            if value is None:
                data[key] = None
                continue

            # Convert to float
            try:
                data[key] = float(value)
            except (TypeError, ValueError) as ex:
                log.warn(u'Measurement "{key}: {value}" float conversion failed: {ex}', key=key, value=value, ex=ex)