def test_completion_rates_for_location(self):
        masaka = Location.objects.create(name="masaka", tree_parent=self.uganda, type=self.city)
        ea = EnumerationArea.objects.create(name="EA2", survey=self.open_survey)
        ea.locations.add(masaka)
        investigator_3 = Investigator.objects.create(name='some_inv_2', mobile_number='123456787', male=True,
                                                     ea=ea)

        household_3 = Household.objects.create(investigator=investigator_3, ea=investigator_3.ea,
                                               survey=self.open_survey)
        HouseholdMember.objects.create(household=household_3, date_of_birth=date(1980, 05, 01))

        with patch.object(BatchCompletionRates, 'percent_completed_households', return_value=self.kampala_city.id):

            completion_rate = BatchHighLevelLocationsCompletionRates(self.batch, [self.kampala_city])
            completions = completion_rate.attributes()
            self.assertEqual(1, len(completions))

            completion_1 = completions[0]
            self.assertEqual(2, completion_1['total_households'])
            self.assertEqual(self.kampala_city.id, completion_1['completed_households_percent'])

            completions.remove(completion_1)

        with patch.object(BatchCompletionRates, 'percent_completed_households', return_value=masaka.id):
            completion_rate = BatchHighLevelLocationsCompletionRates(self.batch, [masaka])

            completions = completion_rate.attributes()
            self.assertEqual(1, len(completions))

            completion_2 = completions[0]
            self.assertEqual(1, completion_2['total_households'])
            self.assertEqual(masaka.id, completion_2['completed_households_percent'])
Esempio n. 2
0
    def test_completion_rates_for_ea(self):
        masaka = Location.objects.create(name="masaka",
                                         tree_parent=self.uganda,
                                         type=self.city)
        mbarara = Location.objects.create(name="mbarara",
                                          tree_parent=self.uganda,
                                          type=self.city)

        ea = EnumerationArea.objects.create(name="EA2",
                                            survey=self.open_survey)
        another_ea = EnumerationArea.objects.create(name="Another EA2",
                                                    survey=self.open_survey)
        ea.locations.add(masaka)
        ea.locations.add(mbarara)

        investigator_3 = Investigator.objects.create(name='some_inv_2',
                                                     mobile_number='123456787',
                                                     male=True,
                                                     ea=ea)
        another_investigator = Investigator.objects.create(
            name='some_inv_2',
            mobile_number='111111',
            male=True,
            ea=another_ea)

        Household.objects.create(investigator=investigator_3,
                                 ea=investigator_3.ea,
                                 survey=self.open_survey)
        Household.objects.create(investigator=investigator_3,
                                 ea=investigator_3.ea,
                                 survey=self.open_survey)
        Household.objects.create(investigator=another_investigator,
                                 ea=another_ea,
                                 survey=self.open_survey)

        with patch.object(BatchCompletionRates,
                          'percent_completed_households',
                          return_value=ea.id):
            completion_rate = BatchHighLevelLocationsCompletionRates(
                self.batch, [self.kampala_city], ea=ea)
            completions = completion_rate.attributes()

        self.assertEqual(1, len(completions))
        completion_1 = completions[0]
        self.assertEqual(2, completion_1['total_households'])
        self.assertEqual(ea.id, completion_1['completed_households_percent'])
    def test_completion_rates_for_ea(self):
        masaka = Location.objects.create(name="masaka", tree_parent=self.uganda, type=self.city)
        mbarara = Location.objects.create(name="mbarara", tree_parent=self.uganda, type=self.city)

        ea = EnumerationArea.objects.create(name="EA2", survey=self.open_survey)
        another_ea = EnumerationArea.objects.create(name="Another EA2", survey=self.open_survey)
        ea.locations.add(masaka)
        ea.locations.add(mbarara)

        investigator_3 = Investigator.objects.create(name='some_inv_2', mobile_number='123456787', male=True, ea=ea)
        another_investigator = Investigator.objects.create(name='some_inv_2', mobile_number='111111', male=True, ea=another_ea)

        Household.objects.create(investigator=investigator_3, ea=investigator_3.ea, survey=self.open_survey)
        Household.objects.create(investigator=investigator_3, ea=investigator_3.ea, survey=self.open_survey)
        Household.objects.create(investigator=another_investigator, ea=another_ea, survey=self.open_survey)

        with patch.object(BatchCompletionRates, 'percent_completed_households', return_value=ea.id):
            completion_rate = BatchHighLevelLocationsCompletionRates(self.batch, [self.kampala_city], ea=ea)
            completions = completion_rate.attributes()

        self.assertEqual(1, len(completions))
        completion_1 = completions[0]
        self.assertEqual(2, completion_1['total_households'])
        self.assertEqual(ea.id, completion_1['completed_households_percent'])
