Пример #1
0
 def test_is_above_threshold(self):
     group = DefinitionGroup(
         name="G2",
         model=None,
         cycle="",
         selected_fields=["consumption"],
         selected_formulations=[],
         sample_formulation_model_overridden={},
         sample_formulation_model_overrides={},
         aggregation=sum_comparison,
         has_factors=None,
         factors=None,
         has_thresholds=True,
         thresholds={
             u"abc3tc-paed": 10, u"efv200-paed": 10, u"tdf3tcefv-adult": "200"
         },
     )
     result = GroupResult(
         group=group,
         values=None,
         factored_records=[],
         aggregate=500.0,
         tracer=Tracer.F1(),
     )
     self.assertEqual(result.is_above_threshold(), True)
Пример #2
0
    def test_groups_have_insufficient_data_if_the_aggregate_is_below_the_threshold(
            self):
        group1 = DefinitionGroup(
            name="G1",
            model=None,
            cycle=current_cycle,
            selected_fields=["consumption"],
            selected_formulations=[],
            sample_formulation_model_overridden={},
            sample_formulation_model_overrides={},
            aggregation=sum_comparison,
            has_factors=None,
            factors=None,
            has_thresholds=True,
            thresholds={
                u"abc3tc-paed": 10,
                u"efv200-paed": 10,
                u"tdf3tcefv-adult": 200
            },
        )
        group2 = DefinitionGroup(
            name="G2",
            model=None,
            cycle=previous_cycle,
            selected_fields=["consumption"],
            selected_formulations=[],
            sample_formulation_model_overridden={},
            sample_formulation_model_overrides={},
            aggregation=sum_comparison,
            has_factors=None,
            factors=None,
            has_thresholds=True,
            thresholds={
                u"abc3tc-paed": 10,
                u"efv200-paed": 10,
                u"tdf3tcefv-adult": 200
            },
        )
        result1 = GroupResult(
            group=group1,
            values=None,
            factored_records=[r1],
            aggregate=50.0,
            tracer=tracer,
        )

        result2 = GroupResult(
            group=group2,
            values=None,
            factored_records=[r2],
            aggregate=40.0,
            tracer=tracer,
        )

        self.assertFalse(Comparison().groups_have_adequate_data(
            [result1, result2]))
Пример #3
0
    def _group_values_from_db(self, group, cycle, sample_location, tracer):
        model = group.model.as_model()
        if group.has_overrides:
            model_id = group.sample_formulation_model_overrides.get(
                tracer.key, {}).get("id", None)
            if model_id:
                model = group.model.as_model(model_id)
        if model:
            formulations = self.get_formulations(group, tracer)
            db_records = model.objects.filter(
                name=sample_location["name"],
                cycle=parse_cycle(cycle, group),
                district=sample_location["district"],
                formulation__in=formulations,
            ).values_list("formulation", *group.selected_fields)
            records = [
                DataRecord(formulation=r[0],
                           fields=group.selected_fields,
                           values=r[1:]) for r in db_records
            ]

            factored_values = get_factored_records(group.factors, records)
            return GroupResult(
                group=group,
                values=records,
                factored_records=factored_values,
                tracer=tracer,
                aggregate=self.aggregate_values(group, factored_values),
            )
Пример #4
0
    def _group_values_from_location_data(self, group, facility_data,
                                         other_facility_data, tracer):
        data_source = other_facility_data if group.cycle and group.cycle.id == "Previous" else facility_data
        records = self.get_records_from_data_source(data_source, group)

        if records:
            formulations = self.get_formulations(group, tracer)
            data_records = self.get_values_from_records(
                records, formulations, group.selected_fields)
            factored_records = get_factored_records(group.factors,
                                                    data_records)
            return GroupResult(
                group=group,
                values=data_records,
                factored_records=factored_records,
                tracer=tracer,
                aggregate=self.aggregate_values(group, factored_records),
            )

        return GroupResult(group=group,
                           values=[],
                           factored_records=[],
                           tracer=tracer,
                           aggregate=None)