Example #1
0
def validate_session(device):
    query = db_session.query(Session).filter(Session.device_id == device.id,
                                             Session.completed.is_(None))
    session = query.first()
    if session is None:
        session = create_session(device)
    return session
Example #2
0
def temp_timeout(db_session):
    while True:
        query = db_session.query(Session).filter(Session.completed.is_(None))
        sessions = query.all()
        for session in sessions:
            query = db_session.query(Temp).filter(
                Temp.session_id == session.id).order_by(
                    Temp.sesssion_temp_id.desc())
            temp = query.first()
            delta = datetime.datetime.utcnow() - temp.created
            seconds = delta.seconds
            print('Session {}. Seconds since last temp update: {}'.format(
                session.id, seconds))
            if seconds > TEMP_TIMEOUT:
                session.completed = temp.created
                db_session.commit()
        time.sleep(10)
Example #3
0
def api_session_last_temp(id):
    query = db_session.query(Session).filter(Session.id == id)
    _session = query.first()
    session = _session.asdict()
    temps = [_session.last_temp.asdict()]
    response = {
        'status': 'success',
        'data': {
            'session': session,
            'temps': temps
        }
    }
    return jsonify(response)
Example #4
0
def api_session_temps(id):
    query = db_session.query(Session).filter(Session.id == id)
    _session = query.first()
    _temps = _session.temps
    session = _session.asdict()
    temps = [temp.asdict() for temp in _temps[::-1]]
    response = {
        'status': 'success',
        'data': {
            'session': session,
            'temps': temps
        }
    }
    return jsonify(response)
Example #5
0
sys.path.append("..")

from bbq.models import Device, Session, Temp
from bbq.database import db_session
from bbq.database import init_db

init_db()


d = Device('AABBCCDDEEFF')
d2 = Device('FFEEDDCCBBAA')
db_session.add(d)
db_session.add(d2)
db_session.commit()

d = db_session.query(Device).all()[0]
d2 = db_session.query(Device).all()[1]
s = Session(d)
s2 = Session(d2)
db_session.add(s)
db_session.add(s2)
db_session.commit()

d = db_session.query(Device).all()[0]
d2 = db_session.query(Device).all()[1]
s = Session(d)
s2 = Session(d2)
db_session.add(s)
db_session.add(s2)
db_session.commit()
Example #6
0
def api_session(id):
    query = db_session.query(Session).filter(Session.id == id)
    _session = query.first()
    session = _session.asdict()
    response = {'status': 'success', 'data': {'session': session}}
    return jsonify(response)
Example #7
0
def device(id):
    query = db_session.query(Device).filter(Device.id == id)
    device = query.first()
    sessions = device.sessions
    return render_template('device.html', device=device, sessions=sessions)
Example #8
0
def session(id):
    query = db_session.query(Session).filter(Session.id == id)
    session = query.first()
    return render_template('temps.html', session=session)
Example #9
0
def validate_device(mac):
    query = db_session.query(Device).filter(Device.mac == mac)
    device = query.first()
    if device is None:
        device = create_device(mac)
    return device
Example #10
0
def index():
    query = db_session.query(Device)
    devices = query.all()
    return render_template('index.html', devices=devices)
Example #11
0
def api_device_sessions(id):
    query = db_session.query(Session).filter(Session.device_id == id)
    sessions = [session.asdict() for session in query[::-1]]
    response = {'status': 'success', 'data': {'sessions': sessions}}
    return jsonify(response)
Example #12
0
def api_devices():
    query = db_session.query(Device).all()
    devices = [device.asdict() for device in query[::-1]]
    response = {'status': 'success', 'data': {'devices': devices}}
    return jsonify(response)
Example #13
0
 def last_temp(self):
     query = db_session.query(Temp).filter(
         Temp.session_id == self.id).order_by(Temp.created.desc())
     temp = query.first()
     return temp
Example #14
0
 def last_session(self):
     query = db_session.query(Session).filter(
         Session.device_id == self.id).order_by(Session.created.desc())
     session = query.first()
     return session