Пример #1
0
def get_all_data_sensor(id):
    try:
        m = Meta.query.filter_by(sid=id).one()
        meta_result = meta_schema.dump(m)
        sensor_result = sensordatas_schema.dump(m.sensordata.all())
        return jsonify({'sensors': meta_result.data, 'data': sensor_result.data})
    except NoResultFound:
        return jsonify({"message": "Sensor could not be found."}), 400
Пример #2
0
def get_all_data_sensor(id):
    try:
        m = Meta.query.filter_by(sid=id).one()
        meta_result = meta_schema.dump(m)
        sensor_result = sensordatas_schema.dump(m.sensordata.all())
        return jsonify({
            'sensors': meta_result.data,
            'data': sensor_result.data
        })
    except NoResultFound:
        return jsonify({"message": "Sensor could not be found."}), 400
Пример #3
0
def get_latest_data_sensor(id):
    try:
        m = Meta.query.filter_by(sid=id).one()
        meta_result = meta_schema.dump(m)
        # query the latest unix_epoch for this <id>
        # order_by: unix_epoch descending
        # with_entities: only return column unix_epoch
        # first(): only get first entry
        qry = Sensordata.query.filter_by(sid=id).order_by(desc('unix_epoch')).with_entities('unix_epoch').first()
        # convert this entry into a scalar representation that can be used for filtering
        max = db.session.query(db.func.max(qry)).scalar()
        sensor_result = sensordatas_schema.dump(m.sensordata.filter_by(unix_epoch=max))
        return jsonify({'sensors': meta_result.data, 'data': sensor_result.data})
    except NoResultFound:
        return jsonify({"message": "Sensor could not be found."}), 400
Пример #4
0
def get_latest_data_sensor(id):
    try:
        m = Meta.query.filter_by(sid=id).one()
        meta_result = meta_schema.dump(m)
        # query the latest unix_epoch for this <id>
        # order_by: unix_epoch descending
        # with_entities: only return column unix_epoch
        # first(): only get first entry
        qry = Sensordata.query.filter_by(sid=id).order_by(
            desc('unix_epoch')).with_entities('unix_epoch').first()
        # convert this entry into a scalar representation that can be used for filtering
        max = db.session.query(db.func.max(qry)).scalar()
        sensor_result = sensordatas_schema.dump(
            m.sensordata.filter_by(unix_epoch=max))
        return jsonify({
            'sensors': meta_result.data,
            'data': sensor_result.data
        })
    except NoResultFound:
        return jsonify({"message": "Sensor could not be found."}), 400