def test_sector_data(self): self.assertDictEqual( get_clean_water_sector_data('icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'block_id': 'b1', 'aggregation_level': 4 }, location_id='b1', loc_level='supervisor'), { "info": awcs_reported_clean_drinking_water_help_text(), "tooltips_data": { "s2": { "in_month": 3, "all": 3 }, "s1": { "in_month": 5, "all": 5 } }, "chart_data": [{ "color": MapColors.BLUE, "values": [["s1", 1.0], ["s2", 1.0]], "strokeWidth": 2, "classed": "dashed", "key": "" }] })
def test_sector_data(self): self.assertDictEqual( get_clean_water_sector_data( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'block_id': 'b1', 'aggregation_level': 4 }, location_id='b1', loc_level='supervisor' ), { "info": awcs_reported_clean_drinking_water_help_text(), "tooltips_data": { "s2": { "in_month": 3, "all": 3 }, "s1": { "in_month": 5, "all": 5 } }, "chart_data": [ { "color": MapColors.BLUE, "values": [ [ "s1", 1.0 ], [ "s2", 1.0 ] ], "strokeWidth": 2, "classed": "dashed", "key": "" } ] } )
def test_map_name_is_different_data(self): self.assertDictEqual( get_clean_water_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ), { "rightLegend": { "info": awcs_reported_clean_drinking_water_help_text(), "average": 100.0, 'extended_info': [{ 'indicator': 'Total number of AWCs with a source of clean drinking water:', 'value': "17" }, { 'indicator': '% of AWCs with a source of clean drinking water:', 'value': '100.00%' }] }, "label": "Percentage of AWCs that reported having a source of clean drinking water", "data": { "block_map": { "in_month": 17, "original_name": ["b1", "b2"], "all": 17, "fillKey": "75%-100%" } }, "slug": "clean_water", "fills": { "0%-25%": MapColors.RED, "25%-75%": MapColors.ORANGE, "75%-100%": MapColors.PINK, "defaultFill": MapColors.GREY } })
def test_map_name_is_different_data(self): self.assertDictEqual( get_clean_water_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ), { "rightLegend": { "info": awcs_reported_clean_drinking_water_help_text(), "average": 100.0, 'extended_info': [ { 'indicator': 'Total number of AWCs with a source of clean drinking water:', 'value': "17" }, {'indicator': '% of AWCs with a source of clean drinking water:', 'value': '100.00%'} ] }, "label": "Percentage of AWCs that reported having a source of clean drinking water", "data": { "block_map": { "in_month": 17, "original_name": [ "b1", "b2" ], "all": 17, "fillKey": "75%-100%" } }, "slug": "clean_water", "fills": { "0%-25%": MapColors.RED, "25%-75%": MapColors.ORANGE, "75%-100%": MapColors.PINK, "defaultFill": MapColors.GREY } } )
def test_data_AWCs_reported_clean_drinking_water(self): self.assertDictEqual( get_awc_infrastructure_data( 'icds-cas', { 'month': (2017, 5, 1), 'prev_month': (2017, 4, 1), 'aggregation_level': 1 })['records'][0][0], { "redirect": "awc_infrastructure/clean_water", "all": 30, "format": "percent_and_div", "color": "red", "percent": -3.3333333333333286, "value": 29, "label": "AWCs Reported Clean Drinking Water", "frequency": "month", "help_text": awcs_reported_clean_drinking_water_help_text() })
def test_map_data(self): self.assertDictEqual( get_clean_water_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'aggregation_level': 1 }, loc_level='state' ), { "rightLegend": { "info": awcs_reported_clean_drinking_water_help_text(), "average": 96.66666666666667, 'extended_info': [ { 'indicator': 'Total number of AWCs with a source of clean drinking water:', 'value': "29" }, {'indicator': '% of AWCs with a source of clean drinking water:', 'value': '96.67%'} ] }, "label": "Percentage of AWCs that reported having a source of clean drinking water", "data": { 'st4': {'in_month': 0, 'original_name': ['st4'], 'all': 0, 'fillKey': '0%-25%'}, 'st5': {'in_month': 0, 'original_name': ['st5'], 'all': 0, 'fillKey': '0%-25%'}, 'st6': {'in_month': 0, 'original_name': ['st6'], 'all': 0, 'fillKey': '0%-25%'}, 'st7': {'in_month': 0, 'original_name': ['st7'], 'all': 0, 'fillKey': '0%-25%'}, 'st1': {'in_month': 17, 'original_name': ['st1'], 'all': 17, 'fillKey': '75%-100%'}, 'st2': {'in_month': 12, 'original_name': ['st2'], 'all': 13, 'fillKey': '75%-100%'}, 'st3': {'in_month': 0, 'original_name': ['st3'], 'all': 0, 'fillKey': '0%-25%'} }, "slug": "clean_water", "fills": { "0%-25%": MapColors.RED, "25%-75%": MapColors.ORANGE, "75%-100%": MapColors.PINK, "defaultFill": MapColors.GREY } } )
def test_map_data(self): self.assertDictEqual( get_clean_water_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'aggregation_level': 1 }, loc_level='state' ), { "rightLegend": { "info": awcs_reported_clean_drinking_water_help_text(), "average": 96.66666666666667, 'extended_info': [ { 'indicator': 'Total number of AWCs with a source of clean drinking water:', 'value': "29" }, {'indicator': '% of AWCs with a source of clean drinking water:', 'value': '96.67%'} ] }, "label": "Percentage of AWCs that reported having a source of clean drinking water", "data": { 'st4': {'in_month': 0, 'original_name': ['st4'], 'all': 0, 'fillKey': '0%-25%'}, 'st5': {'in_month': 0, 'original_name': ['st5'], 'all': 0, 'fillKey': '0%-25%'}, 'st6': {'in_month': 0, 'original_name': ['st6'], 'all': 0, 'fillKey': '0%-25%'}, 'st7': {'in_month': 0, 'original_name': ['st7'], 'all': 0, 'fillKey': '0%-25%'}, 'st1': {'in_month': 17, 'original_name': ['st1'], 'all': 17, 'fillKey': '75%-100%'}, 'st2': {'in_month': 12, 'original_name': ['st2'], 'all': 13, 'fillKey': '75%-100%'}, 'st3': {'in_month': 0, 'original_name': ['st3'], 'all': 0, 'fillKey': '0%-25%'} }, "slug": "clean_water", "fills": { "0%-25%": MapColors.RED, "25%-75%": MapColors.ORANGE, "75%-100%": MapColors.PINK, "defaultFill": MapColors.GREY } } )
def test_data_AWCs_reported_clean_drinking_water(self): self.assertDictEqual( get_awc_infrastructure_data( 'icds-cas', { 'month': (2017, 5, 1), 'prev_month': (2017, 4, 1), 'aggregation_level': 1 } )['records'][0][0], { "redirect": "awc_infrastructure/clean_water", "all": 30, "format": "percent_and_div", "color": "red", "percent": -3.3333333333333286, "value": 29, "label": "AWCs Reported Clean Drinking Water", "frequency": "month", "help_text": awcs_reported_clean_drinking_water_help_text() } )
def get_awc_infrastructure_data(domain, config, show_test=False): def get_data_for(month, filters): queryset = AggAwcMonthly.objects.filter( month=month, **filters ).values( 'aggregation_level' ).annotate( clean_water=Sum('infra_clean_water'), functional_toilet=Sum('infra_functional_toilet'), medicine_kits=Sum('infra_medicine_kits'), infant_scale=Sum('infra_infant_weighing_scale'), adult_scale=Sum('infra_adult_weighing_scale'), sum_last_update=Sum('num_awc_infra_last_update') ) if not show_test: queryset = apply_exclude(domain, queryset) return queryset current_month = datetime(*config['month']) previous_month = datetime(*config['prev_month']) del config['month'] del config['prev_month'] this_month_data = get_data_for(current_month, config) prev_month_data = get_data_for(previous_month, config) return { 'records': [ [ { 'label': _('AWCs Reported Clean Drinking Water'), 'help_text': awcs_reported_clean_drinking_water_help_text(), 'percent': percent_diff( 'clean_water', this_month_data, prev_month_data, 'sum_last_update' ), 'color': get_color_with_green_positive(percent_diff( 'clean_water', this_month_data, prev_month_data, 'sum_last_update' )), 'value': get_value(this_month_data, 'clean_water'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/clean_water' }, { 'label': _("AWCs Reported Functional Toilet"), 'help_text': awcs_reported_functional_toilet_help_text(), 'percent': percent_diff( 'functional_toilet', this_month_data, prev_month_data, 'sum_last_update' ), 'color': get_color_with_green_positive(percent_diff( 'functional_toilet', this_month_data, prev_month_data, 'sum_last_update' )), 'value': get_value(this_month_data, 'functional_toilet'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/functional_toilet' } ], [ # { # 'label': _('AWCs with Electricity'), # 'help_text': _('Percentage of AWCs with access to electricity'), # 'percent': 0, # 'value': 0, # 'all': 0, # 'format': 'percent_and_div', # 'frequency': 'month' # }, { 'label': _('AWCs Reported Weighing Scale: Infants'), 'help_text': awcs_reported_weighing_scale_infants_help_text(), 'percent': percent_diff( 'infant_scale', this_month_data, prev_month_data, 'sum_last_update' ), 'color': get_color_with_green_positive(percent_diff( 'infant_scale', this_month_data, prev_month_data, 'sum_last_update' )), 'value': get_value(this_month_data, 'infant_scale'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/infants_weight_scale' }, { 'label': _('AWCs Reported Weighing Scale: Mother and Child'), 'help_text': awcs_reported_weighing_scale_mother_and_child_help_text(), 'percent': percent_diff( 'adult_scale', this_month_data, prev_month_data, 'sum_last_update' ), 'color': get_color_with_green_positive(percent_diff( 'adult_scale', this_month_data, prev_month_data, 'sum_last_update' )), 'value': get_value(this_month_data, 'adult_scale'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/adult_weight_scale' } ], [ { 'label': _('AWCs Reported Medicine Kit'), 'help_text': awcs_reported_medicine_kit_help_text(), 'percent': percent_diff( 'medicine_kits', this_month_data, prev_month_data, 'sum_last_update' ), 'color': get_color_with_green_positive(percent_diff( 'medicine_kits', this_month_data, prev_month_data, 'sum_last_update' )), 'value': get_value(this_month_data, 'medicine_kits'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/medicine_kit' } ], # [ # { # 'label': _('AWCs with infantometer'), # 'help_text': _('Percentage of AWCs with an Infantometer'), # 'percent': 0, # 'value': 0, # 'all': 0, # 'format': 'percent_and_div', # 'frequency': 'month' # }, # { # 'label': _('AWCs with Stadiometer'), # 'help_text': _('Percentage of AWCs with a Stadiometer'), # 'percent': 0, # 'value': 0, # 'all': 0, # 'format': 'percent_and_div', # 'frequency': 'month' # } # ] ] }
def get_awc_infrastructure_data(domain, config, show_test=False): def get_data_for(month, filters): queryset = AggAwcMonthly.objects.filter( month=month, **filters ).values( 'aggregation_level' ).annotate( clean_water=Sum('infra_clean_water'), functional_toilet=Sum('infra_functional_toilet'), medicine_kits=Sum('infra_medicine_kits'), infant_scale=Sum('infra_infant_weighing_scale'), adult_scale=Sum('infra_adult_weighing_scale'), sum_last_update=Sum('num_awc_infra_last_update') ) if not show_test: queryset = apply_exclude(domain, queryset) return queryset current_month = datetime(*config['month']) previous_month = datetime(*config['prev_month']) del config['month'] del config['prev_month'] this_month_data = get_data_for(current_month, config) prev_month_data = get_data_for(previous_month, config) return { 'records': [ [ { 'label': _('AWCs Reported Clean Drinking Water'), 'help_text': awcs_reported_clean_drinking_water_help_text(), 'percent': percent_diff( 'clean_water', this_month_data, prev_month_data, 'sum_last_update' ), 'color': 'green' if percent_diff( 'clean_water', this_month_data, prev_month_data, 'sum_last_update' ) > 0 else 'red', 'value': get_value(this_month_data, 'clean_water'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/clean_water' }, { 'label': _("AWCs Reported Functional Toilet"), 'help_text': awcs_reported_functional_toilet_help_text(), 'percent': percent_diff( 'functional_toilet', this_month_data, prev_month_data, 'sum_last_update' ), 'color': 'green' if percent_diff( 'functional_toilet', this_month_data, prev_month_data, 'sum_last_update' ) > 0 else 'red', 'value': get_value(this_month_data, 'functional_toilet'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/functional_toilet' } ], [ # { # 'label': _('AWCs with Electricity'), # 'help_text': _('Percentage of AWCs with access to electricity'), # 'percent': 0, # 'value': 0, # 'all': 0, # 'format': 'percent_and_div', # 'frequency': 'month' # }, { 'label': _('AWCs Reported Weighing Scale: Infants'), 'help_text': awcs_reported_weighing_scale_infants_help_text(), 'percent': percent_diff( 'infant_scale', this_month_data, prev_month_data, 'sum_last_update' ), 'color': 'green' if percent_diff( 'infant_scale', this_month_data, prev_month_data, 'sum_last_update' ) > 0 else 'red', 'value': get_value(this_month_data, 'infant_scale'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/infants_weight_scale' }, { 'label': _('AWCs Reported Weighing Scale: Mother and Child'), 'help_text': awcs_reported_weighing_scale_mother_and_child_help_text(), 'percent': percent_diff( 'adult_scale', this_month_data, prev_month_data, 'sum_last_update' ), 'color': 'green' if percent_diff( 'adult_scale', this_month_data, prev_month_data, 'sum_last_update' ) > 0 else 'red', 'value': get_value(this_month_data, 'adult_scale'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/adult_weight_scale' } ], [ { 'label': _('AWCs Reported Medicine Kit'), 'help_text': awcs_reported_medicine_kit_help_text(), 'percent': percent_diff( 'medicine_kits', this_month_data, prev_month_data, 'sum_last_update' ), 'color': 'green' if percent_diff( 'medicine_kits', this_month_data, prev_month_data, 'sum_last_update' ) > 0 else 'red', 'value': get_value(this_month_data, 'medicine_kits'), 'all': get_value(this_month_data, 'sum_last_update'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'awc_infrastructure/medicine_kit' } ], # [ # { # 'label': _('AWCs with infantometer'), # 'help_text': _('Percentage of AWCs with an Infantometer'), # 'percent': 0, # 'value': 0, # 'all': 0, # 'format': 'percent_and_div', # 'frequency': 'month' # }, # { # 'label': _('AWCs with Stadiometer'), # 'help_text': _('Percentage of AWCs with a Stadiometer'), # 'percent': 0, # 'value': 0, # 'all': 0, # 'format': 'percent_and_div', # 'frequency': 'month' # } # ] ] }