diff options
author | Random Hacker <random_hacker@xapek.org> | 2010-08-18 23:46:18 +0200 |
---|---|---|
committer | Random Hacker <random_hacker@xapek.org> | 2010-08-18 23:46:18 +0200 |
commit | de1bbfc28dd9dcc76f8d4a34e1524b1f3a594fdb (patch) | |
tree | 0281f29ff36bea9c4f981ca2756461fe32f0d2e4 /ebus/model/sql.py | |
parent | 7ff580a6fe60f7e3ea160f7b181ff0fa934453ce (diff) | |
download | ebus-alt-de1bbfc28dd9dcc76f8d4a34e1524b1f3a594fdb.tar.gz ebus-alt-de1bbfc28dd9dcc76f8d4a34e1524b1f3a594fdb.zip |
running with pgsql
Diffstat (limited to 'ebus/model/sql.py')
-rw-r--r-- | ebus/model/sql.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/ebus/model/sql.py b/ebus/model/sql.py index 630e31c..de13239 100644 --- a/ebus/model/sql.py +++ b/ebus/model/sql.py @@ -26,7 +26,7 @@ class Value(ModelBase): __tablename__ = 'value' id = Column(Integer, primary_key=True) - timestamp = Column(DateTime) + timestamp = Column(DateTime,index=True) sensor_id = Column(Integer, ForeignKey("sensor.id")) sensor = relationship(Sensor, backref=backref('values', order_by=timestamp)) @@ -84,22 +84,25 @@ class EbusSQL(object): def get_values(self,packet): packet_description = packet.get_packet_description() - sensor_name = str(packet._get_source_name()) - sensor = self.session.query(Sensor) \ - .filter(Sensor.name==sensor_name).first() - if sensor is None: - sensor = Sensor(sensor_name) - self.session.add(sensor) - + packet_source_name = packet.get_source_name() + packet_name = packet.name() for field in packet_description.fields.iterchildren(): try: name = field.get("name") offset = int(field.get("offset")) if not name: continue - elif field.tag == "bit": + + sensor_name = "%s.%s.%s" % (packet_source_name, packet_name, name ) + sensor = self.session.query(Sensor) \ + .filter(Sensor.name==sensor_name).first() + if sensor is None: + sensor = Sensor(sensor_name) + self.session.add(sensor) + + if field.tag == "bit": yield ValueInt(sensor, \ - model.Bit(name, offset).value(packet.data)) + model.Bit(name, offset).value(packet.data) and 1 or 0) elif field.tag == "byte": yield ValueInt(sensor, \ model.Byte(name, offset).value(packet.data)) |