예제 #1
0
 def test_gathers_only_error_free_messages(self):
     self.record_response("8 boys", 8, has_errors=False)
     self.record_response("My phone number is 0794443337",
                          794443337,
                          has_errors=True)
     self.assertEqual(1, NumericResponsesFor([self.poll]).query.count())
     self.assertEqual(8, NumericResponsesFor([self.poll]).total())
예제 #2
0
def get_numeric_enrollment_data(polls, locations, time_range):
    results = NumericResponsesFor(polls).forDateRange(time_range) \
        .forLocations(locations) \
        .excludeZeros() \
        .groupBySchools()

    return sum(results.values()), results.keys()
예제 #3
0
 def test_gathers_only_incoming_messages(self):
     self.record_response("8 boys", 8, direction='I')
     self.record_response("Do you have more than 1 latrine?",
                          None,
                          direction='O')
     self.assertEqual(1, NumericResponsesFor([self.poll]).query.count())
     self.assertEqual(8, NumericResponsesFor([self.poll]).total())
예제 #4
0
 def test_groups_by_location(self):
     self.record_response_for(self.reporter_for(self.kampala), "6 boys", 6)
     self.record_response_for(self.reporter_for(self.kampala), "7 boys", 7)
     self.record_response_for(self.reporter_for(self.gulu), "9 boys", 9)
     results = NumericResponsesFor([self.poll]).groupByLocation()
     self.assertEqual(13, results[self.kampala.id])
     self.assertEqual(9, results[self.gulu.id])
예제 #5
0
 def test_filters_by_value(self):
     self.record_response_for(self.reporter_for(self.kampala), "6 boys", 6)
     self.record_response_for(self.reporter_for(self.kampala), "6 boys", 6)
     self.record_response_for(self.reporter_for(self.kampala), "7 boys", 7)
     self.record_response_for(self.reporter_for(self.gulu), "9 boys", 9)
     self.assertEqual(
         19,
         NumericResponsesFor([self.poll]).forValues([6, 7]).total())
예제 #6
0
 def test_calculates_mode(self):
     self.record_response("8 boys", 8)
     self.record_response("9 boys", 9)
     self.record_response("9 boys", 9)
     self.record_response("10 boys", 10)
     self.record_response("10 boys", 10)
     self.record_response("10 boys", 10)
     self.assertEqual(10, NumericResponsesFor([self.poll]).mode())
예제 #7
0
 def test_groups_by_location(self):
     gulu = Location.objects.create(name="Gulu")
     kampala = Location.objects.create(name="Kampala")
     self.record_response_for(self.reporter_for(kampala), "6 boys", 6)
     self.record_response_for(self.reporter_for(kampala), "7 boys", 7)
     self.record_response_for(self.reporter_for(gulu), "9 boys", 9)
     results = NumericResponsesFor([self.poll]).groupByLocation()
     self.assertEqual(13, results[kampala.id])
     self.assertEqual(9, results[gulu.id])
예제 #8
0
    def test_filters_by_school(self):
        (mary, st_marys) = self.create_teacher_with_school()
        (mark, st_marks) = self.create_teacher_with_school()

        self.record_response_for(mary, "3 girls", 3)
        self.record_response_for(mark, "2 boys", 2)
        self.assertEqual(
            3,
            NumericResponsesFor([self.poll]).forSchools([st_marys]).total())
예제 #9
0
    def test_filters_by_date_range(self):
        today = now
        yesterday = today - timedelta(days=1)
        tomorrow = today + timedelta(days=1)
        next_week = today + timedelta(days=7)

        self.record_response("6 boys", 6, date=yesterday)
        self.record_response("10 boys", 10, date=tomorrow)

        self.assertEqual(10, NumericResponsesFor([self.poll]).forDateRange((today,next_week)).total())
예제 #10
0
    def test_groups_by_school(self):
        (mary, st_marys) = self.create_teacher_with_school()
        (mark, st_marks) = self.create_teacher_with_school()

        self.record_response_for(mary, "3 girls", 3)
        self.record_response_for(mary, "4 girls", 4)
        self.record_response_for(mark, "2 boys", 2)
        results = NumericResponsesFor([self.poll]).groupBySchools()

        self.assertEqual(7, results[st_marys.id])
        self.assertEqual(2, results[st_marks.id])
