Beispiel #1
0
class BaseModel(db.Model):

    created_at = db.Column(db.DateTime, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           default=datetime.now,
                           onupdate=datetime.now)

    __abstract__ = True

    def __int__(**kwargs):
        super.__init__(**kwargs)
Beispiel #2
0
class CloudSource(Collector):

    # Properties
    id = db.Column(db.Integer, db.ForeignKey('collector.id'), primary_key=True)
    url = db.Column(db.String)
    name = db.Column(db.String)
    description = db.Column(db.String)

    # Relationships

    __tablename__ = 'cloud_source'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #3
0
class Sample(db.Model, Serializer):
    
    # Properties
    id = db.Column(db.Integer, primary_key=True)
    collector_id = db.Column(db.Integer, db.ForeignKey('collector.id'))
    timestamp = db.Column(db.DateTime)
    data = db.Column(JSONB)

    # Relationships
    collector = db.relationship("Collector", back_populates="samples")

    __tablename__ = 'sample'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #4
0
class Sensor(Collector):

    # Properties
    id = db.Column(db.Integer, db.ForeignKey('collector.id'), primary_key=True)
    sensor_board_id = db.Column(db.Integer, db.ForeignKey('sensor_board.id'))
    sensor_model_id = db.Column(db.Integer, db.ForeignKey('sensor_model.id'))
    calibration = db.Column(JSONB)

    # Relationships
    board = db.relationship("SensorBoard", back_populates="sensors")
    model = db.relationship("SensorModel", back_populates="sensors")

    __tablename__ = 'sensor'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #5
0
class SensorBoard(Device):

    # Properties
    id = db.Column(db.Integer, db.ForeignKey('device.id'), primary_key=True)
    description = db.Column(db.String)
    version = db.Column(db.String)

    # Relationships
    sensors = db.relationship("Sensor", back_populates="board")
    link = db.relationship("Link", back_populates="sensor_board")

    __tablename__ = 'sensor_board'

    __mapper_args__ = {
        'polymorphic_identity': 'sensor_board',
    }

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #6
0
class App(BaseModel, Serializer):

    # Properties
    id = db.Column(db.Integer, primary_key=True)
    app_id = db.Column(db.String, nullable=False, unique=True)
    name = db.Column(db.String)
    version = db.Column(db.String)
    latest_version = db.Column(db.Boolean)

    # Relationships
    installed_apps = db.relationship("InstalledApp", back_populates="app")

    __tablename__ = 'app'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def new_app_version(new_version):
        pass
Beispiel #7
0
class Collector(BaseModel, Serializer):
    
    # Properties
    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(36), nullable=False, unique=True)
    type = db.Column(db.String)

    # Relationships
    samples = db.relationship("Sample", back_populates="collector")

    __tablename__ = 'collector'

    __mapper_args__ = {
        'polymorphic_identity':'collector',
        'polymorphic_on': type
    }

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #8
0
class Device(BaseModel, Serializer):

    # Properties
    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(36), nullable=False, unique=True)
    name = db.Column(db.String)
    type = db.Column(db.String)

    # Relationships
    installed_apps = db.relationship("InstalledApp", back_populates="device")

    __tablename__ = 'device'

    __mapper_args__ = {
        'polymorphic_identity': 'device',
        'polymorphic_on': type
    }

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def install_app(remove_old=True):
        pass
Beispiel #9
0
class Gateway(Device):
    
    # Properties
    id = db.Column(db.Integer, db.ForeignKey('device.id'), primary_key=True)

    # Relationships
    links = db.relationship("Link", back_populates="gateway")

    __tablename__ = 'gateway'

    __mapper_args__ = {
        'polymorphic_identity': 'gateway',
    }

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #10
0
class Link(BaseModel, Serializer):

    # Properties
    id = db.Column(db.Integer, primary_key=True)
    gateway_id = db.Column(db.Integer, db.ForeignKey('gateway.id'))
    sensor_board_id = db.Column(db.Integer, db.ForeignKey('sensor_board.id'))
    local = db.Column(db.Boolean)
    last_contacted = db.Column(db.DateTime, default=datetime.now)
    collecting_data = db.Column(db.Boolean)
    max_msg_interval_sec = db.Column(db.Integer)

    # Relationships
    gateway = db.relationship("Gateway", back_populates="links")
    sensor_board = db.relationship("SensorBoard", back_populates="link")

    __tablename__ = 'link'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #11
0
class SensorModel(BaseModel, Serializer):

    # Properties
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    model = db.Column(db.String)
    measurement_type = db.Column(db.String)
    description = db.Column(db.String)
    units = db.Column(db.String)

    # Relationships
    sensors = db.relationship("Sensor", back_populates="model")

    __tablename__ = 'sensor_model'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
Beispiel #12
0
class InstalledApp(BaseModel, Serializer):

    # Properties
    id = db.Column(db.Integer, primary_key=True)
    device_id = db.Column(db.Integer, db.ForeignKey('device.id'))
    app_id = db.Column(db.Integer, db.ForeignKey('app.id'))
    install_time = db.Column(db.DateTime, default=datetime.now)
    uninstall_time = db.Column(db.DateTime, default=datetime.now)
    running = db.Column(db.Boolean)

    # Relationships
    device = db.relationship("Device", back_populates="installed_apps")
    app = db.relationship("App", back_populates="installed_apps")

    __tablename__ = 'installed_app'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)