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),
    }
Exemple #3
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":
            _(("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),
    }
Exemple #4
0
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),
    }
Exemple #5
0
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),
    }
Exemple #6
0
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),
    }
Exemple #7
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),
    }
Exemple #8
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),
    }
Exemple #9
0
def get_registered_household_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(household=Sum('cases_household'), ).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 = defaultdict(lambda: {
        'household': 0,
        'original_name': [],
        'fillKey': 'Household'
    })
    average = []

    for row in get_data_for(config):
        household = row['household'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(household)
        data_for_map[on_map_name]['household'] += household
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Household': MapColors.BLUE})
    if beta:
        fills.update({'Not Launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    return {
        "slug": "registered_household",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average":
            sum(average) / float(len(average) or 1),
            "average_format":
            'number',
            "info":
            _("Total number of households registered: %s" %
              indian_formatted_number(sum(average)))
        },
        "data": dict(data_for_map),
    }
def get_registered_household_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(
            household=Sum('cases_household'),
        ).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 = defaultdict(lambda: {
        'household': 0,
        'original_name': [],
        'fillKey': 'Household'
    })
    average = []

    for row in get_data_for(config):
        household = row['household'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(household)
        data_for_map[on_map_name]['household'] += household
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Household': MapColors.BLUE})
    fills.update({'defaultFill': MapColors.GREY})

    return {
        "slug": "registered_household",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average": sum(average) / float(len(average) or 1),
            "average_format": 'number',
            "info": _("Total number of households registered: %s" % indian_formatted_number(sum(average)))
        },
        "data": dict(data_for_map),
    }
Exemple #11
0
def get_adolescent_girls_data_map(domain,
                                  config,
                                  loc_level,
                                  show_test=False,
                                  beta=False):

    valid_col_name = 'cases_person_adolescent_girls_11_14_out_of_school'
    all_col_name = 'cases_person_adolescent_girls_11_14_all_v2'
    valid_num_title = 'Number of adolescent girls (11-14 years) who are out of school:'
    all_num_title = 'Total Number of adolescent girls (11-14 years) who are registered:'
    percent_title = 'Percentage of adolescent girls (11-14 years) who are out of school:'
    info_text = percent_adolescent_girls_enrolled_help_text_v2()

    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(
                valid=Sum(valid_col_name),
                all=Sum(all_col_name),
            ).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 = defaultdict(
        lambda: {
            'valid': 0,
            'all': 0,
            'original_name': [],
            'fillKey': 'Out of school Adolescent Girls'
        })
    average = []
    total_valid = 0
    total = 0
    for row in get_data_for(config):
        valid = row['valid'] or 0
        all_adolescent = row['all'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(valid)

        total_valid += valid
        total += all_adolescent

        data_for_map[on_map_name]['valid'] += valid
        data_for_map[on_map_name]['all'] += all_adolescent
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Out of school Adolescent Girls': MapColors.BLUE})
    if beta:
        fills.update({'Not Launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    return {
        "slug": "adolescent_girls",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average":
            '%.2f' % (total_valid * 100 / float(total or 1)),
            "info":
            info_text,
            "extended_info": [{
                'indicator': valid_num_title,
                'value': indian_formatted_number(total_valid)
            }, {
                'indicator': all_num_title,
                'value': indian_formatted_number(total)
            }, {
                'indicator':
                percent_title,
                'value':
                '%.2f%%' % (total_valid * 100 / float(total or 1))
            }]
        },
        "data": dict(data_for_map),
    }
 def test_if_parameter_will_be_numeric_string(self):
     number = "10000000"
     india_format = indian_formatted_number(number)
     self.assertEqual(india_format, "1,00,00,000")
 def test_less_then_thousand(self):
     number = 900
     india_format = indian_formatted_number(number)
     self.assertEqual(india_format, "900")
Exemple #14
0
def get_prevalence_of_undernutrition_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(
                moderately_underweight=Sum(
                    'nutrition_status_moderately_underweight'),
                severely_underweight=Sum(
                    'nutrition_status_severely_underweight'),
                normal=Sum('nutrition_status_normal'),
                weighed=Sum('nutrition_status_weighed'),
                total=Sum('wer_eligible'),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.filter(age_tranche__lt=72)
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderately_underweight': 0,
            'severely_underweight': 0,
            'normal': 0,
            'weighed': 0,
            'total': 0,
            'original_name': []
        })

    moderately_underweight_total = 0
    severely_underweight_total = 0
    normal_total = 0
    all_total = 0
    weighed_total = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}

    location_launched_status = get_location_launched_status(config, loc_level)

    for row in get_data_for(config):
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        weighed = row['weighed'] or 0
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severely_underweight = row['severely_underweight'] or 0
        moderately_underweight = row['moderately_underweight'] or 0
        normal = row['normal'] or 0

        values_to_calculate_average[
            'numerator'] += moderately_underweight if moderately_underweight else 0
        values_to_calculate_average[
            'numerator'] += severely_underweight if severely_underweight else 0
        values_to_calculate_average['denominator'] += weighed if weighed else 0

        moderately_underweight_total += moderately_underweight
        severely_underweight_total += severely_underweight
        normal_total += normal
        all_total += total
        weighed_total += weighed

        data_for_map[on_map_name][
            'severely_underweight'] += severely_underweight
        data_for_map[on_map_name][
            'moderately_underweight'] += moderately_underweight
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['weighed'] += weighed
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in data_for_map.values():
        numerator = data_for_location[
            'moderately_underweight'] + data_for_location[
                'severely_underweight']
        value = numerator * 100 / (data_for_location['weighed'] or 1)
        if value < 20:
            data_for_location.update({'fillKey': '0%-20%'})
        elif 20 <= value < 35:
            data_for_location.update({'fillKey': '20%-35%'})
        elif value >= 35:
            data_for_location.update({'fillKey': '35%-100%'})

    fills = OrderedDict()
    fills.update({'0%-20%': MapColors.PINK})
    fills.update({'20%-35%': MapColors.ORANGE})
    fills.update({'35%-100%': MapColors.RED})
    fills.update({'Not Launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    average = ((values_to_calculate_average['numerator'] * 100) /
               float(values_to_calculate_average['denominator'] or 1))

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval='0 - 5 years')

    return {
        "slug":
        "moderately_underweight",
        "label":
        "Percent of Children{gender} Underweight ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            format_decimal(average),
            "info":
            underweight_children_help_text(age_label=age_label, html=True),
            "extended_info": [{
                'indicator':
                'Total Children{} weighed in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(weighed_total)
            }, {
                'indicator':
                'Number of children unweighed{}:'.format(chosen_filters),
                'value':
                indian_formatted_number(all_total - weighed_total)
            }, {
                'indicator':
                '% Severely Underweight{}:'.format(chosen_filters),
                'value':
                '%.2f%%' %
                (severely_underweight_total * 100 / float(weighed_total or 1))
            }, {
                'indicator':
                '% Moderately Underweight{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (moderately_underweight_total * 100 /
                            float(weighed_total or 1))
            }, {
                'indicator':
                '% Normal{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (normal_total * 100 / float(weighed_total or 1))
            }]
        },
        "data":
        dict(data_for_map)
    }
 def test_hundred_of_thousands(self):
     number = 200000
     india_format = indian_formatted_number(number)
     self.assertEqual(india_format, "2,00,000")
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 test_if_parameter_will_be_numeric_string(self):
     number = "10000000"
     india_format = indian_formatted_number(number)
     self.assertEquals(india_format, "1,00,00,000")
