コード例 #1
0
def validTimeOfValidProcessed(time_valid,time_type, last_time_turn_on,data_json,product_id,inca_value):
    """ Helper function to valid time of Valid Processed table """
    time_valid = exceptions.checkIntegerVariable(time_valid)
    time_type = exceptions.checkStringVariable(time_type)
    data_json = exceptions.checkDictionaryVariable(data_json)
    product_id = exceptions.checkStringVariable(product_id)
    aditional_time = datetime.timedelta(hours=time_valid) if (time_type=="hour") else datetime.timedelta(minutes=time_valid)
    if(last_time_turn_on + aditional_time < datetime.datetime.now(dateutil.tz.tzutc())):
      validAndBeautyJsonValidProcessed(data_json,product_id,inca_value)
コード例 #2
0
def companyExistBasedOnRUC(ruc):
    """ Helper function to check if company name exist """
    ruc = exceptions.checkStringVariable(ruc)
    company_list = session.query(Company.ruc).filter_by(ruc=ruc).all()
    if (company_list == []):
        return False
    return True
コード例 #3
0
def qhawaxExistBasedOnName(qhawax_name):
    """ Helper function to check if qHAWAX name exist """
    qhawax_name = exceptions.checkStringVariable(qhawax_name)
    qhawax_list = session.query(Qhawax.name).filter_by(name=qhawax_name).all()
    if (qhawax_list == []):
        return False
    return True
コード例 #4
0
def queryDBGasAverageMeasurement(qhawax_name, gas_name):
    """ Helper function to get gas average measurement based on qHAWAX name and sensor name"""
    gas_name = exceptions.checkStringVariable(gas_name)

    if(gas_name not in sensor_array):
        raise ValueError("Sensor name "+str(gas_name)+" should be CO, H2S, NO2, O3, PM25, PM10 or SO2")

    qhawax_id = same_helper.getQhawaxID(qhawax_name)
    if(qhawax_id!= None):
        initial_timestamp = datetime.datetime.now()
        last_timestamp = datetime.datetime.now() - datetime.timedelta(hours=24)
        
        column_array = [AirQualityMeasurement.CO.label('sensor'), AirQualityMeasurement.H2S.label('sensor'), 
                        AirQualityMeasurement.NO2.label('sensor'), AirQualityMeasurement.O3.label('sensor'),
                        AirQualityMeasurement.PM25.label('sensor'), AirQualityMeasurement.PM10.label('sensor'),
                        AirQualityMeasurement.SO2.label('sensor')]

        for i in range(len(sensor_array)):
            if(gas_name==sensor_array[i]):
                sensors = (AirQualityMeasurement.timestamp_zone, column_array[i])

        return session.query(*sensors).filter(AirQualityMeasurement.qhawax_id == qhawax_id). \
                                   filter(AirQualityMeasurement.timestamp_zone >= last_timestamp). \
                                   filter(AirQualityMeasurement.timestamp_zone <= initial_timestamp). \
                                   order_by(AirQualityMeasurement.timestamp_zone.asc()).all()
    return None
コード例 #5
0
def companyExistBasedOnName(company_name):
    """ Helper function to check if company name exist """
    company_name = exceptions.checkStringVariable(company_name)
    company_list = session.query(
        Company.name).filter_by(name=company_name).all()
    if (company_list == []):
        return False
    return True
コード例 #6
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)
コード例 #7
0
def queryQhawaxTypeInFieldInPublicMode(qhawax_type):
    """ Get list of qHAWAXs in field in public mode based on qhawax type """
    qhawax_type = exception_helper.checkStringVariable(qhawax_type)
    qhawax_public = session.query(*columns_qhawax).\
                            join(EcaNoise, QhawaxInstallationHistory.eca_noise_id == EcaNoise.id). \
                            join(Qhawax, QhawaxInstallationHistory.qhawax_id == Qhawax.id). \
                            group_by(Qhawax.id, QhawaxInstallationHistory.id,EcaNoise.id). \
                            filter(Qhawax.qhawax_type==qhawax_type, QhawaxInstallationHistory.end_date_zone == None). \
                            order_by(Qhawax.id).all()
    return [qhawax._asdict() for qhawax in qhawax_public]
コード例 #8
0
def storeLogs(telemetry, drone_name):
    global drone_elapsed_time, drone_telemetry, drone_storage
    telemetry = exceptions.checkDictionaryVariable(telemetry)
    drone_name = exceptions.checkStringVariable(drone_name)
    if drone_elapsed_time is None:
        drone_elapsed_time = time.time()

    if drone_name not in drone_storage:
        qhawax_id = same_helper.getQhawaxID(drone_name) if same_helper.getQhawaxID(drone_name) is not None else 'qH001'
        drone_storage[drone_name] = qhawax_id

    if time.time() - drone_elapsed_time > MAX_SECONDS_DATA_STORAGE:
        drone_telemetry = formatTelemetryForStorage(telemetry)
        drone_telemetry['timestamp'] = datetime.datetime.now(dateutil.tz.tzutc())
        drone_telemetry['qhawax_id'] = drone_storage[drone_name]
        drone_telemetry = DroneTelemetry(**drone_telemetry)
        session.add(drone_telemetry)
        session.commit()
        drone_elapsed_time = time.time() 
コード例 #9
0
def queryQhawaxStatus(name):
    qhawax_type = exception_helper.checkStringVariable(name)
    return session.query(Qhawax.state).filter_by(name=name).one()[0]
コード例 #10
0
def isItFieldQhawax(qhawax_name):
    """Check qhawax in field """
    qhawax_type = exception_helper.checkStringVariable(qhawax_name)
    return True if (same_helper.getInstallationIdBaseName(qhawax_name)
                    is not None) else False