Esempio n. 1
0
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()
Esempio n. 2
0
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()
Esempio n. 3
0
 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()
Esempio n. 4
0
 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()
Esempio n. 5
0
 def destroy_synchronized(cls):
     """Search setting by name"""
     session = Database.instance().session()
     session.query(Noise).filter(Noise.synchronized_at != None).delete()
     session.commit()
Esempio n. 6
0
 def find_synchronized(cls):
     """Search setting by name"""
     session = Database.instance().session()
     return session.query(Noise).filter(Noise.synchronized_at != None)
Esempio n. 7
0
 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()