def get_prevalence_of_severe_data_map(domain, config, loc_level, show_test=False, icds_feature_flag=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(
            moderate=Sum(wasting_moderate_column(icds_feature_flag)),
            severe=Sum(wasting_severe_column(icds_feature_flag)),
            normal=Sum(wasting_normal_column(icds_feature_flag)),
            total_height_eligible=Sum('height_eligible'),
            total_weighed=Sum('nutrition_status_weighed'),
            total_measured=Sum(wfh_recorded_in_month_column(icds_feature_flag)),
        ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level)

        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.exclude(age_tranche=72)
        return queryset

    data_for_map = defaultdict(lambda: {
        'moderate': 0,
        'severe': 0,
        'normal': 0,
        'total_weighed': 0,
        'total_measured': 0,
        'total_height_eligible': 0,
        'original_name': []
    })

    severe_for_all_locations = 0
    moderate_for_all_locations = 0
    normal_for_all_locations = 0
    weighed_for_all_locations = 0
    measured_for_all_locations = 0
    height_eligible_for_all_locations = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    for row in get_data_for(config):
        total_weighed = row['total_weighed'] or 0
        total_height_eligible = row['total_height_eligible'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average['denominator'] += total_measured if total_measured else 0

        severe_for_all_locations += severe
        moderate_for_all_locations += moderate
        normal_for_all_locations += normal
        weighed_for_all_locations += total_weighed
        measured_for_all_locations += total_measured
        height_eligible_for_all_locations += total_height_eligible

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total_weighed'] += total_weighed
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['total_height_eligible'] += total_height_eligible
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 5:
            data_for_location.update({'fillKey': '0%-5%'})
        elif 5 <= value <= 7:
            data_for_location.update({'fillKey': '5%-7%'})
        elif value > 7:
            data_for_location.update({'fillKey': '7%-100%'})

    fills = OrderedDict()
    fills.update({'0%-5%': MapColors.PINK})
    fills.update({'5%-7%': MapColors.ORANGE})
    fills.update({'7%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )

    average = (
        (values_to_calculate_average['numerator'] * 100) /
        float(values_to_calculate_average['denominator'] or 1)
    )

    return {
        "slug": "severe",
        "label": "Percent of Children{gender} Wasted ({age})".format(
            gender=gender_label,
            age=age_label
        ),
        "fills": fills,
        "rightLegend": {
            "average": "%.2f" % average,
            "info": wasting_help_text(age_label),
            "extended_info": [
                {
                    'indicator': 'Total Children{} weighed in given month:'.format(chosen_filters),
                    'value': indian_formatted_number(weighed_for_all_locations)
                },
                {
                    'indicator': 'Total Children{} with height measured in given month:'
                    .format(chosen_filters),
                    'value': indian_formatted_number(measured_for_all_locations)
                },
                {
                    'indicator': 'Number of children{} unmeasured:'.format(chosen_filters),
                    'value': indian_formatted_number(height_eligible_for_all_locations - weighed_for_all_locations)
                },
                {
                    'indicator': '% Severely Acute Malnutrition{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (severe_for_all_locations * 100 / float(measured_for_all_locations or 1))
                },
                {
                    'indicator': '% Moderately Acute Malnutrition{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (moderate_for_all_locations * 100 / float(measured_for_all_locations or 1))
                },
                {
                    'indicator': '% Normal{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (normal_for_all_locations * 100 / float(measured_for_all_locations or 1))
                }
            ]
        },
        "data": dict(data_for_map),
    }
Exemple #19
0
def get_awcs_covered_data_map(domain, config, loc_level, show_test=False):
    level = config['aggregation_level']

    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(
                states=Sum('num_launched_states')
                if level <= 1 else Max('num_launched_states'),
                districts=Sum('num_launched_districts')
                if level <= 2 else Max('num_launched_districts'),
                blocks=Sum('num_launched_blocks')
                if level <= 3 else Max('num_launched_blocks'),
                supervisors=Sum('num_launched_supervisors')
                if level <= 4 else Max('num_launched_supervisors'),
                awcs=Sum('num_launched_awcs')
                if level <= 5 else Max('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_for_map = defaultdict(
        lambda: {
            'awcs': [],
            'supervisors': [],
            'blocks': [],
            'districts': [],
            'states': [],
            'original_name': []
        })

    for row in get_data_for(config):
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        awcs = row['awcs'] or 0
        supervisors = row['supervisors'] or 0
        blocks = row['blocks'] or 0
        districts = row['districts'] or 0
        states = row['states'] or 0

        data_for_map[on_map_name]['awcs'].append(awcs)
        data_for_map[on_map_name]['supervisors'].append(supervisors)
        data_for_map[on_map_name]['blocks'].append(blocks)
        data_for_map[on_map_name]['districts'].append(districts)
        data_for_map[on_map_name]['states'].append(states)
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in data_for_map.values():
        data_for_location['awcs'] = (sum(data_for_location['awcs'])
                                     if level <= 5 else max(
                                         data_for_location['awcs']))
        data_for_location['supervisors'] = (sum(
            data_for_location['supervisors']) if level <= 4 else max(
                data_for_location['supervisors']))
        data_for_location['blocks'] = (sum(data_for_location['blocks'])
                                       if level <= 3 else max(
                                           data_for_location['blocks']))
        data_for_location['districts'] = (sum(data_for_location['districts'])
                                          if level <= 2 else max(
                                              data_for_location['districts']))
        data_for_location['states'] = (sum(data_for_location['states'])
                                       if level <= 1 else max(
                                           data_for_location['states']))
        data_for_location.update({
            'fillKey':
            'Launched' if data_for_location['awcs'] > 0 else 'Not launched'
        })

    if level == 1:
        prop = 'states'
    elif level == 2:
        prop = 'districts'
    elif level == 3:
        prop = 'blocks'
    elif level == 4:
        prop = 'supervisors'
    else:
        prop = 'awcs'

    total_awcs = sum([(x['awcs'] or 0) for x in data_for_map.values()])
    total = sum([(x[prop] or 0) for x in data_for_map.values()])

    fills = OrderedDict()
    fills.update({'Launched': MapColors.PINK})
    fills.update({'Not launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    info = _("{:s}<br /><br />"
             "Number of AWCs launched: {:s}".format(
                 awcs_launched_help_text(),
                 indian_formatted_number(total_awcs)))
    if level != 5:
        info = _("{:s}<br /><br />"
                 "Number of AWCs launched: {:s} <br />"
                 "Number of {:s} launched: {:s}".format(
                     awcs_launched_help_text(),
                     indian_formatted_number(total_awcs), prop.title(),
                     indian_formatted_number(total)))

    return {
        "slug": "awc_covered",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "info": info
        },
        "data": dict(data_for_map),
    }
Exemple #20
0
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),
    }
Exemple #21
0
def get_prevalence_of_undernutrition_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(
                moderately_underweight=Sum(
                    'nutrition_status_moderately_underweight'),
                severely_underweight=Sum(
                    'nutrition_status_severely_underweight'),
                normal=Sum('nutrition_status_normal'),
                weighed=Sum('nutrition_status_weighed'),
                total=Sum('wer_eligible'),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.exclude(age_tranche=72)
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderately_underweight': 0,
            'severely_underweight': 0,
            'normal': 0,
            'weighed': 0,
            'total': 0,
            'original_name': []
        })

    moderately_underweight_total = 0
    severely_underweight_total = 0
    normal_total = 0
    all_total = 0
    weighed_total = 0

    values_to_calculate_average = []
    for row in get_data_for(config):
        weighed = row['weighed'] or 0
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severely_underweight = row['severely_underweight'] or 0
        moderately_underweight = row['moderately_underweight'] or 0
        normal = row['normal'] or 0

        numerator = moderately_underweight + severely_underweight
        values_to_calculate_average.append(numerator * 100 / (weighed or 1))

        moderately_underweight_total += moderately_underweight
        severely_underweight_total += severely_underweight
        normal_total += normal
        all_total += total
        weighed_total += weighed

        data_for_map[on_map_name][
            'severely_underweight'] += severely_underweight
        data_for_map[on_map_name][
            'moderately_underweight'] += moderately_underweight
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['weighed'] += weighed
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location[
            'moderately_underweight'] + data_for_location[
                'severely_underweight']
        value = numerator * 100 / (data_for_location['weighed'] or 1)
        if value < 20:
            data_for_location.update({'fillKey': '0%-20%'})
        elif 20 <= value < 35:
            data_for_location.update({'fillKey': '20%-35%'})
        elif value >= 35:
            data_for_location.update({'fillKey': '35%-100%'})

    fills = OrderedDict()
    fills.update({'0%-20%': MapColors.PINK})
    fills.update({'20%-35%': MapColors.ORANGE})
    fills.update({'35%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    average = ((sum(values_to_calculate_average)) /
               float(len(values_to_calculate_average) or 1))

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval='0 - 5 years')

    return {
        "slug":
        "moderately_underweight",
        "label":
        "Percent of Children{gender} Underweight ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            average,
            "info":
            _(("Of the total children enrolled for Anganwadi services and weighed, the percentage of "
               "children between {} years who were moderately/severely underweight in the current month. "
               "<br/><br/>"
               "Children who are moderately or severely underweight have a higher risk of mortality."
               .format(age_label))),
            "extended_info": [{
                'indicator':
                'Total Children{} weighed in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(weighed_total)
            }, {
                'indicator':
                'Number of children unweighed{}:'.format(chosen_filters),
                'value':
                indian_formatted_number(all_total - weighed_total)
            }, {
                'indicator':
                '% Severely Underweight{}:'.format(chosen_filters),
                'value':
                '%.2f%%' %
                (severely_underweight_total * 100 / float(weighed_total or 1))
            }, {
                'indicator':
                '% Moderately Underweight{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (moderately_underweight_total * 100 /
                            float(weighed_total or 1))
            }, {
                'indicator':
                '% Normal{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (normal_total * 100 / float(weighed_total or 1))
            }]
        },
        "data":
        dict(data_for_map)
    }
