diff options
author | yvesf <yvesf-git@xapek.org> | 2011-06-25 17:14:05 +0200 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2011-06-25 17:14:05 +0200 |
commit | a85541d9f7622813ec98bf042164414edc1fb366 (patch) | |
tree | 8041b06bb1681642777244d1955356bd63af25b7 /ebus/web/model.py | |
parent | c15f4a600ddc3155b761230b84d78458e08bdc40 (diff) | |
download | ebus-alt-a85541d9f7622813ec98bf042164414edc1fb366.tar.gz ebus-alt-a85541d9f7622813ec98bf042164414edc1fb366.zip |
web -> bottle
Diffstat (limited to 'ebus/web/model.py')
-rw-r--r-- | ebus/web/model.py | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/ebus/web/model.py b/ebus/web/model.py deleted file mode 100644 index 7e21e82..0000000 --- a/ebus/web/model.py +++ /dev/null @@ -1,79 +0,0 @@ -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 - -ModelBase = declarative_base() - -class Sensor(ModelBase): - __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) - -# http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#inheritance-configuration -class Value(ModelBase): - __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)) - - discriminator = Column('type', String(50)) - __mapper_args__ = {'polymorphic_on': discriminator} - - def __init__(self, sensor, timestamp=datetime.now()): - self.timestamp = timestamp - self.sensor = sensor - - def __repr__(self): - return "<Value('%s','%s','%s','%s'>" % (self.id, self.sensor, self.value, self.timestamp) - - def value(self): - raise NotImplementedException() - -class ValueFloat(Value): - __mapper_args__ = {'polymorphic_identity': 'float'} - 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': 'int'} - 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': 'string'} - value_string = Column(String) - - def __init__(self, sensor, value, timestamp=datetime.now()): - Value.__init__(self, sensor, timestamp) - self.value_string = value - - def value(self): - return self.value_string - - - - |