def devices(): idDisp1 = sql.dbSelectFromQuery(cursor, sql.SEL_MIN_DISP, sql.WH_ST_DISP.format("'A'")) idDisp2 = sql.dbSelectFromQuery(cursor, sql.SEL_MAX_DISP, sql.WH_ST_DISP.format("'A'")) resp1 = sql.dbSelectFromQuery( cursor, sql.SEL_DISP_ULT_LUM.format(idDisp1[0][0], idDisp2[0][0]), '') dict1 = dt.getDispositivosDict(resp1) resp2 = sql.dbSelectFromQuery(cursor, sql.SEL_ULT_TEMP_DT_HR, '') dict2 = dt.getUltTempDict(resp2) resp3 = sql.dbSelectFromQueryUnion( cursor, [[ sql.SEL_TEMP_HR_OC, sql.WH_MAX_OC_DISP.format(idDisp1[0][0]) + sql.AND + sql.ULT_24_HORAS ], [ sql.SEL_TEMP_HR_OC, sql.WH_MAX_OC_DISP.format(idDisp2[0][0]) + sql.AND + sql.ULT_24_HORAS ]]) dict3 = dt.getDiffTempDict(resp3) resp = json.dumps(dt.concatDicts([dict1, dict2, dict3]), indent=4, separators=(", ", " : ")) return util.answer(app, 200, resp)
def temperatures(): try: data = request.get_json() except (KeyError, TypeError, ValueError): return jsonify(success=False) try: resp1 = sql.dbSelectFromQuery( cursor, sql.SEL_ALL_OCS, sql.WH_DISP.format(data['id_dispositivo']) + sql.AND + sql.ULT_24_HORAS + "\nLIMIT 192") dict1 = (dt.getOcorrenciaDict(resp1)) resp_freq = sql.dbSelectFromQuery( cursor, sql.SEL_FREQ_DISP, sql.WH_DISP.format(data['id_dispositivo'])) dict_freq = (dt.getFreqDispDict(resp_freq)) dict1.update(dict_freq) resp = json.dumps(dt.concatDicts([dict1, dict_freq]), indent=4, separators=(", ", " : ")) return util.answer(app, 200, resp) except: d = data['id_dispositivo'] print(f'Error: device {d} not found.') return jsonify(success=False)
def frequency(): try: data = request.get_json() except (KeyError, TypeError, ValueError): resp = jsonify(success=False) return util.answer(app, 204, resp) resp1 = sql.dbSelectFromQuery(cursor, sql.SEL_FREQ_DISP, sql.WH_DISP.format(data['id_dispositivo'])) dict1 = json.dumps(dt.getFreqDispDict(resp1), indent=4, separators=(", ", " : ")) return util.answer(app, 200, dict1)