Exemple #22
0
def get_prevalence_of_severe_data_map(domain,
                                      config,
                                      loc_level,
                                      show_test=False,
                                      icds_feature_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(
                moderate=Sum(wasting_moderate_column(icds_feature_flag)),
                severe=Sum(wasting_severe_column(icds_feature_flag)),
                normal=Sum(wasting_normal_column(icds_feature_flag)),
                total_height_eligible=Sum('height_eligible'),
                total_weighed=Sum('nutrition_status_weighed'),
                total_measured=Sum(
                    wfh_recorded_in_month_column(icds_feature_flag)),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)

        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.filter(age_tranche__lt=72)
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total_weighed': 0,
            'total_measured': 0,
            'total_height_eligible': 0,
            'original_name': []
        })

    severe_for_all_locations = 0
    moderate_for_all_locations = 0
    normal_for_all_locations = 0
    weighed_for_all_locations = 0
    measured_for_all_locations = 0
    height_eligible_for_all_locations = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    if icds_feature_flag:
        location_launched_status = get_location_launched_status(
            config, loc_level)
    else:
        location_launched_status = None
    for row in get_data_for(config):
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        total_weighed = row['total_weighed'] or 0
        total_height_eligible = row['total_height_eligible'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average[
            'denominator'] += total_measured if total_measured else 0

        severe_for_all_locations += severe
        moderate_for_all_locations += moderate
        normal_for_all_locations += normal
        weighed_for_all_locations += total_weighed
        measured_for_all_locations += total_measured
        height_eligible_for_all_locations += total_height_eligible

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total_weighed'] += total_weighed
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name][
            'total_height_eligible'] += total_height_eligible
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in data_for_map.values():
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 5:
            data_for_location.update({'fillKey': '0%-5%'})
        elif 5 <= value <= 7:
            data_for_location.update({'fillKey': '5%-7%'})
        elif value > 7:
            data_for_location.update({'fillKey': '7%-100%'})

    fills = OrderedDict()
    fills.update({'0%-5%': MapColors.PINK})
    fills.update({'5%-7%': MapColors.ORANGE})
    fills.update({'7%-100%': MapColors.RED})
    if icds_feature_flag:
        fills.update({'Not Launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    average = ((values_to_calculate_average['numerator'] * 100) /
               float(values_to_calculate_average['denominator'] or 1))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Wasted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % average,
            "info":
            wasting_help_text(age_label),
            "extended_info": [{
                'indicator':
                'Total Children{} weighed in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(weighed_for_all_locations)
            }, {
                'indicator':
                'Total Children{} with weight and height measured in given month:'
                .format(chosen_filters),
                'value':
                indian_formatted_number(measured_for_all_locations)
            }, {
                'indicator':
                'Number of children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(height_eligible_for_all_locations -
                                        weighed_for_all_locations)
            }, {
                'indicator':
                '% Severely Acute Malnutrition{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (severe_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }, {
                'indicator':
                '% Moderately Acute Malnutrition{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (moderate_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }, {
                'indicator':
                '% Normal{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (normal_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
def get_enrolled_children_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(
            valid=Sum('valid_in_month'),
            all=Sum('valid_all_registered_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 = defaultdict(lambda: {
        'valid': 0,
        'all': 0,
        'original_name': [],
        'fillKey': 'Children'
    })
    average = []
    total_valid = 0
    total = 0
    for row in get_data_for(config):
        valid = row['valid'] or 0
        name = row['%s_name' % loc_level]
        all_children = row['all'] or 0
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(valid)
        total_valid += valid
        total += all_children
        data_for_map[on_map_name]['valid'] += valid
        data_for_map[on_map_name]['all'] += all_children
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Children': MapColors.BLUE})
    fills.update({'defaultFill': MapColors.GREY})

    gender_ignored, age_label, chosen_filters = chosen_filters_to_labels(config, default_interval='0 - 6 years')

    return {
        "slug": "enrolled_children",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average": '%.2f' % (total_valid * 100 / float(total or 1)),
            "info": percent_children_enrolled_help_text(age_label=age_label),
            "extended_info": [
                {
                    'indicator':
                        'Number of children{} who are enrolled for Anganwadi Services:'
                        .format(chosen_filters),
                    'value': indian_formatted_number(total_valid)
                },
                {
                    'indicator': (
                        'Total number of children{} who are registered: '
                        .format(chosen_filters)
                    ),
                    'value': indian_formatted_number(total)
                },
                {
                    'indicator': (
                        'Percentage of registered children{} who are enrolled for Anganwadi Services:'
                        .format(chosen_filters)
                    ),
                    'value': '%.2f%%' % (total_valid * 100 / float(total or 1))
                }
            ]
        },
        "data": dict(data_for_map),
    }
Exemple #24
0
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),
    }
