def test_count_by_variable(self): counts = FacilityRecord.counts_by_variable(self.lgas[0]) expected_dict = { 'test': { 'power': { 'none': 2, 'good': 1, 'bad': 1, }, 'has_water': { True: 2, False: 2, }, 'num_doctors': { 10.0: 2, 20.0: 1, 30.0: 1, }, } } self.assertEquals(counts, expected_dict) counts = FacilityRecord.counts_of_boolean_variables(self.lgas[0]) expected_dict = {'test': {'has_water': expected_dict['test']['has_water']}} self.assertEquals(counts, expected_dict)
def boolean_counts_for_facilities_in_lga(request, lga_id): lga = LGA.objects.get(id=lga_id) text = json.dumps(FacilityRecord.counts_of_boolean_variables(lga), indent=4, sort_keys=True) return HttpResponse(text)