예제 #11
0
    def test_filters_by_school(self):
        gulu = Location.objects.create(name="Gulu")

        mary = EmisReporter.objects.create()
        st_marys = School.objects.create(name="St Marys", location=gulu)
        mary.schools = [st_marys]
        mary.save()

        mark = EmisReporter.objects.create()
        st_marks = School.objects.create(name="St Marks", location=gulu)
        mark.schools = [st_marks]
        mark.save()

        self.record_response_for(mary, "3 girls", 3)
        self.record_response_for(mark, "2 boys", 2)
        self.assertEqual(3, NumericResponsesFor([self.poll]).forSchools([st_marys]).total())
예제 #12
0
    def test_groups_by_school(self):
        gulu = Location.objects.create(name="Gulu")

        mary = EmisReporter.objects.create()
        st_marys = School.objects.create(name="St Marys", location=gulu)
        mary.schools = [st_marys]
        mary.save()

        mark = EmisReporter.objects.create()
        st_marks = School.objects.create(name="St Marks", location=gulu)
        mark.schools = [st_marks]
        mark.save()

        self.record_response_for(mary, "3 girls", 3)
        self.record_response_for(mary, "4 girls", 4)
        self.record_response_for(mark, "2 boys", 2)
        results = NumericResponsesFor([self.poll]).groupBySchools()

        self.assertEqual(7, results[st_marys.id])
        self.assertEqual(2, results[st_marks.id])
예제 #13
0
def get_numeric_data_all_schools_for_locations(polls, locations, time_range):
    return NumericResponsesFor(polls).forDateRange(time_range) \
        .forLocations(locations) \
        .groupBySchools()
예제 #14
0
 def test_excludes_zeros(self):
     self.record_response("0 boys", 0)
     self.record_response("10 boys", 10)
     self.assertEqual(1, NumericResponsesFor([self.poll]).excludeZeros().query.count())
예제 #15
0
def get_numeric_data(polls, locations, time_range):
    return NumericResponsesFor(polls).forDateRange(time_range).forLocations(
        locations).total()
예제 #16
0
 def test_mode_defaults_to_zero(self):
     self.assertEqual(0, NumericResponsesFor([self.poll]).mode())
예제 #17
0
 def test_calculates_mean(self):
     self.record_response("6 boys", 6)
     self.record_response("10 boys", 10)
     self.assertEqual(8, NumericResponsesFor([self.poll]).mean())
예제 #18
0
def get_numeric_data_for_location(polls, locations, time_range):
    return NumericResponsesFor(polls).forDateRange(time_range).forLocations(
        locations).groupByLocation()
예제 #19
0
 def test_excludes_greater_than(self):
     self.record_response("6 boys", 6)
     self.record_response("10 boys", 10)
     self.assertEqual(6, NumericResponsesFor([self.poll]).excludeGreaterThan(6).total())
예제 #20
0
def get_numeric_data_by_school(polls, schools, time_range):
    return NumericResponsesFor(polls).forDateRange(time_range) \
        .forSchools(schools) \
        .groupBySchools() \
        .values()
예제 #21
0
 def test_filters_by_location(self):
     gulu = Location.objects.create(name="Gulu")
     kampala = Location.objects.create(name="Kampala")
     self.record_response_for(self.reporter_for(kampala), "6 boys", 6)
     self.record_response_for(self.reporter_for(gulu), "9 boys", 9)
     self.assertEqual(9, NumericResponsesFor([self.poll]).forLocations([gulu]).total())
예제 #22
0
 def test_filters_by_location(self):
     self.record_response_for(self.reporter_for(self.kampala), "6 boys", 6)
     self.record_response_for(self.reporter_for(self.gulu), "9 boys", 9)
     self.assertEqual(
         9,
         NumericResponsesFor([self.poll]).forLocations([self.gulu]).total())