summaryrefslogtreecommitdiff
path: root/ebus/web/model.py
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2010-06-09 11:14:18 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2010-06-09 11:14:18 +0000
commitfeebdc2e14426921a585c31c5279886bca3e2eca (patch)
tree82fbb3700d5d43d1d302d95c639d0d540b7bcabb /ebus/web/model.py
parent602182ed488c9713d793206f6da2f3758051c32d (diff)
downloadebus-alt-feebdc2e14426921a585c31c5279886bca3e2eca.tar.gz
ebus-alt-feebdc2e14426921a585c31c5279886bca3e2eca.zip
foo
git-svn-id: http://10.2.2.13/svn/common/ebus@1676 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
Diffstat (limited to 'ebus/web/model.py')
-rw-r--r--ebus/web/model.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/ebus/web/model.py b/ebus/web/model.py
new file mode 100644
index 0000000..b8405dc
--- /dev/null
+++ b/ebus/web/model.py
@@ -0,0 +1,41 @@
+from datetime import datetime
+from sqlalchemy import Column, Integer, Float, DateTime, String, ForeignKey
+from sqlalchemy.orm import relationship, backref
+from sqlalchemy.ext.declarative import declarative_base
+
+Base = declarative_base()
+
+class Sensor(Base):
+ __tablename__ = 'sensor'
+
+ id = Column(Integer, primary_key=True)
+ name = Column(String)
+ description = Column(String, default="")
+
+ def __init__(self, name, description=""):
+ self.name = name
+ self.description = description
+
+ def __repr__(self):
+ return "<Sensor('%s','%s','%s')>" % (self.id, self.name, self.description)
+
+
+
+
+class Value(Base):
+ __tablename__ = 'value'
+
+ id = Column(Integer, primary_key=True)
+ timestamp = Column(DateTime)
+ sensor_id = Column(Integer, ForeignKey("sensor.id"))
+ sensor = relationship(Sensor, backref=backref('values', order_by=timestamp))
+ value = Column(Float(precision=4))
+
+ def __init__(self, sensor, value, timestamp=datetime.now()):
+ self.sensor = sensor
+ self.value = value
+ self.timestamp = timestamp
+
+ def __repr__(self):
+ return "<Value('%s','%s','%s','%s'>" % (self.id, self.sensor, self.value, self.timestamp)
+