Beispiel #1
0
    def process_entry(self, entry):
        attr_map = {
            'fahrenheit': 'Temperature',
            'humidity': 'Humidity',
            'pressure': 'Pressure',
            'pm10_env': 'PM1.0 (ATM)',
            'pm25_env': 'PM2.5 (ATM)',
            'pm100_env': 'PM10.0 (ATM)',
            'pm10_standard': 'PM1.0 (CF=1)',
            'pm25_standard': 'PM2.5 (CF=1)',
            'pm100_standard': 'PM10.0 (CF=1)',
            'particles_03um': '0.3um',
            'particles_05um': '0.5um',
            'particles_10um': '1.0um',
            'particles_25um': '2.5um',
            'particles_50um': '5.0um',
            'particles_100um': '10.0um',
        }

        for data in entry.payload:
            for attr, key in attr_map.items():
                if key in data:
                    setattr(entry, attr, data[key])

        entry.timestamp = parse_datetime(entry.payload[0].get('created_at'))
        entry = self.copy_fields(entry)
        return super().process_entry(entry)
Beispiel #2
0
    def process_entry(self, entry):
        attr_map = {
            # TODO: Figure out the rest of these.
            'celcius': 'temp',
            'humidity': 'rh',
        }

        for attr, key in attr_map.items():
            setattr(entry, attr, entry.payload[key])

        entry.timestamp = parse_datetime(entry.payload['timestamp'])
        return super().process_entry(entry)
Beispiel #3
0
    def process_entry(self, entry):
        attr_map = {
            'celcius': 'AT(C)',
            'humidity': 'RH(%)',
            'pressure': 'BP(mmHg)',
            'pm25': 'ConcRT(ug/m3)',
        }

        for attr, key in attr_map.items():
            setattr(entry, attr, entry.payload[key])

        entry.timestamp = parse_datetime(entry.payload['Time'])
        return super().process_entry(entry)
Beispiel #4
0
    def get_feed(self, channel, **options):
        try:
            response = json.loads(channel.get(options=options))
        except json.decoder.JSONDecodeError:
            return []

        for entry in response['feeds']:
            data = dict(entry_id=entry['entry_id'],
                        created_at=parse_datetime(entry['created_at']),
                        **dict(((response['channel'][f'field{x}'],
                                 entry[f'field{x}']) for x in range(1, 9))))

            yield data
Beispiel #5
0
 def create_entry(self, payload, sensor=None):
     timestamp = parse_datetime(payload['Time'])
     if self.entries.filter(timestamp=timestamp).exists():
         raise ValidationError(
             'An entry for this timestamp has already been recorded.')
     return super().create_entry(payload=payload, sensor=sensor)