def handleProcessedDataByQhawax(): """ Records processed and valid processed measurements every five seconds qHAWAX: Record new measurement """ flag_email = False data_json = request.get_json() try: product_id = data_json['ID'] data_json = util_helper.validTimeJsonProcessed(data_json) data_json = util_helper.validAndBeautyJsonProcessed(data_json) post_data_helper.storeProcessedDataInDB(data_json) data_json['ID'] = product_id data_json['zone'] = "Undefined Zone" mode = same_helper.getQhawaxMode(product_id) inca_value = same_helper.getMainIncaQhawaxTable(product_id) if (mode == "Customer" and inca_value != None): data_json['zone'] = get_business_helper.getNoiseData(product_id) minutes_difference, last_time_turn_on = get_business_helper.getHoursDifference( product_id) if (minutes_difference != None): if (minutes_difference < 5): post_data_helper.validTimeOfValidProcessed( 10, "minute", last_time_turn_on, data_json, product_id, inca_value) elif (minutes_difference >= 5): post_data_helper.validTimeOfValidProcessed( 2, "hour", last_time_turn_on, data_json, product_id, inca_value) data_json = util_helper.setNoneStringElements(data_json) socketio.emit(data_json['ID'] + '_processed', data_json) return make_response('OK', 200) except TypeError as e: json_message = jsonify({'error': '\'%s\'' % (e)}) return make_response(json_message, 400)
def queryIncaQhawax(name): """ Helper qHAWAX function to get main inca value """ qhawax_id = same_helper.getQhawaxID(name) if (qhawax_id is not None): qhawax_inca = int(same_helper.getMainIncaQhawaxTable(qhawax_id)) return util_helper.getColorBaseOnIncaValue(qhawax_inca) return None
def handleProcessedDataByQhawax(): """ Records processed and valid processed measurements every five seconds qHAWAX: Record new measurement """ flag_email = False data_json = request.get_json() try: product_id = data_json["ID"] data_json = util_helper.validTimeJsonProcessed(data_json) data_json = util_helper.validAndBeautyJsonProcessed(data_json) post_data_helper.storeProcessedDataInDB(data_json) data_json["ID"] = product_id data_json["zone"] = "Undefined Zone" mode = same_helper.getQhawaxMode(product_id) inca_value = same_helper.getMainIncaQhawaxTable(product_id) # same endpoint for every qHAWAX but logic different per type of qHAWAX if mode == "Customer" and inca_value != None: data_json["zone"] = get_business_helper.getNoiseData(product_id) ( minutes_difference, last_time_turn_on, ) = get_business_helper.getHoursDifference(product_id) if minutes_difference != None: if minutes_difference < 5: post_data_helper.validTimeOfValidProcessed( 10, "minute", last_time_turn_on, data_json, product_id, inca_value, ) elif minutes_difference >= 5: post_data_helper.validTimeOfValidProcessed( 2, "hour", last_time_turn_on, data_json, product_id, inca_value, ) data_json = util_helper.setNoneStringElements(data_json) socketio.emit(data_json["ID"] + "_processed", data_json) return make_response("OK", 200) except TypeError as e: json_message = jsonify({"error": "'%s'" % (e)}) return make_response(json_message, 400)
def storeNewQhawaxInstallation(data): """Insert new qHAWAX in Field""" data = exceptions.checkVariable_helper(data, dict) if util_helper.areFieldsValid(data) == False: raise Exception("qHAWAX Installation fields have to have data") qhawax_id = same_helper.getQhawaxID(data["qhawax_name"]) if qhawax_id != None: data["qhawax_id"] = int(qhawax_id) data["main_inca"] = same_helper.getMainIncaQhawaxTable( data["qhawax_name"]) data["installation_date_zone"] = data["instalation_date"] data["last_time_physically_turn_on_zone"] = data["instalation_date"] data.pop("instalation_date", None) data.pop("qhawax_name", None) if "id" in data: data.pop("id", None) if "company_name" in data: data.pop("company_name", None) qhawax_installation = QhawaxInstallationHistory(**data) session.add(qhawax_installation) session.commit()
def storeNewQhawaxInstallation(data): """ Insert new qHAWAX in Field """ if (isinstance(data, dict)): if (util_helper.areFieldsValid(data) == True): data['main_inca'] = same_helper.getMainIncaQhawaxTable( data['qhawax_id']) data['installation_date_zone'] = datetime.datetime.now( dateutil.tz.tzutc()) data['last_time_physically_turn_on_zone'] = datetime.datetime.now( dateutil.tz.tzutc()) data['last_registration_time_zone'] = datetime.datetime.now( dateutil.tz.tzutc()) qhawax_installation = QhawaxInstallationHistory(**data) session.add(qhawax_installation) session.commit() else: raise Exception("qHAWAX Installation fields have to have data") else: raise TypeError("The Json company " + str(data) + " should be in Json Format")
def test_get_main_inca_valid(self): self.assertAlmostEqual(same_helper.getMainIncaQhawaxTable("qH004"), 50.0) self.assertAlmostEqual(same_helper.getMainIncaQhawaxTable("qH100"), None)
def test_get_main_inca_valid(self): self.assertAlmostEqual(same_helper.getMainIncaQhawaxTable(4), -1) self.assertAlmostEqual(same_helper.getMainIncaQhawaxTable(100), None)