2018-04-27 08:47:24 +00:00
|
|
|
from datetime import datetime
|
2018-05-03 13:28:57 +00:00
|
|
|
from app import db
|
|
|
|
from sqlalchemy import Column, Integer, DateTime, String
|
2018-04-27 08:47:24 +00:00
|
|
|
from sqlalchemy.dialects.postgresql import JSON
|
|
|
|
|
2018-04-27 14:06:16 +00:00
|
|
|
|
2018-05-03 13:28:57 +00:00
|
|
|
class Recording(db.Model):
|
2018-04-27 08:47:24 +00:00
|
|
|
__tablename__ = 'recordings'
|
|
|
|
|
2018-05-03 12:23:24 +00:00
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
recorded_at = Column(DateTime, index=True,
|
|
|
|
default=datetime.utcnow())
|
|
|
|
received_at = Column(DateTime, index=True,
|
|
|
|
default=datetime.utcnow())
|
|
|
|
device_id = Column(Integer)
|
|
|
|
record_type = Column(Integer, nullable=False)
|
|
|
|
record_value = Column(String, nullable=False)
|
|
|
|
raw_record = Column(JSON, nullable=True)
|
2018-04-27 08:47:24 +00:00
|
|
|
|
2018-04-27 14:06:16 +00:00
|
|
|
def __init__(self, device_id, record_type,
|
|
|
|
record_value, recorded_at, raw_json):
|
2018-05-02 19:05:30 +00:00
|
|
|
self.device_id = int(device_id)
|
|
|
|
self.record_type = int(record_type)
|
|
|
|
self.record_value = str(record_value)
|
|
|
|
self.recorded_at = datetime.fromtimestamp(int(recorded_at))
|
2018-04-27 14:06:16 +00:00
|
|
|
self.received_at = datetime.utcnow()
|
|
|
|
self.raw_record = raw_json
|
2018-04-27 08:47:24 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2018-05-02 19:05:30 +00:00
|
|
|
return '<Recording (value=%s, recorded_at=%s)>' % (
|
|
|
|
self.record_value, self.recorded_at)
|