Esempio n. 4
0
    def test_completion_rates_for_location(self):
        masaka = Location.objects.create(name="masaka",
                                         tree_parent=self.uganda,
                                         type=self.city)
        ea = EnumerationArea.objects.create(name="EA2",
                                            survey=self.open_survey)
        ea.locations.add(masaka)
        investigator_3 = Investigator.objects.create(name='some_inv_2',
                                                     mobile_number='123456787',
                                                     male=True,
                                                     ea=ea)

        household_3 = Household.objects.create(investigator=investigator_3,
                                               ea=investigator_3.ea,
                                               survey=self.open_survey)
        HouseholdMember.objects.create(household=household_3,
                                       date_of_birth=date(1980, 05, 01))

        with patch.object(BatchCompletionRates,
                          'percent_completed_households',
                          return_value=self.kampala_city.id):

            completion_rate = BatchHighLevelLocationsCompletionRates(
                self.batch, [self.kampala_city])
            completions = completion_rate.attributes()
            self.assertEqual(1, len(completions))

            completion_1 = completions[0]
            self.assertEqual(2, completion_1['total_households'])
            self.assertEqual(self.kampala_city.id,
                             completion_1['completed_households_percent'])

            completions.remove(completion_1)

        with patch.object(BatchCompletionRates,
                          'percent_completed_households',
                          return_value=masaka.id):
            completion_rate = BatchHighLevelLocationsCompletionRates(
                self.batch, [masaka])

            completions = completion_rate.attributes()
            self.assertEqual(1, len(completions))

            completion_2 = completions[0]
            self.assertEqual(1, completion_2['total_households'])
            self.assertEqual(masaka.id,
                             completion_2['completed_households_percent'])
Esempio n. 5
0
def show(request):
    selected_location = None
    location_filter_form = LocationFilterForm()
    content = {'action': 'survey_completion_rates',
               'request': request}
    locations_filter = LocFilterForm(data=request.POST, include_ea=True)
    if request.method == 'POST':
        location_filter_form = LocationFilterForm(request.POST)
        if location_filter_form.is_valid():
            batch = location_filter_form.cleaned_data.get('batch', None)
            content['selected_batch'] = batch
            selected_location = locations_filter.last_location_selected
            selected_ea = request.POST.get('enumeration_area', None)
            if selected_ea:
                return render_household_details(request, selected_location, batch, selected_ea)
            if selected_location:
                high_level_locations = selected_location.get_children().order_by('name')
                content['selection_location_type'] = LocationType.objects.get(parent=selected_location.type)
            else:
                high_level_locations = __get_parent_level_locations()
            content['completion_rates'] = BatchHighLevelLocationsCompletionRates(batch, high_level_locations)
    content['locations_filter'] = locations_filter
    content['filter'] = location_filter_form
    return render(request, 'aggregates/completion_status.html', content)
Esempio n. 6
0
def show(request):
    selected_location = None
    location_filter_form = LocationFilterForm()
    content = {'action': 'survey_completion_rates', 'request': request}
    if request.method == 'POST':
        location_filter_form = LocationFilterForm(request.POST)
        if location_filter_form.is_valid():
            batch = location_filter_form.cleaned_data.get('batch', None)
            selected_location = location_filter_form.cleaned_data.get(
                'location', None)
            selected_ea = location_filter_form.cleaned_data.get('ea', None)
            if selected_ea:
                return render_household_details(request, selected_ea, batch)
            if selected_location:
                high_level_locations = selected_location.get_children(
                ).order_by('name')
            else:
                high_level_locations = __get_parent_level_locations()
            content[
                'completion_rates'] = BatchHighLevelLocationsCompletionRates(
                    batch, high_level_locations)
    content['locations'] = LocationWidget(selected_location)
    content['filter'] = location_filter_form
    return render(request, 'aggregates/completion_status.html', content)