예제 #1
0
    def test_knows_all_locations_given_type_of_location(self):
        locations = BatchSurveyCompletionRates(self.district).locations
        self.assertIn(self.abim, locations)
        self.assertIn(self.zombo, locations)

        locations = BatchSurveyCompletionRates(self.city).locations
        self.assertIn(self.kampala, locations)
        self.assertIn(self.apachi, locations)
예제 #2
0
def completion_json(request, survey_id):
    survey = Survey.objects.get(id=survey_id)
    location_type = LocationType.objects.get(name='District')
    completion_rates = BatchSurveyCompletionRates(
        location_type).get_completion_formatted_for_json(survey)
    json_dump = json.dumps(completion_rates, cls=DjangoJSONEncoder)
    return HttpResponse(json_dump, mimetype='application/json')
예제 #3
0
def add_to_redis():
    r_server = redis.Redis()
    survey_all = Survey.objects.all().values_list("id")
    for id in survey_all:
        key = settings.SURVEY_REDIS_KEY%{'survey_id':str(id[0])}
        survey = Survey.objects.get(id=id[0])
        location_type = LocationType.largest_unit()
        expire_time = (settings.RESULT_REFRESH_FREQ*60+30)*60
        completion_rates = BatchSurveyCompletionRates(location_type).get_completion_formatted_for_json(survey)
        json_dump = json.dumps(completion_rates, cls=DjangoJSONEncoder)
        r_server.set(key, json_dump)
        r_server.expire(key,expire_time)
예제 #4
0
    def test_returns_minus_one_when_no_batch_is_open_in_the_location(self):
        kisoro = Location.objects.create(name='Kisoro', type=self.district)

        survey = Survey.objects.create(name="open survey",
                                       description="open survey",
                                       has_sampling=True)
        batch = Batch.objects.create(order=1, name='B', survey=survey)
        batch.open_for_location(self.abim)

        with patch.object(BatchLocationCompletionRates,
                          'percent_completed_households',
                          return_value=10):
            completion = BatchSurveyCompletionRates(self.district)
            self.assertEqual(
                -1,
                completion.get_completion_formatted_for_json(survey)[
                    kisoro.name])
            self.assertNotEqual(
                0,
                completion.get_completion_formatted_for_json(survey)[
                    self.abim.name])
예제 #5
0
 def get_result_json():
     print "Getting data from DB"
     survey = Survey.objects.get(id=survey_id)
     location_type = LocationType.largest_unit()
     completion_rates = BatchSurveyCompletionRates(location_type).get_completion_formatted_for_json(survey)
     return json.dumps(completion_rates, cls=DjangoJSONEncoder)
예제 #6
0
    def test_knows_completion_rates_for_location_type(self):

        household_1_member = HouseholdMember.objects.create(
            household=self.household_1, date_of_birth=date(1980, 05, 01))
        household_2_member = HouseholdMember.objects.create(
            household=self.household_2, date_of_birth=date(1980, 05, 01))
        household_3_member = HouseholdMember.objects.create(
            household=self.household_3, date_of_birth=date(1980, 05, 01))
        household_4_member = HouseholdMember.objects.create(
            household=self.household_4, date_of_birth=date(1980, 05, 01))

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_1,
            householdmember=household_1_member,
            batch=self.batch,
            investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_2,
            householdmember=household_2_member,
            batch=self.batch,
            investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_3,
            householdmember=household_3_member,
            batch=self.batch,
            investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_3,
            householdmember=household_4_member,
            batch=self.batch,
            investigator=self.investigator_1)

        self.household_5 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)
        self.household_6 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)
        self.household_7 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)
        self.household_8 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)

        household_5_member = HouseholdMember.objects.create(
            household=self.household_5, date_of_birth=date(1980, 05, 01))
        household_6_member = HouseholdMember.objects.create(
            household=self.household_6, date_of_birth=date(1980, 05, 01))

        HouseholdMember.objects.create(household=self.household_7,
                                       date_of_birth=date(1980, 05, 01))
        HouseholdMember.objects.create(household=self.household_8,
                                       date_of_birth=date(1980, 05, 01))

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_1,
            householdmember=household_5_member,
            batch=self.batch,
            investigator=self.investigator_2)
        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_2,
            householdmember=household_6_member,
            batch=self.batch,
            investigator=self.investigator_2)

        district_level_completion = BatchSurveyCompletionRates(self.district)
        expected_completion = {self.zombo.name: 25.0, self.abim.name: 50.0}
        self.assertEqual(
            district_level_completion.get_completion_formatted_for_json(
                self.survey), expected_completion)