Exemple #25
0
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),
    }
Exemple #26
0
def get_prevalence_of_stunting_data_map(domain,
                                        config,
                                        loc_level,
                                        show_test=False,
                                        icds_feature_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(
                moderate=Sum(stunting_moderate_column(icds_feature_flag)),
                severe=Sum(stunting_severe_column(icds_feature_flag)),
                normal=Sum(stunting_normal_column(icds_feature_flag)),
                total=Sum('height_eligible'),
                total_measured=Sum(
                    hfa_recorded_in_month_column(icds_feature_flag)),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.filter(age_tranche__lt=72)
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total': 0,
            'total_measured': 0,
            'original_name': []
        })

    moderate_total = 0
    severe_total = 0
    normal_total = 0
    all_total = 0
    measured_total = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}

    if icds_feature_flag:
        location_launched_status = get_location_launched_status(
            config, loc_level)
    else:
        location_launched_status = None

    for row in get_data_for(config):
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average[
            'denominator'] += total_measured if total_measured else 0

        severe_total += severe
        moderate_total += moderate
        normal_total += normal
        all_total += total
        measured_total += total_measured

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in data_for_map.values():
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 25:
            data_for_location.update({'fillKey': '0%-25%'})
        elif 25 <= value < 38:
            data_for_location.update({'fillKey': '25%-38%'})
        elif value >= 38:
            data_for_location.update({'fillKey': '38%-100%'})

    fills = OrderedDict()
    fills.update({'0%-25%': MapColors.PINK})
    fills.update({'25%-38%': MapColors.ORANGE})
    fills.update({'38%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))
    average = ((values_to_calculate_average['numerator'] * 100) /
               float(values_to_calculate_average['denominator'] or 1))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Stunted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % average,
            "info":
            _(("Of the children enrolled for Anganwadi services, whose height was measured, the percentage of "
               "children between {} who were moderately/severely stunted in the current month. "
               "<br/><br/>"
               "Stunting is a sign of chronic undernutrition and has long lasting harmful consequences on "
               "the growth of a child".format(age_label))),
            "extended_info": [{
                'indicator':
                'Total Children{} eligible to have height measured:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(all_total)
            }, {
                'indicator':
                'Total Children{} with height measured in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(measured_total)
            }, {
                'indicator':
                'Number of Children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(all_total - measured_total)
            }, {
                'indicator':
                '% children{} with severely stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (severe_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with moderate stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (moderate_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with normal stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (normal_total * 100 / float(measured_total or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
 def test_milions(self):
     number = 10000000
     india_format = indian_formatted_number(number)
     self.assertEquals(india_format, "1,00,00,000")
Exemple #28
0
def get_awcs_covered_data_map(domain, config, loc_level, show_test=False):
    level = config['aggregation_level']

    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(
            states=Sum('num_launched_states') if level <= 1 else Max('num_launched_states'),
            districts=Sum('num_launched_districts') if level <= 2 else Max('num_launched_districts'),
            blocks=Sum('num_launched_blocks') if level <= 3 else Max('num_launched_blocks'),
            supervisors=Sum('num_launched_supervisors') if level <= 4 else Max('num_launched_supervisors'),
            awcs=Sum('num_launched_awcs') if level <= 5 else Max('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_for_map = defaultdict(lambda: {
        'awcs': [],
        'supervisors': [],
        'blocks': [],
        'districts': [],
        'states': [],
        'original_name': []
    })

    for row in get_data_for(config):
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        awcs = row['awcs'] or 0
        supervisors = row['supervisors'] or 0
        blocks = row['blocks'] or 0
        districts = row['districts'] or 0
        states = row['states'] or 0

        data_for_map[on_map_name]['awcs'].append(awcs)
        data_for_map[on_map_name]['supervisors'].append(supervisors)
        data_for_map[on_map_name]['blocks'].append(blocks)
        data_for_map[on_map_name]['districts'].append(districts)
        data_for_map[on_map_name]['states'].append(states)
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        data_for_location['awcs'] = (
            sum(data_for_location['awcs']) if level <= 5 else max(data_for_location['awcs'])
        )
        data_for_location['supervisors'] = (
            sum(data_for_location['supervisors']) if level <= 4 else max(data_for_location['supervisors'])
        )
        data_for_location['blocks'] = (
            sum(data_for_location['blocks']) if level <= 3 else max(data_for_location['blocks'])
        )
        data_for_location['districts'] = (
            sum(data_for_location['districts']) if level <= 2 else max(data_for_location['districts'])
        )
        data_for_location['states'] = (
            sum(data_for_location['states']) if level <= 1 else max(data_for_location['states'])
        )
        data_for_location.update({'fillKey': 'Launched' if data_for_location['awcs'] > 0 else 'Not launched'})

    if level == 1:
        prop = 'states'
    elif level == 2:
        prop = 'districts'
    elif level == 3:
        prop = 'blocks'
    elif level == 4:
        prop = 'supervisors'
    else:
        prop = 'awcs'

    total_awcs = sum([(x['awcs'] or 0) for x in six.itervalues(data_for_map)])
    total = sum([(x[prop] or 0) for x in six.itervalues(data_for_map)])

    fills = OrderedDict()
    fills.update({'Launched': MapColors.PINK})
    fills.update({'Not launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    info = _(
        "{:s}<br /><br />"
        "Number of AWCs launched: {:s}".format(
            awcs_launched_help_text(),
            indian_formatted_number(total_awcs)
        )
    )
    if level != 5:
        info = _(
            "{:s}<br /><br />"
            "Number of AWCs launched: {:s} <br />"
            "Number of {:s} launched: {:s}".format(
                awcs_launched_help_text(),
                indian_formatted_number(total_awcs),
                prop.title(),
                indian_formatted_number(total)
            )
        )

    return {
        "slug": "awc_covered",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "info": info
        },
        "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": 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_prevalence_of_stunting_data_map(domain, config, loc_level, show_test=False, icds_feature_flag=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(
            moderate=Sum(stunting_moderate_column(icds_feature_flag)),
            severe=Sum(stunting_severe_column(icds_feature_flag)),
            normal=Sum(stunting_normal_column(icds_feature_flag)),
            total=Sum('height_eligible'),
            total_measured=Sum(hfa_recorded_in_month_column(icds_feature_flag)),
        ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.exclude(age_tranche=72)
        return queryset

    data_for_map = defaultdict(lambda: {
        'moderate': 0,
        'severe': 0,
        'normal': 0,
        'total': 0,
        'total_measured': 0,
        'original_name': []
    })

    moderate_total = 0
    severe_total = 0
    normal_total = 0
    all_total = 0
    measured_total = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    for row in get_data_for(config):
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average['denominator'] += total_measured if total_measured else 0

        severe_total += severe
        moderate_total += moderate
        normal_total += normal
        all_total += total
        measured_total += total_measured

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 25:
            data_for_location.update({'fillKey': '0%-25%'})
        elif 25 <= value < 38:
            data_for_location.update({'fillKey': '25%-38%'})
        elif value >= 38:
            data_for_location.update({'fillKey': '38%-100%'})

    fills = OrderedDict()
    fills.update({'0%-25%': MapColors.PINK})
    fills.update({'25%-38%': MapColors.ORANGE})
    fills.update({'38%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )
    average = (
        (values_to_calculate_average['numerator'] * 100) /
        float(values_to_calculate_average['denominator'] or 1)
    )

    return {
        "slug": "severe",
        "label": "Percent of Children{gender} Stunted ({age})".format(
            gender=gender_label,
            age=age_label
        ),
        "fills": fills,
        "rightLegend": {
            "average": "%.2f" % average,
            "info": _((
                "Of the children enrolled for Anganwadi services, whose height was measured, the percentage of "
                "children between {} who were moderately/severely stunted in the current month. "
                "<br/><br/>"
                "Stunting is a sign of chronic undernutrition and has long lasting harmful consequences on "
                "the growth of a child".format(age_label)
            )),
            "extended_info": [
                {
                    'indicator': 'Total Children{} eligible to have height measured:'.format(chosen_filters),
                    'value': indian_formatted_number(all_total)
                },
                {
                    'indicator': 'Total Children{} with height measured in given month:'
                    .format(chosen_filters),
                    'value': indian_formatted_number(measured_total)
                },
                {
                    'indicator': 'Number of Children{} unmeasured:'.format(chosen_filters),
                    'value': indian_formatted_number(all_total - measured_total)
                },
                {
                    'indicator': '% children{} with severely stunted growth:'.format(chosen_filters),
                    'value': '%.2f%%' % (severe_total * 100 / float(measured_total or 1))
                },
                {
                    'indicator': '% children{} with moderate stunted growth:'.format(chosen_filters),
                    'value': '%.2f%%' % (moderate_total * 100 / float(measured_total or 1))
                },
                {
                    'indicator': '% children{} with normal stunted growth:'.format(chosen_filters),
                    'value': '%.2f%%' % (normal_total * 100 / float(measured_total or 1))
                }
            ]
        },
        "data": dict(data_for_map),
    }
def get_lactating_enrolled_women_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(
            valid=Sum('lactating'),
            all=Sum('lactating_all'),
        ).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 = defaultdict(lambda: {
        'valid': 0,
        'all': 0,
        'original_name': [],
        'fillKey': 'Women'
    })
    average = []
    total_valid = 0
    total = 0
    for row in get_data_for(config):
        valid = row['valid'] or 0
        all_lactating = row['all'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(valid)

        total_valid += valid
        total += all_lactating

        data_for_map[on_map_name]['valid'] += valid
        data_for_map[on_map_name]['all'] += all_lactating
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Women': MapColors.BLUE})
    fills.update({'defaultFill': MapColors.GREY})

    return {
        "slug": "lactating_enrolled_women",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average": '%.2f' % (total_valid * 100 / float(total or 1)),
            "info": percent_lactating_women_enrolled_help_text(),
            "extended_info": [
                {
                    'indicator': 'Number of lactating women who are enrolled for Anganwadi Services:',
                    'value': indian_formatted_number(total_valid)
                },
                {
                    'indicator': (
                        'Total number of lactating women who are registered:'
                    ),
                    'value': indian_formatted_number(total)
                },
                {
                    'indicator': (
                        'Percentage of registered lactating women who are enrolled for Anganwadi Services:'
                    ),
                    'value': '%.2f%%' % (total_valid * 100 / float(total or 1))
                }
            ]
        },
        "data": dict(data_for_map),
    }
Exemple #32
0
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),
    }
Exemple #34
0
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 test_milions(self):
     number = 10000000
     india_format = indian_formatted_number(number)
     self.assertEqual(india_format, "1,00,00,000")
 def test_wrong_data(self):
     number = "some non numeric value"
     india_format = indian_formatted_number(number)
     self.assertEquals(india_format, 0)
 def test_wrong_data(self):
     number = "some non numeric value"
     india_format = indian_formatted_number(number)
     self.assertEqual(india_format, 0)
Exemple #38
0
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),
    }
Exemple #39
0
def get_enrolled_children_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(
                valid=Sum('valid_in_month'),
                all=Sum('valid_all_registered_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 = defaultdict(lambda: {
        'valid': 0,
        'all': 0,
        'original_name': [],
        'fillKey': 'Children'
    })
    average = []
    total_valid = 0
    total = 0

    location_launched_status = get_location_launched_status(config, loc_level)

    for row in get_data_for(config):
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        valid = row['valid'] or 0
        name = row['%s_name' % loc_level]
        all_children = row['all'] or 0
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(valid)
        total_valid += valid
        total += all_children
        data_for_map[on_map_name]['valid'] += valid
        data_for_map[on_map_name]['all'] += all_children
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Children': MapColors.BLUE})
    fills.update({'Not Launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    gender_ignored, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval='0 - 6 years')

    return {
        "slug": "enrolled_children",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average":
            '%.2f' % (total_valid * 100 / float(total or 1)),
            "info":
            percent_children_enrolled_help_text(age_label=age_label),
            "extended_info": [{
                'indicator':
                'Number of children{} who are enrolled for Anganwadi Services:'
                .format(chosen_filters),
                'value':
                indian_formatted_number(total_valid)
            }, {
                'indicator':
                ('Total number of children{} who are registered: '.format(
                    chosen_filters)),
                'value':
                indian_formatted_number(total)
            }, {
                'indicator':
                ('Percentage of registered children{} who are enrolled for Anganwadi Services:'
                 .format(chosen_filters)),
                'value':
                '%.2f%%' % (total_valid * 100 / float(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),
    }
Exemple #41
0
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 test_less_then_thousand(self):
     number = 900
     india_format = indian_formatted_number(number)
     self.assertEquals(india_format, "900")
def get_prevalence_of_stunting_data_map(domain,
                                        config,
                                        loc_level,
                                        show_test=False,
                                        icds_feature_flag=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(
                moderate=Sum(stunting_moderate_column(icds_feature_flag)),
                severe=Sum(stunting_severe_column(icds_feature_flag)),
                normal=Sum(stunting_normal_column(icds_feature_flag)),
                total=Sum('height_eligible'),
                total_measured=Sum('height_measured_in_month'),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            if icds_feature_flag:
                queryset = queryset.exclude(age_tranche=72)
            else:
                queryset = queryset.exclude(age_tranche__in=[0, 6, 72])
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total': 0,
            'total_measured': 0,
            'original_name': []
        })

    moderate_total = 0
    severe_total = 0
    normal_total = 0
    all_total = 0
    measured_total = 0

    values_to_calculate_average = []
    for row in get_data_for(config):
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        numerator = moderate + severe
        values_to_calculate_average.append(numerator * 100 /
                                           (total_measured or 1))

        severe_total += severe
        moderate_total += moderate
        normal_total += normal
        all_total += total
        measured_total += total_measured

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 25:
            data_for_location.update({'fillKey': '0%-25%'})
        elif 25 <= value < 38:
            data_for_location.update({'fillKey': '25%-38%'})
        elif value >= 38:
            data_for_location.update({'fillKey': '38%-100%'})

    fills = OrderedDict()
    fills.update({'0%-25%': MapColors.PINK})
    fills.update({'25%-38%': MapColors.ORANGE})
    fills.update({'38%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Stunted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % ((sum(values_to_calculate_average)) /
                      float(len(values_to_calculate_average) or 1)),
            "info":
            _(("Percentage of children ({}) enrolled for Anganwadi Services with height-for-age below "
               "-2Z standard deviations of the WHO Child Growth Standards median."
               "<br/><br/>"
               "Stunting is a sign of chronic undernutrition and has long lasting harmful "
               "consequences on the growth of a child".format(age_label))),
            "extended_info": [{
                'indicator':
                'Total Children{} eligible to have height measured:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(all_total)
            }, {
                'indicator':
                'Total Children{} with height measured in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(measured_total)
            }, {
                'indicator':
                'Number of Children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(all_total - measured_total)
            }, {
                'indicator':
                '% children{} with severely stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (severe_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with moderate stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (moderate_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with normal stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (normal_total * 100 / float(measured_total or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
Exemple #44
0
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_lactating_enrolled_women_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(
                valid=Sum('lactating'),
                all=Sum('lactating_all'),
            ).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 = defaultdict(lambda: {
        'valid': 0,
        'all': 0,
        'original_name': [],
        'fillKey': 'Women'
    })
    average = []
    total_valid = 0
    total = 0
    for row in get_data_for(config):
        valid = row['valid'] or 0
        all_lactating = row['all'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(valid)

        total_valid += valid
        total += all_lactating

        data_for_map[on_map_name]['valid'] += valid
        data_for_map[on_map_name]['all'] += all_lactating
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Women': MapColors.BLUE})
    fills.update({'defaultFill': MapColors.GREY})

    return {
        "slug": "lactating_enrolled_women",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average":
            '%.2f' % (total_valid * 100 / float(total or 1)),
            "info":
            percent_lactating_women_enrolled_help_text(),
            "extended_info": [{
                'indicator':
                'Number of lactating women who are enrolled for Anganwadi Services:',
                'value': indian_formatted_number(total_valid)
            }, {
                'indicator':
                ('Total number of lactating women who are registered:'),
                'value':
                indian_formatted_number(total)
            }, {
                'indicator':
                ('Percentage of registered lactating women who are enrolled for Anganwadi Services:'
                 ),
                'value':
                '%.2f%%' % (total_valid * 100 / float(total or 1))
            }]
        },
        "data": dict(data_for_map),
    }
Exemple #46
0
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),
    }
Exemple #47
0
def get_adolescent_girls_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(
                valid=Sum('cases_person_adolescent_girls_11_14'),
                all=Sum('cases_person_adolescent_girls_11_14_all'),
            ).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 = defaultdict(lambda: {
        'valid': 0,
        'all': 0,
        'original_name': [],
        'fillKey': 'Adolescent Girls'
    })
    average = []
    total_valid = 0
    total = 0
    for row in get_data_for(config):
        valid = row['valid'] or 0
        all_adolescent = row['all'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name

        average.append(valid)

        total_valid += valid
        total += all_adolescent

        data_for_map[on_map_name]['valid'] += valid
        data_for_map[on_map_name]['all'] += all_adolescent
        data_for_map[on_map_name]['original_name'].append(name)

    fills = OrderedDict()
    fills.update({'Adolescent Girls': MapColors.BLUE})
    fills.update({'defaultFill': MapColors.GREY})

    return {
        "slug": "adolescent_girls",
        "label": "",
        "fills": fills,
        "rightLegend": {
            "average":
            sum(average) / float(len(average) or 1),
            "average_format":
            'number',
            "info":
            _(("Of the total number of adolescent girls (aged 11-14 years), the percentage of girls enrolled "
               "for Anganwadi Services")),
            "extended_info": [{
                'indicator':
                ('Number of adolescent girls (11 - 14 years) who are enrolled for Anganwadi Services:'
                 ),
                'value':
                indian_formatted_number(total_valid)
            }, {
                'indicator':
                ('Total number of adolescent girls (11 - 14 years) who are registered:'
                 ),
                'value':
                indian_formatted_number(total)
            }, {
                'indicator':
                ('Percentage of registered adolescent girls (11 - 14 years) '
                 'who are enrolled for Anganwadi Services:'),
                'value':
                '%.2f%%' % (total_valid * 100 / float(total or 1))
            }]
        },
        "data": dict(data_for_map),
    }
 def test_hundred_of_thousands(self):
     number = 200000
     india_format = indian_formatted_number(number)
     self.assertEquals(india_format, "2,00,000")
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_prevalence_of_undernutrition_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(
            moderately_underweight=Sum('nutrition_status_moderately_underweight'),
            severely_underweight=Sum('nutrition_status_severely_underweight'),
            normal=Sum('nutrition_status_normal'),
            weighed=Sum('nutrition_status_weighed'),
            total=Sum('wer_eligible'),
        ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.exclude(age_tranche=72)
        return queryset

    data_for_map = defaultdict(lambda: {
        'moderately_underweight': 0,
        'severely_underweight': 0,
        'normal': 0,
        'weighed': 0,
        'total': 0,
        'original_name': []
    })

    moderately_underweight_total = 0
    severely_underweight_total = 0
    normal_total = 0
    all_total = 0
    weighed_total = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    for row in get_data_for(config):
        weighed = row['weighed'] or 0
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severely_underweight = row['severely_underweight'] or 0
        moderately_underweight = row['moderately_underweight'] or 0
        normal = row['normal'] or 0

        values_to_calculate_average['numerator'] += moderately_underweight if moderately_underweight else 0
        values_to_calculate_average['numerator'] += severely_underweight if severely_underweight else 0
        values_to_calculate_average['denominator'] += weighed if weighed else 0

        moderately_underweight_total += moderately_underweight
        severely_underweight_total += severely_underweight
        normal_total += normal
        all_total += total
        weighed_total += weighed

        data_for_map[on_map_name]['severely_underweight'] += severely_underweight
        data_for_map[on_map_name]['moderately_underweight'] += moderately_underweight
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['weighed'] += weighed
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderately_underweight'] + data_for_location['severely_underweight']
        value = numerator * 100 / (data_for_location['weighed'] or 1)
        if value < 20:
            data_for_location.update({'fillKey': '0%-20%'})
        elif 20 <= value < 35:
            data_for_location.update({'fillKey': '20%-35%'})
        elif value >= 35:
            data_for_location.update({'fillKey': '35%-100%'})

    fills = OrderedDict()
    fills.update({'0%-20%': MapColors.PINK})
    fills.update({'20%-35%': MapColors.ORANGE})
    fills.update({'35%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    average = (
        (values_to_calculate_average['numerator'] * 100) /
        float(values_to_calculate_average['denominator'] or 1)
    )

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(config, default_interval='0 - 5 years')

    return {
        "slug": "moderately_underweight",
        "label": "Percent of Children{gender} Underweight ({age})".format(
            gender=gender_label,
            age=age_label
        ),
        "fills": fills,
        "rightLegend": {
            "average": format_decimal(average),
            "info": underweight_children_help_text(age_label=age_label, html=True),
            "extended_info": [
                {
                    'indicator': 'Total Children{} weighed in given month:'.format(chosen_filters),
                    'value': indian_formatted_number(weighed_total)
                },
                {
                    'indicator': 'Number of children unweighed{}:'.format(chosen_filters),
                    'value': indian_formatted_number(all_total - weighed_total)
                },
                {
                    'indicator': '% Severely Underweight{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (severely_underweight_total * 100 / float(weighed_total or 1))
                },
                {
                    'indicator': '% Moderately Underweight{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (moderately_underweight_total * 100 / float(weighed_total or 1))
                },
                {
                    'indicator': '% Normal{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (normal_total * 100 / float(weighed_total or 1))
                }
            ]
        },
        "data": dict(data_for_map)
    }