Beispiel #1
0
def sendQhawaxStatusOn():
    """qHAWAX / Web Comercial - Set qHAWAX ON due to module reset (sensors reset)"""
    jsonsend = {}
    req_json = request.get_json()
    description = "qHAWAX turned on after a general reset"
    try:
        qhawax_name = str(req_json["qhawax_name"]).strip()
        comercial_name = same_helper.getComercialName(qhawax_name)
        post_business_helper.saveStatusQhawaxTable(qhawax_name, "ON", 0)
        post_business_helper.saveTurnOnLastTime(qhawax_name)
        post_business_helper.writeBinnacle(qhawax_name, description, "API")
        type = same_helper.queryQhawaxType(qhawax_name)
        if type == "MOBILE_EXT":
            (
                trip_start,
                trip_id,
            ) = get_data_helper.getqHAWAXMobileLatestTripStart(qhawax_name)
            if trip_id != None and trip_start != None:
                date_start = (
                    trip_start - datetime.timedelta(hours=5)
                ).date()  # local
                now_date = (
                    datetime.datetime.now(dateutil.tz.tzutc())
                    - datetime.timedelta(hours=5)
                ).date()
                if date_start == now_date:
                    same_helper.setTripEndNull(
                        trip_id
                    )  # trip is continued if there is any that started in the same day
        return make_response({"Success": "qHAWAX ON physically"}, 200)
    except TypeError as e:
        json_message = jsonify({"error": "'%s'" % (e)})
        return make_response(json_message, 400)
Beispiel #2
0
def sendQhawaxStatusOnBaseOnLossSignal():
    """ Set qHAWAX ON Base On Loss Signal  - It should set last main inca value, set last last_time_off record and last last_time_on """
    req_json = request.get_json()
    try:
        qH_name, timestamp = exception_helper.getQhawaxSignalJson(req_json)
        qhawax_state = same_helper.getQhawaxStatus(qH_name)
        description = 'qHAWAX turned on after a loss of signal'
        json_email = {
            'description': description,
            'person_in_charge': 'Firmware'
        }
        if (qhawax_state is not None):
            mode = same_helper.getQhawaxMode(qH_name)
            on_loop = int(same_helper.getQhawaxOnLoop(qH_name)) + 1
            if (qhawax_state == 'OFF'):
                post_business_helper.saveStatusQhawaxTable(qH_name, "ON", 0)
                post_business_helper.setLastMeasurementOfQhawax(qH_name)
                post_business_helper.writeBinnacle(
                    qH_name, json_email['description'],
                    json_email['person_in_charge'])
                post_business_helper.resetOnLoop(qH_name, 0)
                return make_response({'Success': description}, 200)
            else:
                post_business_helper.reset_on_loop(qH_name, 0) if (
                    on_loop == 20) else post_business_helper.reset_on_loop(
                        qH_name, on_loop)
                if (on_loop == 1):
                    post_business_helper.recordFirstTimeLoop(
                        qH_name, timestamp)
                return make_response({'Success': 'qHAWAX is already ON'}, 200)
        return make_response({'Warning': 'qHAWAX name has not been found'},
                             400)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Beispiel #3
0
def sendQhawaxStatusOnBaseOnLossSignal():
    """Set qHAWAX ON Base On Loss Signal  - It should set last main inca value, set last last_time_off record and last last_time_on"""
    req_json = request.get_json()
    try:
        qH_name, timestamp = exception_helper.getQhawaxSignalJson(req_json)
        qhawax_state = same_helper.getQhawaxStatus(qH_name)
        description = "qHAWAX turned on after a loss of signal"
        json_email = {
            "description": description,
            "person_in_charge": "Firmware",
        }
        qhawax_type = same_helper.queryQhawaxType(qH_name)
        if qhawax_state is not None:
            mode = same_helper.getQhawaxMode(qH_name)
            on_loop = int(same_helper.getQhawaxOnLoop(qH_name)) + 1
            if qhawax_state == "OFF":
                post_business_helper.saveStatusQhawaxTable(
                    qH_name, "ON", 0
                )  # tabla qHAWAX
                post_business_helper.setLastMeasurementOfQhawax(qH_name)
                post_business_helper.writeBinnacle(
                    qH_name,
                    json_email["description"],
                    json_email["person_in_charge"],
                )
                post_business_helper.resetOnLoop(qH_name, 0)
                if qhawax_type == "MOBILE_EXT":
                    # only if mobile, we have to check if there is a previous trip that we must continue
                    (
                        trip_start,
                        trip_id,
                    ) = get_data_helper.getqHAWAXMobileLatestTripStart(qH_name)
                    if trip_id != None and trip_start != None:
                        # trip_start = datetime.datetime.strptime('2021-07-12 12:00:00', '%Y-%m-%d %H:%M:%S') # test
                        date_start = (
                            trip_start - datetime.timedelta(hours=5)
                        ).date()  # local
                        now_date = (
                            datetime.datetime.now(dateutil.tz.tzutc())
                            - datetime.timedelta(hours=5)
                        ).date()
                        if date_start == now_date:
                            same_helper.setTripEndNull(trip_id)
                return make_response({"Success": description}, 200)
            else:
                post_business_helper.resetOnLoop(qH_name, 0) if (
                    on_loop == 20
                ) else post_business_helper.resetOnLoop(qH_name, on_loop)
                if on_loop == 1:
                    post_business_helper.recordFirstTimeLoop(
                        qH_name, timestamp
                    )
                return make_response({"Success": "qHAWAX is already ON"}, 200)
        return make_response(
            {"Warning": "qHAWAX name has not been found"}, 400
        )
    except TypeError as e:
        json_message = jsonify({"error": "'%s'" % (e)})
        return make_response(json_message, 400)
