summaryrefslogtreecommitdiff
path: root/ebus/web
diff options
context:
space:
mode:
authorYves <yvesf-git@xapek.org>2010-06-27 20:25:50 +0200
committerYves <yvesf-git@xapek.org>2010-06-27 20:25:50 +0200
commit7a57ef77a3093f480ab414400d44d546f283d81c (patch)
treebd1a42cf3b4366539ba44c5e70f451f77c05a758 /ebus/web
parent155abf125c0b40483d404bf7aa10b7800398ac66 (diff)
downloadebus-alt-7a57ef77a3093f480ab414400d44d546f283d81c.tar.gz
ebus-alt-7a57ef77a3093f480ab414400d44d546f283d81c.zip
Value class inheritanced by StringValue, IntValue FloatValue
Diffstat (limited to 'ebus/web')
-rw-r--r--ebus/web/model.py52
1 files changed, 43 insertions, 9 deletions
diff --git a/ebus/web/model.py b/ebus/web/model.py
index e9fc04c..04b15ed 100644
--- a/ebus/web/model.py
+++ b/ebus/web/model.py
@@ -19,8 +19,7 @@ class Sensor(ModelBase):
def __repr__(self):
return "<Sensor('%s','%s','%s')>" % (self.id, self.name, self.description)
-
-
+# http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#inheritance-configuration
class Value(ModelBase):
__tablename__ = 'value'
@@ -29,17 +28,52 @@ class Value(ModelBase):
sensor_id = Column(Integer, ForeignKey("sensor.id"))
sensor = relationship(Sensor, backref=backref('values', order_by=timestamp))
- value_float = Column(Float(precision=4))
- value_int = Column(Integer)
- value_string = Column(String)
+ discriminator = Column('type', String(50))
+ __mapper_args__ = {'polymorphic_on': discriminator}
- def __init__(self, sensor, value_float=None, value_int=None, value_string=None, timestamp=datetime.now()):
+ def __init__(self, sensor, timestamp=datetime.now()):
self.timestamp = timestamp
self.sensor = sensor
- self.value_float = value_float
- self.value_int = value_int
- self.value_string = value_string
def __repr__(self):
return "<Value('%s','%s','%s','%s'>" % (self.id, self.sensor, self.value, self.timestamp)
+ def value(self):
+ raise NotImplementedException()
+
+class ValueInt(Value):
+ __mapper_args__ = {'polymorphic_identity': 'value'}
+ value_float = Column(Float(precision=4))
+
+ def __init__(self, sensor, value, timestamp=datetime.now()):
+ Value.__init__(self, sensor, timestamp)
+ self.value_float = value
+
+ def value(self):
+ return self.value_float
+
+class ValueInt(Value):
+ __mapper_args__ = {'polymorphic_identity': 'value'}
+ value_int = Column(Integer)
+
+ def __init__(self, sensor, value, timestamp=datetime.now()):
+ Value.__init__(self, sensor, timestamp)
+ self.value_int = value
+
+ def value(self):
+ return self.value_int
+
+class ValueString(Value):
+ __mapper_args__ = {'polymorphic_identity': 'value'}
+ value_string = Column(String)
+
+ def __init__(self, sensor, value, timestamp=datetime.now()):
+ Value.__init__(self, sensor, timestamp)
+ self.value_int = value
+
+ def value(self):
+ return self.value_string
+
+
+
+