def test_calculate_average(self): data_mock = [{ 'all': 9, 'children': 9, 'state_name': 'State 1', 'state_map_location_name': 'test1' }, { 'all': 0, 'children': 0, 'state_name': 'State 2', 'state_map_location_name': 'test2' }, { 'all': 0, 'children': 0, 'state_name': 'State 3', 'state_map_location_name': 'test3' }, { 'all': 0, 'children': 0, 'state_name': 'State 4', 'state_map_location_name': 'test4' }, { 'all': 6, 'children': 0, 'state_name': 'State 5', 'state_map_location_name': 'test5' }] data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( data_mock, 'state', 'children', 'all', 20, 60) self.assertEquals(average, 60.0)
def get_awc_daily_status_data_map(domain, config, loc_level, show_test=False): date = datetime(*config['month']) config['date'] = date del config['month'] def get_data_for(filters): queryset = AggAwcDailyView.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( in_day=Sum('daily_attendance_open'), all=Sum('num_launched_awcs'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data = get_data_for(config) if not data: config['date'] = (date - relativedelta(days=1)).date() data = get_data_for(config) data_for_map, valid_total, in_day_total, average, total = generate_data_for_map( data, loc_level, 'in_day', 'all', 50, 75) fills = OrderedDict() fills.update({'0%-50%': MapColors.RED}) fills.update({'50%-75%': MapColors.ORANGE}) fills.update({'75%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "awc_daily_statuses", "label": "Percent AWCs Open Yesterday", "fills": fills, "rightLegend": { "average": average, "info": _(("Of the total number of AWCs, the percentage of AWCs that were open yesterday." )), 'period': 'Daily', "extended_info": [{ 'indicator': 'Total number of AWCs that were open yesterday:', 'value': indian_formatted_number(in_day_total) }, { 'indicator': 'Total number of AWCs that have been launched:', 'value': indian_formatted_number(valid_total) }, { 'indicator': '% of AWCs open yesterday:', 'value': '%.2f%%' % (in_day_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }
def get_exclusive_breastfeeding_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( children=Sum('ebf_in_month'), all=Sum('ebf_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels( config) return { "slug": "severe", "label": "Percent Exclusive Breastfeeding{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": exclusive_breastfeeding_help_text(html=True), "extended_info": [{ 'indicator': 'Total number of children between ages 0 - 6 months{}:'.format( chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ('Total number of children (0-6 months) exclusively breastfed in the given month{}:' .format(chosen_filters)), 'value': indian_formatted_number(in_month_total) }, { 'indicator': '% children (0-6 months) exclusively breastfed in the ' 'given month{}:'.format(chosen_filters), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }
def get_clean_water_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggAwcMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( in_month=Sum('infra_clean_water'), all=Sum('num_awc_infra_last_update'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'in_month', 'all', 25, 75 ) fills = OrderedDict() fills.update({'0%-25%': MapColors.RED}) fills.update({'25%-75%': MapColors.ORANGE}) fills.update({'75%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "clean_water", "label": "Percentage of AWCs that reported having a source of clean drinking water", "fills": fills, "rightLegend": { "average": average, "info": _(( "Of the AWCs that have submitted an Infrastructure Details form, the percentage of AWCs that " "reported having a source of clean drinking water. " )), "extended_info": [ { 'indicator': ( 'Total number of AWCs with a source of clean drinking water:' ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% of AWCs with a source of clean drinking water:' ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_clean_water_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggAwcMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( in_month=Sum('infra_clean_water'), all=Sum('num_awc_infra_last_update'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'in_month', 'all', 25, 75 ) fills = OrderedDict() fills.update({'0%-25%': MapColors.RED}) fills.update({'25%-75%': MapColors.ORANGE}) fills.update({'75%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "clean_water", "label": "Percentage of AWCs that reported having a source of clean drinking water", "fills": fills, "rightLegend": { "average": average, "info": _(( "Of the AWCs that have submitted an Infrastructure Details form, the percentage of AWCs that " "reported having a source of clean drinking water. " )), "extended_info": [ { 'indicator': ( 'Total number of AWCs with a source of clean drinking water:' ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% of AWCs with a source of clean drinking water:' ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_institutional_deliveries_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggCcsRecordMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( children=Sum('institutional_delivery_in_month'), all=Sum('delivered_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "institutional_deliveries", "label": "Percent Instituitional Deliveries", "fills": fills, "rightLegend": { "average": average, "info": _(("Of the total number of women enrolled for Anganwadi services who gave birth in the last month, " "the percentage who delivered in a public or private medical facility. " "<br/><br/>" "Delivery in medical instituitions is associated with a decrease in maternal mortality rate" )), "extended_info": [{ 'indicator': 'Total number of pregnant women who delivered in the last month:', 'value': indian_formatted_number(valid_total) }, { 'indicator': ('Total number of pregnant women who delivered in a ' 'public/private medical facilitiy in the last month:'), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ('% pregnant women who delivered in a public or private medical ' 'facility in the last month:'), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }
def get_adult_weight_scale_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggAwcMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( in_month=Sum('infra_adult_weighing_scale'), all=Sum('num_awc_infra_last_update'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'in_month', 'all', 25, 75 ) fills = OrderedDict() fills.update({'0%-25%': MapColors.RED}) fills.update({'25%-75%': MapColors.ORANGE}) fills.update({'75%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "adult_weight_scale", "label": "Percentage of AWCs that reported having a weighing scale for mother and child", "fills": fills, "rightLegend": { "average": average, "info": awcs_reported_weighing_scale_mother_and_child_help_text(), "extended_info": [ { 'indicator': ( 'Total number of AWCs with a weighing scale for mother and child:' ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% of AWCs with a weighing scale for mother and child:' ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def test_calculate_average_if_divide_by_zero(self): data_mock = [{ 'all': 0, 'children': 0, 'state_name': 'State 1', 'state_map_location_name': 'test1' }] data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( data_mock, 'state', 'children', 'all', 20, 60) self.assertEquals(average, 0.0)
def test_calculate_average_if_data_are_none(self): data_mock = [{ 'all': None, 'children': None, 'state_name': None, 'state_map_location_name': None }] data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( data_mock, 'state', 'children', 'all', 20, 60) self.assertEquals(average, 0.0)
def get_adhaar_data_map(domain, config, loc_level, show_test=False, beta=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggAwcMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( in_month=Sum(person_has_aadhaar_column(beta)), all=Sum(person_is_beneficiary_column(beta)), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'in_month', 'all', 25, 50 ) fills = OrderedDict() fills.update({'0%-25%': MapColors.RED}) fills.update({'25%-50%': MapColors.ORANGE}) fills.update({'50%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "adhaar", "label": "Percent Aadhaar-seeded Beneficiaries", "fills": fills, "rightLegend": { "average": average, "info": percent_aadhaar_seeded_beneficiaries_help_text(), "extended_info": [ { 'indicator': ( 'Total number of ICDS beneficiaries whose Aadhaar has been captured:' ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% of ICDS beneficiaries whose Aadhaar has been captured:' ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_adhaar_data_map(domain, config, loc_level, show_test=False, beta=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggAwcMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( in_month=Sum(person_has_aadhaar_column(beta)), all=Sum(person_is_beneficiary_column(beta)), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'in_month', 'all', 25, 50 ) fills = OrderedDict() fills.update({'0%-25%': MapColors.RED}) fills.update({'25%-50%': MapColors.ORANGE}) fills.update({'50%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "adhaar", "label": "Percent Aadhaar-seeded Beneficiaries", "fills": fills, "rightLegend": { "average": average, "info": percent_aadhaar_seeded_beneficiaries_help_text(), "extended_info": [ { 'indicator': ( 'Total number of ICDS beneficiaries whose Aadhaar has been captured:' ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% of ICDS beneficiaries whose Aadhaar has been captured:' ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def test_calculate_average_if_divide_by_zero(self): data_mock = [{'all': 0, 'children': 0, 'state_name': 'State 1', 'state_map_location_name': 'test1'}] data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( data_mock, 'state', 'children', 'all', 20, 60 ) self.assertEquals(average, 0.0)
def test_calculate_average_if_data_are_none(self): data_mock = [{'all': None, 'children': None, 'state_name': None, 'state_map_location_name': None}] data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( data_mock, 'state', 'children', 'all', 20, 60 ) self.assertEquals(average, 0.0)
def test_calculate_average(self): data_mock = [{'all': 9, 'children': 9, 'state_name': 'State 1', 'state_map_location_name': 'test1'}, {'all': 0, 'children': 0, 'state_name': 'State 2', 'state_map_location_name': 'test2'}, {'all': 0, 'children': 0, 'state_name': 'State 3', 'state_map_location_name': 'test3'}, {'all': 0, 'children': 0, 'state_name': 'State 4', 'state_map_location_name': 'test4'}, {'all': 6, 'children': 0, 'state_name': 'State 5', 'state_map_location_name': 'test5'}] data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( data_mock, 'state', 'children', 'all', 20, 60 ) self.assertEquals(average, 60.0)
def get_institutional_deliveries_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggCcsRecordMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( children=Sum('institutional_delivery_in_month'), all=Sum('delivered_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60 ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "institutional_deliveries", "label": "Percent Instituitional Deliveries", "fills": fills, "rightLegend": { "average": average, "info": institutional_deliveries_help_text(html=True), "extended_info": [ { 'indicator': 'Total number of pregnant women who delivered in the last month:', 'value': indian_formatted_number(valid_total) }, { 'indicator': ( 'Total number of pregnant women who delivered in a ' 'public/private medical facilitiy in the last month:' ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% pregnant women who delivered in a public or private medical ' 'facility in the last month:' ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_newborn_with_low_birth_weight_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( low_birth=Sum('low_birth_weight_in_month'), in_month=Sum('weighed_and_born_in_month'), all=Sum('born_in_month') ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, in_month_total, low_birth_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'low_birth', 'in_month', 20, 60, 'all' ) fills = OrderedDict() fills.update({'0%-20%': MapColors.PINK}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.RED}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "low_birth", "label": "Percent Newborns with Low Birth Weight{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _(( new_born_with_low_weight_help_text(html=True) )), "extended_info": [ { 'indicator': 'Total Number of Newborns born in given month{}:'.format(chosen_filters), 'value': indian_formatted_number(total) }, { 'indicator': 'Number of Newborns with LBW in given month{}:'.format(chosen_filters), 'value': indian_formatted_number(low_birth_total) }, { 'indicator': 'Total Number of children born and weight in given month{}:'.format( chosen_filters ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': '% newborns with LBW in given month{}:'.format(chosen_filters), 'value': '%.2f%%' % (low_birth_total * 100 / float(in_month_total or 1)) }, { 'indicator': '% of children with weight in normal{}:'.format(chosen_filters), 'value': '%.2f%%' % ((in_month_total - low_birth_total) * 100 / float(in_month_total or 1)) }, { 'indicator': '% Unweighted{}:'.format(chosen_filters), 'value': '%.2f%%' % ((total - in_month_total) * 100 / float(total or 1)) } ] }, "data": dict(data_for_map), }
def get_exclusive_breastfeeding_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( children=Sum('ebf_in_month'), all=Sum('ebf_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60 ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "severe", "label": "Percent Exclusive Breastfeeding{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": (in_month_total * 100) / (float(valid_total) or 1), "info": _(( "Percentage of infants 0-6 months of age who are fed exclusively with breast milk. " "<br/><br/>" "An infant is exclusively breastfed if they recieve only breastmilk with no additional food, " "liquids (even water) ensuring optimal nutrition and growth between 0 - 6 months" )), "extended_info": [ { 'indicator': 'Total number of children between ages 0 - 6 months{}:' .format(chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ( 'Total number of children (0-6 months) exclusively breastfed in the given month{}:' .format(chosen_filters) ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': '% children (0-6 months) exclusively breastfed in the ' 'given month{}:'.format(chosen_filters), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_early_initiation_breastfeeding_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( birth=Sum('bf_at_birth'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, in_month_total, birth_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'birth', 'in_month', 20, 60 ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "early_initiation", "label": "Percent Early Initiation of Breastfeeding{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _(( "Percentage of children who were put to the breast within one hour of birth." "<br/><br/>" "Early initiation of breastfeeding ensure the newborn recieves the 'first milk' rich in " "nutrients and encourages exclusive breastfeeding practice" )), "extended_info": [ { 'indicator': 'Total Number of Children born in the given month{}:'.format(chosen_filters), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( 'Total Number of Children who were put to the breast within one hour of birth{}:' .format(chosen_filters) ), 'value': indian_formatted_number(birth_total) }, { 'indicator': '% children who were put to the breast within one hour of ' 'birth{}:'.format(chosen_filters), 'value': '%.2f%%' % (birth_total * 100 / float(in_month_total or 1)) } ] }, "data": dict(data_for_map), }
def get_immunization_coverage_data_map(domain, config, loc_level, show_test=False, icds_features_flag=False): config['month'] = datetime(*config['month']) def get_data_for(filters): queryset = AggChildHealthMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( children=Sum('fully_immunized_on_time') + Sum('fully_immunized_late'), all=Sum('fully_immunized_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset if icds_features_flag: location_launched_status = get_location_launched_status( config, loc_level) else: location_launched_status = None data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60, location_launched_status=location_launched_status) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels( config) return { "slug": "institutional_deliveries", "label": "Percent Immunization Coverage at 1 year{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _(("Of the total number of children enrolled for Anganwadi Services who are over a year old, " "the percentage of children who have received the complete immunization as per the National " "Immunization Schedule of India that is required by age 1." "<br/><br/>" "This includes the following immunizations:<br/>" "If Pentavalent path: Penta1/2/3, OPV1/2/3, BCG, Measles, VitA1<br/>" "If DPT/HepB path: DPT1/2/3, HepB1/2/3, OPV1/2/3, BCG, Measles, VitA1" )), "extended_info": [{ 'indicator': 'Total number of ICDS Child beneficiaries older than ' '1 year{}:'.format(chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ('Total number of children who have recieved complete immunizations required ' 'by age 1{}:'.format(chosen_filters)), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ('% of children who have recieved complete immunizations required by age 1{}:' .format(chosen_filters)), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }
def get_newborn_with_low_birth_weight_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate(low_birth=Sum('low_birth_weight_in_month'), in_month=Sum('weighed_and_born_in_month'), all=Sum('born_in_month')).order_by( '%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, in_month_total, low_birth_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'low_birth', 'in_month', 20, 60, 'all') fills = OrderedDict() fills.update({'0%-20%': MapColors.PINK}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.RED}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels( config) return { "slug": "low_birth", "label": "Percent Newborns with Low Birth Weight{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _((new_born_with_low_weight_help_text(html=True))), "extended_info": [{ 'indicator': 'Total Number of Newborns born in given month{}:'.format( chosen_filters), 'value': indian_formatted_number(total) }, { 'indicator': 'Number of Newborns with LBW in given month{}:'.format( chosen_filters), 'value': indian_formatted_number(low_birth_total) }, { 'indicator': 'Total Number of children born and weight in given month{}:'. format(chosen_filters), 'value': indian_formatted_number(in_month_total) }, { 'indicator': '% newborns with LBW in given month{}:'.format(chosen_filters), 'value': '%.2f%%' % (low_birth_total * 100 / float(in_month_total or 1)) }, { 'indicator': '% of children with weight in normal{}:'.format( chosen_filters), 'value': '%.2f%%' % ((in_month_total - low_birth_total) * 100 / float(in_month_total or 1)) }, { 'indicator': '% Unweighted{}:'.format(chosen_filters), 'value': '%.2f%%' % ((total - in_month_total) * 100 / float(total or 1)) }] }, "data": dict(data_for_map), }
def get_institutional_deliveries_data_map(domain, config, loc_level, show_test=False, icds_features_flag=False): config['month'] = datetime(*config['month']) def get_data_for(filters): queryset = AggCcsRecordMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( children=Sum('institutional_delivery_in_month'), all=Sum('delivered_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset if icds_features_flag: location_launched_status = get_location_launched_status( config, loc_level) else: location_launched_status = None data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60, location_launched_status=location_launched_status) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "institutional_deliveries", "label": "Percent Instituitional Deliveries", "fills": fills, "rightLegend": { "average": average, "info": institutional_deliveries_help_text(html=True), "extended_info": [{ 'indicator': 'Total number of pregnant women who delivered in the current month:', 'value': indian_formatted_number(valid_total) }, { 'indicator': ('Total number of pregnant women who delivered in a ' 'public/private medical facilitiy in the current month:'), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ('% pregnant women who delivered in a public or private medical ' 'facility in the current month:'), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }
def get_early_initiation_breastfeeding_map(domain, config, loc_level, show_test=False, icds_features_flag=False): config['month'] = datetime(*config['month']) def get_data_for(filters): queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( birth=Sum('bf_at_birth'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset if icds_features_flag: location_launched_status = get_location_launched_status(config, loc_level) else: location_launched_status = None data_for_map, in_month_total, birth_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'birth', 'in_month', 20, 60, location_launched_status=location_launched_status ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) if icds_features_flag: fills.update({'Not Launched': MapColors.GREY}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "early_initiation", "label": "Percent Early Initiation of Breastfeeding{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": early_initiation_breastfeeding_help_text(html=True), "extended_info": [ { 'indicator': 'Total Number of Children born in the current month{}:'.format(chosen_filters), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( 'Total Number of Children who were put to the breast within one hour of birth{}:' .format(chosen_filters) ), 'value': indian_formatted_number(birth_total) }, { 'indicator': '% children who were put to the breast within one hour of ' 'birth{}:'.format(chosen_filters), 'value': '%.2f%%' % (birth_total * 100 / float(in_month_total or 1)) } ] }, "data": dict(data_for_map), }
def get_children_initiated_data_map(domain, config, loc_level, show_test=False, icds_features_flag=False): config['month'] = datetime(*config['month']) def get_data_for(filters): queryset = AggChildHealthMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( children=Sum('cf_initiation_in_month'), all=Sum('cf_initiation_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset if icds_features_flag: location_launched_status = get_location_launched_status( config, loc_level) else: location_launched_status = None data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60, location_launched_status=location_launched_status) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels( config) return { "slug": "severe", "label": "Percent Children (6-8 months) initiated Complementary Feeding{}". format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": children_initiated_appropriate_complementary_feeding_help_text( html=True), "extended_info": [{ 'indicator': 'Total number of children between age 6 - 8 months{}:'.format( chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ('Total number of children (6-8 months) given timely introduction to sold or ' 'semi-solid food in the given month{}:'.format(chosen_filters) ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ('% children (6-8 months) given timely introduction to solid or ' 'semi-solid food in the given month{}:'.format(chosen_filters) ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }
def get_newborn_with_low_birth_weight_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( low_birth=Sum('low_birth_weight_in_month'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, in_month_total, low_birth_total, average = generate_data_for_map( get_data_for(config), loc_level, 'low_birth', 'in_month', 20, 60) fills = OrderedDict() fills.update({'0%-20%': MapColors.PINK}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.RED}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels( config) return { "slug": "low_birth", "label": "Percent Newborns with Low Birth Weight{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _(("Percentage of newborns with born with birth weight less than 2500 grams." "<br/><br/>" "Newborns with Low Birth Weight are closely associated with foetal and neonatal " "mortality and morbidity, inhibited growth and cognitive development, and chronic " "diseases later in life")), "extended_info": [{ 'indicator': 'Total Number of Newborns born in given month{}:'.format( chosen_filters), 'value': indian_formatted_number(in_month_total) }, { 'indicator': 'Number of Newborns with LBW in given month{}:'.format( chosen_filters), 'value': indian_formatted_number(low_birth_total) }, { 'indicator': '% newborns with LBW in given month{}:'.format(chosen_filters), 'value': '%.2f%%' % (low_birth_total * 100 / float(in_month_total or 1)) }, { 'indicator': '% Unweighed{}:'.format(chosen_filters), 'value': '%.2f%%' % ((in_month_total - low_birth_total) * 100 / float(in_month_total or 1)) }] }, "data": dict(data_for_map), }
def get_immunization_coverage_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( children=Sum('fully_immunized_on_time') + Sum('fully_immunized_late'), all=Sum('fully_immunized_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60 ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "institutional_deliveries", "label": "Percent Immunization Coverage at 1 year{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _(( "Of the total number of children enrolled for Anganwadi Services who are over a year old, " "the percentage of children who have received the complete immunization as per the National " "Immunization Schedule of India that is required by age 1." "<br/><br/>" "This includes the following immunizations:<br/>" "If Pentavalent path: Penta1/2/3, OPV1/2/3, BCG, Measles, VitA1<br/>" "If DPT/HepB path: DPT1/2/3, HepB1/2/3, OPV1/2/3, BCG, Measles, VitA1" )), "extended_info": [ { 'indicator': 'Total number of ICDS Child beneficiaries older than ' '1 year{}:'.format(chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ( 'Total number of children who have recieved complete immunizations required ' 'by age 1{}:'.format(chosen_filters) ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% of children who have recieved complete immunizations required by age 1{}:' .format(chosen_filters) ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_children_initiated_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( children=Sum('cf_initiation_in_month'), all=Sum('cf_initiation_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60 ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "severe", "label": "Percent Children (6-8 months) initiated Complementary Feeding{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": children_initiated_appropriate_complementary_feeding_help_text(html=True), "extended_info": [ { 'indicator': 'Total number of children between age 6 - 8 months{}:'.format(chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ( 'Total number of children (6-8 months) given timely introduction to sold or ' 'semi-solid food in the given month{}:'.format(chosen_filters) ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( '% children (6-8 months) given timely introduction to solid or ' 'semi-solid food in the given month{}:'.format(chosen_filters) ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_early_initiation_breastfeeding_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( birth=Sum('bf_at_birth'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, in_month_total, birth_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'birth', 'in_month', 20, 60 ) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels(config) return { "slug": "early_initiation", "label": "Percent Early Initiation of Breastfeeding{}".format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": early_initiation_breastfeeding_help_text(html=True), "extended_info": [ { 'indicator': 'Total Number of Children born in the given month{}:'.format(chosen_filters), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ( 'Total Number of Children who were put to the breast within one hour of birth{}:' .format(chosen_filters) ), 'value': indian_formatted_number(birth_total) }, { 'indicator': '% children who were put to the breast within one hour of ' 'birth{}:'.format(chosen_filters), 'value': '%.2f%%' % (birth_total * 100 / float(in_month_total or 1)) } ] }, "data": dict(data_for_map), }
def get_awc_daily_status_data_map(domain, config, loc_level, show_test=False): date = datetime(*config['month']) del config['month'] def get_data_for(filters): queryset = AggAwcDailyView.objects.filter( **filters ).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level ).annotate( in_day=Sum('daily_attendance_open'), all=Sum('num_launched_awcs'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset config['date'] = date.date() data = None while data is None or (not data and config['date'].day != 1): data = get_data_for(config) config['date'] -= relativedelta(days=1) data_for_map, valid_total, in_day_total, average, total = generate_data_for_map( data, loc_level, 'in_day', 'all', 50, 75 ) fills = OrderedDict() fills.update({'0%-50%': MapColors.RED}) fills.update({'50%-75%': MapColors.ORANGE}) fills.update({'75%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) return { "slug": "awc_daily_statuses", "label": "Percent AWCs Open Yesterday", "fills": fills, "rightLegend": { "average": average, "info": _(( "Of the total number of AWCs, the percentage of AWCs that were open yesterday." )), 'period': 'Daily', "extended_info": [ { 'indicator': 'Total number of AWCs that were open yesterday:', 'value': indian_formatted_number(in_day_total) }, { 'indicator': 'Total number of AWCs that have been launched:', 'value': indian_formatted_number(valid_total) }, { 'indicator': '% of AWCs open yesterday:', 'value': '%.2f%%' % (in_day_total * 100 / float(valid_total or 1)) } ] }, "data": dict(data_for_map), }
def get_children_initiated_data_map(domain, config, loc_level, show_test=False): def get_data_for(filters): filters['month'] = datetime(*filters['month']) queryset = AggChildHealthMonthly.objects.filter(**filters).values( '%s_name' % loc_level, '%s_map_location_name' % loc_level).annotate( children=Sum('cf_initiation_in_month'), all=Sum('cf_initiation_eligible'), ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset data_for_map, valid_total, in_month_total, average, total = generate_data_for_map( get_data_for(config), loc_level, 'children', 'all', 20, 60) fills = OrderedDict() fills.update({'0%-20%': MapColors.RED}) fills.update({'20%-60%': MapColors.ORANGE}) fills.update({'60%-100%': MapColors.PINK}) fills.update({'defaultFill': MapColors.GREY}) gender_ignored, age_ignored, chosen_filters = chosen_filters_to_labels( config) return { "slug": "severe", "label": "Percent Children (6-8 months) initiated Complementary Feeding{}". format(chosen_filters), "fills": fills, "rightLegend": { "average": average, "info": _(("Of the total children enrolled for Anganwadi services between the ages of 6 to 8 months, " "the percentage that was given a timely introduction to solid, semi-solid or soft food." "<br/><br/>" "Timely intiation of complementary feeding in addition to breastmilk at 6 months of age " "is a key feeding practice to reduce malnutrition")), "extended_info": [{ 'indicator': 'Total number of children between age 6 - 8 months{}:'.format( chosen_filters), 'value': indian_formatted_number(valid_total) }, { 'indicator': ('Total number of children (6-8 months) given timely introduction to sold or ' 'semi-solid food in the given month{}:'.format(chosen_filters) ), 'value': indian_formatted_number(in_month_total) }, { 'indicator': ('% children (6-8 months) given timely introduction to solid or ' 'semi-solid food in the given month{}:'.format(chosen_filters) ), 'value': '%.2f%%' % (in_month_total * 100 / float(valid_total or 1)) }] }, "data": dict(data_for_map), }