Esempio n. 1
0
def status_filter(self, query, criteria):
    StatusTable = Base.metadata.tables['IndividualStatus']
    query = query.where(
        eval_.eval_binary_expr(StatusTable.c['Status_'], criteria['Operator'],
                               criteria['Value']))

    return query
Esempio n. 2
0
def fk_sensorType_filter(self, query, criteria):
    ## TODO FK_SensorType on history
    #         if self.history:
    #             query = self.whereInEquipement(query, [criteria])
    if self.from_history is None:
        query = query.where(
            eval_.eval_binary_expr(Sensor._type_id, criteria['Operator'],
                                   criteria['Value']))
    return query
Esempio n. 3
0
def fk_sensor_filter(self, query, criteria):
    ## TODO FK_sensor on history
    #         if self.history:
    #             query = self.whereInEquipement(query, [criteriaObj])
    if self.from_history is None:
        query = query.where(
            eval_.eval_binary_expr(Sensor.UnicIdentifier, criteria['Operator'],
                                   criteria['Value']))

    return query
def protocoleType_filter(self, modelToAdd, modelRel, criteria):

    if Observation.ID not in modelToAdd:
        modelToAdd.append(Observation.ID)
        modelRel.append(Station.ID == Observation.FK_Station)

    clauseToAdd = eval_.eval_binary_expr(Observation._type_id,
                                         criteria['Operator'],
                                         criteria['Value'])

    return clauseToAdd
def fieldworker_filter(self, modelToAdd, modelRel, criteria):

    modelToAdd.append(Station_FieldWorker.ID)
    modelToAdd.append(Station_FieldWorker.FK_Station)
    modelToAdd.append(Station_FieldWorker.FK_FieldWorker)
    modelToAdd.append(User.id)
    modelRel.append(Station.ID == Station_FieldWorker.FK_Station)
    modelRel.append(Station_FieldWorker.FK_FieldWorker == User.id)

    clauseToAdd = eval_.eval_binary_expr(User.Login, criteria['Operator'],
                                         criteria['Value'])

    return clauseToAdd
Esempio n. 6
0
def frequency_VHF_filter(self, query, criteria):
    startDate = self.startDate

    freq = criteria['Value']
    e2 = aliased(Equipment)
    vs = Base.metadata.tables['SensorDynPropValuesNow']
    join_table_exist = join(Equipment, Sensor,
                            Equipment.FK_Sensor == Sensor.ID)
    join_table_exist = join(join_table_exist, vs,
                            vs.c['FK_Sensor'] == Sensor.ID)

    if self.from_history == 'all':
        queryExist = select(
            [e2]).where(Equipment.FK_Individual == e2.FK_Individual)
        fullQueryExist = select([Equipment.FK_Individual
                                 ]).select_from(join_table_exist).where(
                                     Equipment.FK_Individual == Individual.ID)
        fullQueryExist = fullQueryExist.where(
            and_(vs.c['FK_SensorDynProp'] == 9, Sensor.type_id == 4))

    else:
        queryExist = select([e2]).where(
            and_(
                Equipment.FK_Individual == e2.FK_Individual,
                and_(e2.StartDate > Equipment.StartDate,
                     e2.StartDate < startDate)))

        fullQueryExist = select([Equipment.FK_Individual
                                 ]).select_from(join_table_exist)
        fullQueryExist = fullQueryExist.where(
            and_(
                ~exists(queryExist),
                and_(
                    vs.c['FK_SensorDynProp'] == 9,
                    and_(
                        Sensor.type_id == 4,
                        and_(
                            Equipment.Deploy == 1,
                            and_(Equipment.StartDate < startDate,
                                 Equipment.FK_Individual == Individual.ID))))))

    if criteria['Operator'].lower() in ['is null']:
        query = query.where(~exists(fullQueryExist))
    else:
        fullQueryExist = fullQueryExist.where(
            eval_.eval_binary_expr(vs.c['ValueInt'], criteria['Operator'],
                                   freq))
        query = query.where(exists(fullQueryExist))

    return query
def species_filter(self, modelToAdd, modelRel, criteria):

    if Observation.ID not in modelToAdd:
        modelToAdd.append(Observation.ID)
        modelRel.append(Station.ID == Observation.FK_Station)

    observationDynPropValue = Observation.DynamicValuesClass
    observationDynProp = Observation.TypeClass.PropertiesClass
    if Observation.DynamicValuesClass.ID not in modelToAdd:
        modelToAdd.append(observationDynPropValue.ID)
        modelToAdd.append(observationDynProp.ID)
        modelToAdd.append(observationDynPropValue.fk_parent)
        modelToAdd.append(observationDynPropValue.fk_property)
        modelRel.append(Observation.ID == observationDynPropValue.fk_parent)
        modelRel.append(
            observationDynProp.ID == observationDynPropValue.fk_property)

    clauseToAdd = and_(
        or_(observationDynProp.Name.like('%taxon'),
            observationDynProp.Name.like('%species%')),
        eval_.eval_binary_expr(observationDynPropValue.ValueString,
                               criteria['Operator'],
                               criteria['Value'])).self_group()
    return clauseToAdd