class Noise(Database.instance().Base, CRUDMixin): """Model for measures table """ __tablename__ = 'noises' registered_at = Column( DateTime, primary_key=True) # este id es del smartcitizen no del sensor peak = Column(Float) var1 = Column(Float) var5 = Column(Float) var10 = Column(Float) avg = Column(Float) synchronized_at = Column(DateTime) @classmethod def find_unsynchronized(cls): """Search setting by name""" session = Database.instance().session() return session.query(Noise).filter(Noise.synchronized_at == None) @classmethod def find_synchronized(cls): """Search setting by name""" session = Database.instance().session() return session.query(Noise).filter(Noise.synchronized_at != None) @classmethod def destroy_synchronized(cls): """Search setting by name""" session = Database.instance().session() session.query(Noise).filter(Noise.synchronized_at != None).delete() session.commit()
class Peak(Database.instance().Base, CRUDMixin): """Model for measures table """ __tablename__ = 'peaks' registered_at = Column( DateTime, primary_key=True) # este id es del smartcitizen no del sensor peak_value = Column(Float) @classmethod def find_last_min(cls, time): """Search setting by name""" session = Database.instance().session() return session.query(Peak).filter( and_(Peak.registered_at > time + timedelta(minutes=-1), Peak.registered_at <= time)).all() @classmethod def destroy_processed(cls, time): """Search setting by name""" session = Database.instance().session() session.query(Peak).filter( Peak.registered_at <= time + timedelta(minutes=-1)).delete() session.commit()
def destroy_processed(cls, time): """Search setting by name""" session = Database.instance().session() session.query(Peak).filter( Peak.registered_at <= time + timedelta(minutes=-1)).delete() session.commit()
def find_last_min(cls, time): """Search setting by name""" session = Database.instance().session() return session.query(Peak).filter( and_(Peak.registered_at > time + timedelta(minutes=-1), Peak.registered_at <= time)).all()
def destroy_synchronized(cls): """Search setting by name""" session = Database.instance().session() session.query(Noise).filter(Noise.synchronized_at != None).delete() session.commit()
def find_synchronized(cls): """Search setting by name""" session = Database.instance().session() return session.query(Noise).filter(Noise.synchronized_at != None)
def create_database(self): """Creates the database if it doesn't exist""" db = Database.instance() db.Base.metadata.create_all(bind=db.engine) db.set_session()