def __call__(self, packet): device = Device.get_or_create(packet.data['packet_type'], packet.data['sub_type'], packet.data['id']) for series_name, value_name in self.mapping.items(): series = Series.get_or_create(name=series_name) db.session.commit() try: val = packet.data[value_name] except KeyError: self.log.error("Failed to find %s in packet. Key list: %r" % (value_name, sorted(packet.data.keys()))) return id_ = packet.data.get('id') self.log.info("ID=%s, %s=%s, Device ID=%s, Series ID=%s" % (id_, series_name, val, device.id, series.id)) DataPoint.record(series, device, val) db.session.commit()
def __call__(self, packet): device = Device.get_or_create(packet.data['packet_type'], packet.data['sub_type'], packet.data['id']) for series_name, value_name in self.mapping.items(): series = Series.get_or_create(name=series_name) db.session.commit() try: val = packet.data[value_name] except KeyError: self.log.error("Failed to find %s in packet. Key list: %r" % ( value_name, sorted(packet.data.keys()))) return id_ = packet.data.get('id') self.log.info("ID=%s, %s=%s, Device ID=%s, Series ID=%s" % ( id_, series_name, val, device.id, series.id)) DataPoint.record(series, device, val) db.session.commit()
def test_record(self): DataPoint.record(self.series, self.device, 100)