def get_newborn_with_low_birth_weight_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).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) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'low_birth': 0, 'all': 0 }) for row in data: in_month = row['in_month'] or 0 name = row['%s_name' % loc_level] all_records = row['all'] or 0 low_birth = row['low_birth'] or 0 value = low_birth / float(in_month or 1) tooltips_data[name]['low_birth'] += low_birth tooltips_data[name]['in_month'] += in_month tooltips_data[name]['all'] += all_records chart_data['blue'].append([name, value]) chart_data['blue'] = sorted(chart_data['blue']) return { "tooltips_data": dict(tooltips_data), "info": _((new_born_with_low_weight_help_text(html=True))), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def test_map_data_right_legend_info(self): data = get_newborn_with_low_birth_weight_map('icds-cas', config={ 'month': (2017, 5, 1), 'aggregation_level': 1 }, loc_level='state') expected = (new_born_with_low_weight_help_text(html=True)) self.assertEquals(data['rightLegend']['info'], expected)
def test_map_data_right_legend_info(self): data = get_newborn_with_low_birth_weight_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'aggregation_level': 1 }, loc_level='state' ) expected = ( new_born_with_low_weight_help_text(html=True) ) self.assertEquals(data['rightLegend']['info'], expected)
def test_sector_data_info(self): data = get_newborn_with_low_birth_weight_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') self.assertEquals(data['info'], new_born_with_low_weight_help_text(html=True))
def test_sector_data_info(self): data = get_newborn_with_low_birth_weight_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' ) self.assertEquals( data['info'], new_born_with_low_weight_help_text(html=True) )
def test_data_newborns_with_low_birth_weight(self): self.assertDictEqual( get_maternal_child_data( 'icds-cas', { 'month': (2017, 5, 1), 'prev_month': (2017, 4, 1), 'aggregation_level': 1 })['records'][1][1], { "redirect": "maternal_and_child/low_birth", "color": "red", "all": 4, "frequency": "month", "format": "percent_and_div", "help_text": new_born_with_low_weight_help_text(html=False), "percent": "Data in the previous reporting period was 0", "value": 2, "label": "Newborns with Low Birth Weight" })
def test_data_newborns_with_low_birth_weight(self): self.assertDictEqual( get_maternal_child_data( 'icds-cas', { 'month': (2017, 5, 1), 'prev_month': (2017, 4, 1), 'aggregation_level': 1 } )['records'][1][1], { "redirect": "maternal_and_child/low_birth", "color": "red", "all": 3, "frequency": "month", "format": "percent_and_div", "help_text": new_born_with_low_weight_help_text(html=False), "percent": "Data in the previous reporting period was 0", "value": 1, "label": "Newborns with Low Birth Weight" } )
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_maternal_child_data(domain, config, show_test=False, icds_feature_flag=False): def get_data_for_child_health_monthly(date, filters): age_filters = { 'age_tranche': 72 } if icds_feature_flag else { 'age_tranche__in': [0, 6, 72] } moderately_underweight = exclude_records_by_age_for_column( {'age_tranche': 72}, 'nutrition_status_moderately_underweight') severely_underweight = exclude_records_by_age_for_column( {'age_tranche': 72}, 'nutrition_status_severely_underweight') wasting_moderate = exclude_records_by_age_for_column( age_filters, wasting_moderate_column(icds_feature_flag)) wasting_severe = exclude_records_by_age_for_column( age_filters, wasting_severe_column(icds_feature_flag)) stunting_moderate = exclude_records_by_age_for_column( age_filters, stunting_moderate_column(icds_feature_flag)) stunting_severe = exclude_records_by_age_for_column( age_filters, stunting_severe_column(icds_feature_flag)) nutrition_status_weighed = exclude_records_by_age_for_column( {'age_tranche': 72}, 'nutrition_status_weighed') height_measured_in_month = exclude_records_by_age_for_column( age_filters, hfa_recorded_in_month_column(icds_feature_flag)) weighed_and_height_measured_in_month = exclude_records_by_age_for_column( age_filters, wfh_recorded_in_month_column(icds_feature_flag)) queryset = AggChildHealthMonthly.objects.filter( month=date, **filters).values('aggregation_level').annotate( underweight=(Sum(moderately_underweight) + Sum(severely_underweight)), valid=Sum(nutrition_status_weighed), wasting=Sum(wasting_moderate) + Sum(wasting_severe), stunting=Sum(stunting_moderate) + Sum(stunting_severe), height_measured_in_month=Sum(height_measured_in_month), weighed_and_height_measured_in_month=Sum( weighed_and_height_measured_in_month), low_birth_weight=Sum('low_birth_weight_in_month'), bf_birth=Sum('bf_at_birth'), born=Sum('born_in_month'), weighed_and_born_in_month=Sum('weighed_and_born_in_month'), ebf=Sum('ebf_in_month'), ebf_eli=Sum('ebf_eligible'), cf_initiation=Sum('cf_initiation_in_month'), cf_initiation_eli=Sum('cf_initiation_eligible')) if not show_test: queryset = apply_exclude(domain, queryset) return queryset def get_data_for_deliveries(date, filters): queryset = AggCcsRecordMonthly.objects.filter( month=date, **filters).values('aggregation_level').annotate( institutional_delivery=Sum('institutional_delivery_in_month'), delivered=Sum('delivered_in_month')) 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_child_health_monthly(current_month, config) prev_month_data = get_data_for_child_health_monthly(previous_month, config) deliveries_this_month = get_data_for_deliveries(current_month, config) deliveries_prev_month = get_data_for_deliveries(previous_month, config) gender_label, age_label, chosen_filters = chosen_filters_to_labels( config, default_interval=default_age_interval(icds_feature_flag)) return { 'records': [[{ 'label': _('Underweight (Weight-for-Age)'), 'help_text': underweight_children_help_text(), 'percent': percent_diff('underweight', this_month_data, prev_month_data, 'valid'), 'color': 'red' if percent_diff('underweight', this_month_data, prev_month_data, 'valid') > 0 else 'green', 'value': get_value(this_month_data, 'underweight'), 'all': get_value(this_month_data, 'valid'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/underweight_children' }, { 'label': _('Wasting (Weight-for-Height)'), 'help_text': _(wasting_help_text(age_label)), 'percent': percent_diff('wasting', this_month_data, prev_month_data, 'weighed_and_height_measured_in_month'), 'color': 'red' if percent_diff('wasting', this_month_data, prev_month_data, 'weighed_and_height_measured_in_month') > 0 else 'green', 'value': get_value(this_month_data, 'wasting'), 'all': get_value(this_month_data, 'weighed_and_height_measured_in_month'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/wasting' }], [{ 'label': _('Stunting (Height-for-Age)'), 'help_text': _(stunting_help_text(age_label)), 'percent': percent_diff('stunting', this_month_data, prev_month_data, 'height_measured_in_month'), 'color': 'red' if percent_diff('stunting', this_month_data, prev_month_data, 'height_measured_in_month') > 0 else 'green', 'value': get_value(this_month_data, 'stunting'), 'all': get_value(this_month_data, 'height_measured_in_month'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/stunting' }, { 'label': _('Newborns with Low Birth Weight'), 'help_text': _((new_born_with_low_weight_help_text(html=False))), 'percent': percent_diff('low_birth_weight', this_month_data, prev_month_data, 'weighed_and_born_in_month'), 'color': get_color_with_red_positive( percent_diff('low_birth_weight', this_month_data, prev_month_data, 'weighed_and_born_in_month')), 'value': get_value(this_month_data, 'low_birth_weight'), 'all': get_value(this_month_data, 'weighed_and_born_in_month'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/low_birth' }], [{ 'label': _('Early Initiation of Breastfeeding'), 'help_text': early_initiation_breastfeeding_help_text(), 'percent': percent_diff('bf_birth', this_month_data, prev_month_data, 'born'), 'color': get_color_with_green_positive( percent_diff('bf_birth', this_month_data, prev_month_data, 'born')), 'value': get_value(this_month_data, 'bf_birth'), 'all': get_value(this_month_data, 'born'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/early_initiation' }, { 'label': _('Exclusive Breastfeeding'), 'help_text': exclusive_breastfeeding_help_text(), 'percent': percent_diff('ebf', this_month_data, prev_month_data, 'ebf_eli'), 'color': get_color_with_green_positive( percent_diff('ebf', this_month_data, prev_month_data, 'ebf_eli')), 'value': get_value(this_month_data, 'ebf'), 'all': get_value(this_month_data, 'ebf_eli'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/exclusive_breastfeeding' }], [{ 'label': _('Children initiated appropriate Complementary Feeding'), 'help_text': children_initiated_appropriate_complementary_feeding_help_text(), 'percent': percent_diff('cf_initiation', this_month_data, prev_month_data, 'cf_initiation_eli'), 'color': get_color_with_green_positive( percent_diff('cf_initiation', this_month_data, prev_month_data, 'cf_initiation_eli')), 'value': get_value(this_month_data, 'cf_initiation'), 'all': get_value(this_month_data, 'cf_initiation_eli'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/children_initiated' }, { 'label': _('Institutional Deliveries'), 'help_text': institutional_deliveries_help_text(), 'percent': percent_diff('institutional_delivery', deliveries_this_month, deliveries_prev_month, 'delivered'), 'color': get_color_with_green_positive( percent_diff('institutional_delivery', deliveries_this_month, deliveries_prev_month, 'delivered')), 'value': get_value(deliveries_this_month, 'institutional_delivery'), 'all': get_value(deliveries_this_month, 'delivered'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/institutional_deliveries' }]] }
def get_maternal_child_data(domain, config, show_test=False, icds_feature_flag=False): def get_data_for_child_health_monthly(date, filters): age_filters = {'age_tranche': 72} if icds_feature_flag else {'age_tranche__in': [0, 6, 72]} moderately_underweight = exclude_records_by_age_for_column( {'age_tranche': 72}, 'nutrition_status_moderately_underweight' ) severely_underweight = exclude_records_by_age_for_column( {'age_tranche': 72}, 'nutrition_status_severely_underweight' ) wasting_moderate = exclude_records_by_age_for_column( age_filters, wasting_moderate_column(icds_feature_flag) ) wasting_severe = exclude_records_by_age_for_column( age_filters, wasting_severe_column(icds_feature_flag) ) stunting_moderate = exclude_records_by_age_for_column( age_filters, stunting_moderate_column(icds_feature_flag) ) stunting_severe = exclude_records_by_age_for_column( age_filters, stunting_severe_column(icds_feature_flag) ) nutrition_status_weighed = exclude_records_by_age_for_column( {'age_tranche': 72}, 'nutrition_status_weighed' ) height_measured_in_month = exclude_records_by_age_for_column( age_filters, hfa_recorded_in_month_column(icds_feature_flag) ) weighed_and_height_measured_in_month = exclude_records_by_age_for_column( age_filters, wfh_recorded_in_month_column(icds_feature_flag) ) queryset = AggChildHealthMonthly.objects.filter( month=date, **filters ).values( 'aggregation_level' ).annotate( underweight=( Sum(moderately_underweight) + Sum(severely_underweight) ), valid=Sum(nutrition_status_weighed), wasting=Sum(wasting_moderate) + Sum(wasting_severe), stunting=Sum(stunting_moderate) + Sum(stunting_severe), height_measured_in_month=Sum(height_measured_in_month), weighed_and_height_measured_in_month=Sum(weighed_and_height_measured_in_month), low_birth_weight=Sum('low_birth_weight_in_month'), bf_birth=Sum('bf_at_birth'), born=Sum('born_in_month'), weighed_and_born_in_month=Sum('weighed_and_born_in_month'), ebf=Sum('ebf_in_month'), ebf_eli=Sum('ebf_eligible'), cf_initiation=Sum('cf_initiation_in_month'), cf_initiation_eli=Sum('cf_initiation_eligible') ) if not show_test: queryset = apply_exclude(domain, queryset) return queryset def get_data_for_deliveries(date, filters): queryset = AggCcsRecordMonthly.objects.filter( month=date, **filters ).values( 'aggregation_level' ).annotate( institutional_delivery=Sum('institutional_delivery_in_month'), delivered=Sum('delivered_in_month') ) 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_child_health_monthly(current_month, config) prev_month_data = get_data_for_child_health_monthly(previous_month, config) deliveries_this_month = get_data_for_deliveries(current_month, config) deliveries_prev_month = get_data_for_deliveries(previous_month, config) gender_label, age_label, chosen_filters = chosen_filters_to_labels( config, default_interval=default_age_interval(icds_feature_flag) ) return { 'records': [ [ { 'label': _('Underweight (Weight-for-Age)'), 'help_text': underweight_children_help_text(), 'percent': percent_diff( 'underweight', this_month_data, prev_month_data, 'valid' ), 'color': 'red' if percent_diff( 'underweight', this_month_data, prev_month_data, 'valid' ) > 0 else 'green', 'value': get_value(this_month_data, 'underweight'), 'all': get_value(this_month_data, 'valid'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/underweight_children' }, { 'label': _('Wasting (Weight-for-Height)'), 'help_text': _(wasting_help_text(age_label)), 'percent': percent_diff( 'wasting', this_month_data, prev_month_data, 'weighed_and_height_measured_in_month' ), 'color': 'red' if percent_diff( 'wasting', this_month_data, prev_month_data, 'weighed_and_height_measured_in_month' ) > 0 else 'green', 'value': get_value(this_month_data, 'wasting'), 'all': get_value(this_month_data, 'weighed_and_height_measured_in_month'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/wasting' } ], [ { 'label': _('Stunting (Height-for-Age)'), 'help_text': _(stunting_help_text(age_label)), 'percent': percent_diff( 'stunting', this_month_data, prev_month_data, 'height_measured_in_month' ), 'color': 'red' if percent_diff( 'stunting', this_month_data, prev_month_data, 'height_measured_in_month' ) > 0 else 'green', 'value': get_value(this_month_data, 'stunting'), 'all': get_value(this_month_data, 'height_measured_in_month'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/stunting' }, { 'label': _('Newborns with Low Birth Weight'), 'help_text': _(( new_born_with_low_weight_help_text(html=False) )), 'percent': percent_diff( 'low_birth_weight', this_month_data, prev_month_data, 'weighed_and_born_in_month' ), 'color': 'red' if percent_diff( 'low_birth_weight', this_month_data, prev_month_data, 'weighed_and_born_in_month' ) > 0 else 'green', 'value': get_value(this_month_data, 'low_birth_weight'), 'all': get_value(this_month_data, 'weighed_and_born_in_month'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/low_birth' } ], [ { 'label': _('Early Initiation of Breastfeeding'), 'help_text': early_initiation_breastfeeding_help_text(), 'percent': percent_diff( 'bf_birth', this_month_data, prev_month_data, 'born' ), 'color': 'green' if percent_diff( 'bf_birth', this_month_data, prev_month_data, 'born' ) > 0 else 'red', 'value': get_value(this_month_data, 'bf_birth'), 'all': get_value(this_month_data, 'born'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/early_initiation' }, { 'label': _('Exclusive Breastfeeding'), 'help_text': exclusive_breastfeeding_help_text(), 'percent': percent_diff( 'ebf', this_month_data, prev_month_data, 'ebf_eli' ), 'color': 'green' if percent_diff( 'ebf', this_month_data, prev_month_data, 'ebf_eli' ) > 0 else 'red', 'value': get_value(this_month_data, 'ebf'), 'all': get_value(this_month_data, 'ebf_eli'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/exclusive_breastfeeding' } ], [ { 'label': _('Children initiated appropriate Complementary Feeding'), 'help_text': children_initiated_appropriate_complementary_feeding_help_text(), 'percent': percent_diff( 'cf_initiation', this_month_data, prev_month_data, 'cf_initiation_eli' ), 'color': 'green' if percent_diff( 'cf_initiation', this_month_data, prev_month_data, 'cf_initiation_eli' ) > 0 else 'red', 'value': get_value(this_month_data, 'cf_initiation'), 'all': get_value(this_month_data, 'cf_initiation_eli'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/children_initiated' }, { 'label': _('Institutional Deliveries'), 'help_text': institutional_deliveries_help_text(), 'percent': percent_diff( 'institutional_delivery', deliveries_this_month, deliveries_prev_month, 'delivered' ), 'color': 'green' if percent_diff( 'institutional_delivery', deliveries_this_month, deliveries_prev_month, 'delivered' ) > 0 else 'red', 'value': get_value(deliveries_this_month, 'institutional_delivery'), 'all': get_value(deliveries_this_month, 'delivered'), 'format': 'percent_and_div', 'frequency': 'month', 'redirect': 'maternal_and_child/institutional_deliveries' } ] ] }
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_newborn_with_low_birth_weight_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).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) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'low_birth': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] or 0 name = row['%s_name' % loc_level] result_set.add(name) all_records = row['all'] or 0 low_birth = row['low_birth'] or 0 value = low_birth / float(in_month or 1) tooltips_data[name]['low_birth'] += low_birth tooltips_data[name]['in_month'] += in_month tooltips_data[name]['all'] += all_records chart_data['blue'].append([ name, value ]) for sql_location in loc_children: if sql_location.name not in result_set: chart_data['blue'].append([sql_location.name, 0]) chart_data['blue'] = sorted(chart_data['blue']) return { "tooltips_data": dict(tooltips_data), "info": _(( new_born_with_low_weight_help_text(html=True) )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }