def _format_answer(self, locations, answers, survey): question_options = self.options.all() data = SortedDict() for location in locations: households = Household.all_households_in(location, survey) data[location] = {option.text: answers.filter(answer=option, household__in=households).count() for option in question_options} return data
def _format_answer(self, locations, answers, survey): question_options = self.options.all() data = OrderedDict() for location in locations: households = Household.all_households_in(location, survey) data[location] = {option.text: answers.filter(value=option, interview__householdmember__household__in=households).count() for option in question_options} return data
def test_should_know_total_households_in_location(self): open_survey = Survey.objects.create(name="open survey", description="open survey", has_sampling=True) Household.objects.all().delete() kampala_city = Location.objects.create(name='Kampala City', tree_parent=self.kampala, type=self.city) ea = EnumerationArea.objects.create(name="EA2", survey=self.survey) ea.locations.add(kampala_city) investigator_1 = Interviewer.objects.create(name='some_inv', mobile_number='123456783', male=True, ea=self.ea) investigator_2 = Interviewer.objects.create(name='some_inv', mobile_number='123456781', male=True, ea=ea) household_1 = Household.objects.create(investigator=investigator_1, ea=investigator_1.ea, survey=open_survey) household_2 = Household.objects.create(investigator=investigator_2, ea=investigator_2.ea, survey=open_survey) self.assertEqual(2, Household.all_households_in(self.uganda, open_survey).count()) self.assertIn(household_1, Household.all_households_in(self.uganda, open_survey)) self.assertIn(household_2, Household.all_households_in(self.uganda, open_survey))
def test_should_know_total_households_in_location(self): open_survey = Survey.objects.create(name="open survey", description="open survey", has_sampling=True) Household.objects.all().delete() kampala_city = Location.objects.create(name='Kampala City', tree_parent=self.kampala, type=self.city) ea = EnumerationArea.objects.create(name="EA2", survey=self.survey) ea.locations.add(kampala_city) investigator_1 = Investigator.objects.create(name='some_inv', mobile_number='123456783', male=True, ea=self.ea) investigator_2 = Investigator.objects.create(name='some_inv', mobile_number='123456781', male=True, ea=ea) household_1 = Household.objects.create(investigator=investigator_1, ea=investigator_1.ea, survey=open_survey) household_2 = Household.objects.create(investigator=investigator_2, ea=investigator_2.ea, survey=open_survey) self.assertEqual(2, Household.all_households_in(self.uganda, open_survey).count()) self.assertIn(household_1, Household.all_households_in(self.uganda, open_survey)) self.assertIn(household_2, Household.all_households_in(self.uganda, open_survey))
def _format_answer(self, locations, answers, survey): question_options = self.options.all() data = OrderedDict() for location in locations: households = Household.all_households_in(location, survey) data[location] = { option.text: answers.filter( value=option, interview__householdmember__household__in=households). count() for option in question_options } return data
def test_knows_number_of_households_in_an_ea(self): kisasi = Location.objects.create(name="Kisasi", type=self.city, tree_parent=self.uganda) ea = EnumerationArea.objects.create(name="EA2", survey=self.survey) ea.locations.add(kisasi) investigator_1 = Interviewer.objects.create(name='some_inv', mobile_number='123456783', male=True, ea=self.ea) household_1 = Household.objects.create(uid='123', investigator=investigator_1, ea=investigator_1.ea, survey=self.survey) household_3 = Household.objects.create(uid='123', investigator=investigator_1, survey=self.survey, ea=ea) households_in_ea = Household.all_households_in(self.uganda, self.survey, ea=self.ea) self.assertEqual(households_in_ea.count(), 2) self.assertIn(household_1, households_in_ea) self.assertIn(self.household, households_in_ea) self.assertNotIn(household_3, households_in_ea)
def test_knows_number_of_households_in_an_ea(self): kisasi = Location.objects.create(name="Kisasi", type=self.city, tree_parent=self.uganda) ea = EnumerationArea.objects.create(name="EA2", survey=self.survey) ea.locations.add(kisasi) investigator_1 = Investigator.objects.create(name='some_inv', mobile_number='123456783', male=True, ea=self.ea) household_1 = Household.objects.create(uid='123', investigator=investigator_1, ea=investigator_1.ea, survey=self.survey) household_3 = Household.objects.create(uid='123', investigator=investigator_1, survey=self.survey, ea=ea) households_in_ea = Household.all_households_in(self.uganda, self.survey, ea=self.ea) self.assertEqual(households_in_ea.count(), 2) self.assertIn(household_1, households_in_ea) self.assertIn(self.household, households_in_ea) self.assertNotIn(household_3, households_in_ea)