Esempio n. 1
0
def qhawaxEndCalibration():
    """
    qHAWAX update end calibration mode, set main inca original, depends of mode (customer or stand by)

    """
    req_json = request.get_json()
    try:
        qhawax_name = str(req_json['qhawax_name']).strip()
        person_in_charge = str(req_json['person_in_charge'])
        flag_costumer = get_business_helper.isItFieldQhawax(qhawax_name)
        if (flag_costumer == True):
            post_business_helper.turnOnAfterCalibration(qhawax_name)
            mode = "Cliente"
            description = "Se cambió a modo cliente"
            main_inca = 0
        else:
            mode = "Stand By"
            description = "Se cambió a modo stand by"
            main_inca = -1
        post_business_helper.changeMode(qhawax_name, mode)
        post_business_helper.updateMainIncaQhawaxTable(main_inca, qhawax_name)
        post_business_helper.updateMainIncaQhawaxInstallationTable(
            main_inca, qhawax_name)
        post_business_helper.writeBinnacle(qhawax_name, description,
                                           person_in_charge)
        return make_response(
            {'Success': 'qHAWAX have changed to original mode'}, 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Esempio n. 2
0
def qhawaxEndCalibration():
    """qHAWAX update end calibration mode, set main inca original, depends of mode (customer or stand by)"""
    req_json = request.get_json()
    try:
        qH_name, in_charge = exception_helper.getEndCalibrationFields(req_json)
        (
            mode,
            description,
            main_inca,
        ) = get_business_helper.getLastValuesOfQhawax(qH_name)
        post_business_helper.updateMainIncaQhawaxTable(main_inca, qH_name)
        post_business_helper.updateMainIncaQhawaxInstallationTable(
            main_inca, qH_name
        )
        # post_business_helper.updateTimeOnPreviousTurnOn(qH_name,1) # update last_registration relatively to the physically_turn_on
        post_business_helper.changeMode(qH_name, mode)
        post_business_helper.writeBinnacle(qH_name, description, in_charge)
        return make_response(
            {"Success": "qHAWAX has been changed to original mode - open"}, 200
        )
    except (TypeError, ValueError) as e:
        json_message = jsonify({"error": "'%s'" % (e)})
        return make_response(json_message, 400)
    except (Exception) as e:
        json_message = jsonify({"database error": "'%s'" % (e)})
        return make_response(json_message, 400)
Esempio n. 3
0
def qhawaxChangeToCalibration():
    """
    qHAWAX update to Calibration mode, set main inca -2 value

    """
    req_json = request.get_json()
    try:
        qhawax_name = str(req_json['qhawax_name']).strip()
        person_in_charge = req_json['person_in_charge']
        description = req_json['description']
        qhawax_time_off = now.replace(tzinfo=None)
        post_business_helper.saveStatusOffQhawaxTable(qhawax_name)
        post_business_helper.updateMainIncaQhawaxTable(-2, qhawax_name)
        if (same_helper.getQhawaxMode(qhawax_name) == 'Cliente'):
            post_business_helper.saveStatusOffQhawaxInstallationTable(
                name, qhawax_time_off)
            post_business_helper.updateMainIncaQhawaxInstallationTable(
                -2, qhawax_name)
        post_business_helper.changeMode(qhawax_name, "Calibracion")
        post_business_helper.writeBinnacle(qhawax_name, description,
                                           person_in_charge)
        return make_response(
            {'Success': 'qHAWAX have changed to calibration mode'}, 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Esempio n. 4
0
def validAndBeautyJsonValidProcessed(data_json,product_id,inca_value):
    """ Helper function to valid json Valid Processed table """
    data_json = exceptions.checkDictionaryVariable(data_json)
    product_id = exceptions.checkStringVariable(product_id)
    storeValidProcessedDataInDB(data_json,product_id)
    if(inca_value==0.0):
      post_business_helper.updateMainIncaQhawaxTable(1,product_id)
      post_business_helper.updateMainIncaQhawaxInstallationTable(1,product_id)
def validAndBeautyJsonValidProcessedMobile(data_json, product_id):
    data_json = exceptions.checkVariable_helper(data_json, dict)
    product_id = exceptions.checkVariable_helper(product_id, str)
    if util_helper.checkValidLatLonValues(data_json):
        if not (
            same_helper.isMobileQhawaxInATrip(product_id)
        ):  # in case trip has finished, a new one has to begin...
            recordStartTrip(product_id)
        storeValidProcessedDataInDBMobile(data_json, product_id)
        max_value = 0
        for i in range(len(pollutants)):
            socket_name = data_json["ID"] + "_" + str(pollutants[i]) + "_valid"
            pollutantStr = (
                str(pollutants[i]) + "_ug_m3"
                if (pollutants[i] in ["CO", "NO2", "O3", "H2S", "SO2"])
                else str(pollutants[i])
            )
            new_data_json = {
                "sensor": pollutants[i],
                "center": {"lat": data_json["lat"], "lng": data_json["lon"]},
            }
            factor_final_json = {
                "CO": 100 / 10000,
                "NO2": 100 / 200,
                "PM10": 100 / 150,
                "PM25": 100 / 25,
                "SO2": 100 / 20,
                "O3": 100 / 100,
                "H2S": 100 / 150,
            }
            if data_json[pollutantStr] != None:
                if pollutants[i] in factor_final_json:
                    data_json[pollutantStr] = round(
                        data_json[pollutantStr]
                        * factor_final_json[pollutants[i]],
                        3,
                    )
                new_data_json[pollutants[i]] = data_json[pollutantStr]
                socketio.emit(socket_name, new_data_json)  # qH006_CO_valid
                if (
                    data_json[pollutantStr] >= max_value
                ):  # same percentage comparison logic to obtain the highest percentage out of all pollutants
                    max_value = data_json[pollutantStr]
                    sensor_name = pollutants[i]
        calInca = util_helper.validaPollutant(max_value, sensor_name)
        post_business_helper.updateMainIncaQhawaxTable(calInca, product_id)
        post_business_helper.updateMainIncaQhawaxInstallationTable(
            calInca, product_id
        )
Esempio n. 6
0
def updateIncaData():
    """ Server Open Source / Server Comercial - To save qHAWAX inca value """
    jsonsend = {}
    req_json = request.get_json()
    try:
        name, value_inca = exception_helper.getIncaTargetofJson(req_json)
        post_business_helper.updateMainIncaQhawaxTable(value_inca, name)
        post_business_helper.updateMainIncaQhawaxInstallationTable(
            value_inca, name)
        jsonsend['main_inca'] = value_inca
        jsonsend['name'] = name
        socketio.emit('update_inca', jsonsend)
        return make_response({'Success': ' save inca value'}, 200)
    except (ValueError, TypeError) as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Esempio n. 7
0
def updateIncaData():
    """
    To save qHAWAX inca value
    """
    jsonsend = {}
    try:
        req_json = request.get_json()
        exception_helper.getIncaTargetofJson(req_json)
        name = str(req_json['name']).strip()
        value_inca = req_json['value_inca']
        post_business_helper.updateMainIncaQhawaxTable(value_inca, name)
        if (same_helper.getQhawaxMode(name) == 'Cliente'):
            post_business_helper.updateMainIncaInDB(value_inca, name)
        jsonsend['main_inca'] = value_inca
        jsonsend['name'] = name
        socketio.emit('update_inca', jsonsend)
        return make_response({'Success': ' save inca value'}, 200)
    except (ValueError, TypeError) as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Esempio n. 8
0
def qhawaxEndCalibration():
    """ qHAWAX update end calibration mode, set main inca original, depends of mode (customer or stand by)"""
    req_json = request.get_json()
    try:
        qH_name, in_charge = exception_helper.getEndCalibrationFields(req_json)
        mode, description, main_inca = get_business_helper.getLastValuesOfQhawax(
            qH_name)
        post_business_helper.updateMainIncaQhawaxTable(main_inca, qH_name)
        post_business_helper.updateMainIncaQhawaxInstallationTable(
            main_inca, qH_name)
        post_business_helper.changeMode(qH_name, mode)
        post_business_helper.writeBinnacle(qH_name, description, in_charge)
        return make_response(
            {'Success': 'qHAWAX has been changed to original mode - open'},
            200)
    except (TypeError, ValueError) as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
    except (Exception) as e:
        json_message = jsonify({'database error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Esempio n. 9
0
def qhawaxChangeToCalibration():
    """ qHAWAX update to Calibration mode, set main inca -2 value """
    req_json = request.get_json()
    qhawax_time_off = datetime.datetime.now(dateutil.tz.tzutc())
    description = "qHAWAX has been changed to calibration mode"
    try:
        qH_name, in_charge = exception_helper.getChangeCalibrationFields(
            req_json)
        post_business_helper.updateMainIncaQhawaxTable(-2, qH_name)
        post_business_helper.saveStatusOffQhawaxInstallationTable(
            qH_name, qhawax_time_off)
        post_business_helper.updateMainIncaQhawaxInstallationTable(-2, qH_name)
        post_business_helper.changeMode(qH_name, "Calibration")
        post_business_helper.writeBinnacle(qH_name, description, in_charge)
        return make_response(
            {'Success': 'qHAWAX has been changed to calibration mode - open'},
            200)
    except (TypeError, ValueError) as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
    except (Exception) as e:
        json_message = jsonify({'database error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Esempio n. 10
0
def qhawaxChangeToCalibration():
    """qHAWAX update to Calibration mode, set main inca -2 value"""
    req_json = request.get_json()
    qhawax_time_off = datetime.datetime.now(dateutil.tz.tzutc())
    description = "qHAWAX has been changed to calibration mode"
    try:
        qH_name, in_charge = exception_helper.getChangeCalibrationFields(
            req_json
        )
        comercial_name = same_helper.getComercialName(qH_name)
        qhawax_type = same_helper.queryQhawaxType(qH_name)
        post_business_helper.updateMainIncaQhawaxTable(-2, qH_name)
        if (
            qhawax_type != "MOBILE_EXT"
        ):  # Mobile qhawaxs should not be affected by this condition. Nor any other qhawaxs though..
            post_business_helper.saveStatusOffQhawaxInstallationTable(
                qH_name, qhawax_time_off
            )
        post_business_helper.updateMainIncaQhawaxInstallationTable(-2, qH_name)
        post_business_helper.changeMode(qH_name, "Calibration")
        post_business_helper.writeBinnacle(qH_name, description, in_charge)
        # if (qhawax_type == 'MOBILE_EXT'):
        #     post_data_helper.recordEndTrip(qH_name, str(comercial_name))
        #     jsonLatLon = get_data_helper.getMobileLatestLatLonValidProcessedMeasurement(qH_name)
        #     if(jsonLatLon!=None):
        #         post_data_helper.updateLastestLatLonMobile(qH_name,jsonLatLon)
        return make_response(
            {"Success": "qHAWAX has been changed to calibration mode - open"},
            200,
        )
    except (TypeError, ValueError) as e:
        json_message = jsonify({"error": "'%s'" % (e)})
        return make_response(json_message, 400)
    except (Exception) as e:
        json_message = jsonify({"database error": "'%s'" % (e)})
        return make_response(json_message, 400)
 def test_update_main_inca_qhawax_valid(self):
     post_business_helper.updateMainIncaQhawaxTable(-1, "qH057")