Beispiel #4
0
def sendQhawaxStatusOn():
    """ qHAWAX / Web Comercial - Set qHAWAX ON due to module reset (sensors reset) """
    jsonsend = {}
    req_json = request.get_json()
    description = "qHAWAX turned on after a general reset"
    try:
        qhawax_name = str(req_json['qhawax_name']).strip()
        post_business_helper.saveStatusQhawaxTable(qhawax_name, 'ON', 0)
        post_business_helper.saveTurnOnLastTime(qhawax_name)
        post_business_helper.writeBinnacle(qhawax_name, description, None)
        jsonsend['main_inca'] = 0
        jsonsend['name'] = qhawax_name
        return make_response({'Success': 'qHAWAX ON physically'}, 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
def handleProcessedDataByMobileQhawax():
    data_json = request.get_json()
    try:
        product_id = data_json["ID"]
        if data_json is not None:
            if "zone" in data_json:
                data_json.pop("zone")
            post_data_helper.storeProcessedDataInDB(data_json)
            data_json["ID"] = product_id
            state = get_business_helper.queryQhawaxStatus(product_id)
            mode = same_helper.getQhawaxMode(product_id)
            if state == "OFF":  # if API turned it off
                post_business_helper.saveTurnOnLastTimeProcessedMobile(
                    product_id)
                post_business_helper.saveStatusQhawaxTable(
                    product_id, "ON", 1)  # state = ON - qhawax
                post_business_helper.writeBinnacle(product_id, "Reconnection",
                                                   "API")

            if mode == "Customer":
                (
                    minutes_difference,
                    last_time_turn_on,
                ) = get_business_helper.getHoursDifference(product_id)
                if minutes_difference != None:
                    if minutes_difference < 30:
                        if last_time_turn_on + datetime.timedelta(
                                minutes=1) < datetime.datetime.now(
                                    dateutil.tz.tzutc()):
                            post_data_helper.validAndBeautyJsonValidProcessedMobile(
                                data_json, product_id)

                    elif minutes_difference >= 30:
                        if last_time_turn_on + datetime.timedelta(
                                hours=2) < datetime.datetime.now(
                                    dateutil.tz.tzutc()):
                            post_data_helper.validAndBeautyJsonValidProcessedMobile(
                                data_json, product_id)

            return make_response("OK", 200)
        return make_response("ID not found", 400)
    except TypeError as e:
        json_message = jsonify({"error": "'%s'" % (e)})
        return make_response(json_message, 400)
Beispiel #6
0
def sendQhawaxStatusOff():
    """ Server Open Source lo apagara / Web Comercial lo pagara y enviara correo- Endpoint to set qHAWAX OFF because script detect no new data within five minutes  """
    jsonsend = {}
    req_json = request.get_json()
    description = "qHAWAX off"
    try:
        qH_name = exception_helper.getStatusOffTargetofJson(req_json)
        post_business_helper.saveStatusQhawaxTable(qH_name, 'OFF', -1)
        lessfive = get_data_helper.getQhawaxLatestTimestampProcessedMeasurement(
            qhawax_name)
        post_business_helper.saveStatusOffQhawaxInstallationTable(
            qH_name, lessfive)
        post_business_helper.writeBinnacle(qH_name, description, None)
        jsonsend['main_inca'] = -1
        jsonsend['name'] = qH_name
        socketio.emit('update_inca', jsonsend)
        return make_response({'Success': 'qHAWAX OFF'}, 200)
    except (ValueError, TypeError) as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
Beispiel #7
0
def sendQhawaxStatusOff():
    """Server Open Source lo apagara / Web Comercial lo pagara y enviara correo- Endpoint to set qHAWAX OFF because script detect no new data within five minutes"""
    jsonsend = {}
    req_json = request.get_json()
    description = "qHAWAX off"
    try:
        qH_name = exception_helper.getStatusOffTargetofJson(req_json)
        comercial_name = same_helper.getComercialName(qH_name)
        post_business_helper.saveStatusQhawaxTable(qH_name, "OFF", -1)
        lessfive = (
            get_data_helper.getQhawaxLatestTimestampProcessedMeasurement(
                qH_name
            )
        )  # obtuve la ultima medida enviada a la tabla procesed open
        post_business_helper.saveStatusOffQhawaxInstallationTable(
            qH_name, lessfive
        )
        post_business_helper.writeBinnacle(qH_name, description, "API")
        jsonsend["main_inca"] = -1
        jsonsend["name"] = qH_name
        socketio.emit("update_inca", jsonsend)
        type = same_helper.queryQhawaxType(qH_name)
        if 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 OFF"}, 200)
    except (ValueError, TypeError) as e:
        json_message = jsonify({"error": "'%s'" % (e)})
        return make_response(json_message, 400)
 def test_save_status_qhawax_valid(self):
     post_business_helper.saveStatusQhawaxTable("qH057", "ON", 0)
     post_business_helper.saveStatusQhawaxTable("qH057", "OFF", -1)
	def test_save_status_qhawax_valid(self):
		post_business_helper.saveStatusQhawaxTable('qH057','ON',0)
		post_business_helper.saveStatusQhawaxTable('qH057','OFF',-1)