Exemple #1
0
    def get_excel_data(self, location):
        aggregation_level = self.loc_level
        filters = {}
        filters[
            'aggregation_level'] = aggregation_level  # this report is needed district wise only
        export_filters = [['Generated at', india_now()]]
        if location:
            try:
                locs = SQLLocation.objects.get(
                    location_id=location).get_ancestors(include_self=True)
                for loc in locs:
                    export_filters.append(
                        [loc.location_type.name.title(), loc.name])
                    location_key = '%s_id' % loc.location_type.code
                    filters.update({
                        location_key: loc.location_id,
                    })
            except SQLLocation.DoesNotExist:
                pass
        order_by = ('state_name', 'district_name')
        if self.report_type == 'month':
            filters['month'] = self.config['month']
            excel_rows = self.month_wise(filters, order_by)
        else:
            filters['month__in'] = generate_quarter_months(
                self.quarter, self.year)
            excel_rows = self.quarter_wise(filters, order_by,
                                           aggregation_level)

        export_filters.append(['Report Layout', self.layout.title()])
        export_filters.append(['Data Period', self.report_type.title()])

        return [[self.title, excel_rows], ['Export Info', export_filters]]
def get_poshan_progress_dashboard_data(domain,
                                       year,
                                       month,
                                       quarter,
                                       data_period,
                                       step,
                                       location_filters,
                                       include_test=False,
                                       beta=False):
    aggregation_level = location_filters.get('aggregation_level', 1)
    filters = location_filters
    value_fields = PPR_COLS_TO_FETCH[:]
    unique_id = ''
    if data_period == 'month':
        filters['month'] = date(year, month, 1)
    else:
        months = generate_quarter_months(quarter, year)
        if aggregation_level == 1:
            unique_id = 'state_id'
            value_fields.append('state_id')
        else:
            unique_id = 'district_id'
            value_fields.append('district_id')
    # including only launched states and districts
    filters['num_launched_awcs__gt'] = 0
    order_by = ('state_name', 'district_name')
    if aggregation_level == 1:
        value_fields.remove('district_name')
    response = {}

    if step == 'aggregated':
        value_fields.append('num_launched_states')
        if data_period == 'month':
            data = fetch_month_data(value_fields, order_by, filters,
                                    include_test, domain)
        else:
            data = fetch_quarter_data(value_fields, order_by, filters,
                                      include_test, domain, months,
                                      data_period, unique_id)
        response = calculate_aggregated_row(data, aggregation_level, beta)
    elif step == 'comparative':
        if data_period == 'month':
            data = fetch_month_data(value_fields, order_by, filters,
                                    include_test, domain)
        else:
            data = fetch_quarter_data(value_fields, order_by, filters,
                                      include_test, domain, months,
                                      data_period, unique_id)
        response = calculate_comparative_rows(data, aggregation_level, beta)
    return response
Exemple #3
0
def get_poshan_progress_dashboard_data(domain,
                                       year,
                                       month,
                                       quarter,
                                       data_format,
                                       step,
                                       location_filters,
                                       include_test=False):
    aggregation_level = location_filters.get('aggregation_level', 1)
    filters = location_filters
    value_fields = PPR_COLS_TO_FETCH[:]
    unique_id = ''
    if data_format == 'month':
        filters['month'] = date(year, month, 1)
    else:
        filters['month__in'] = generate_quarter_months(quarter, year)
        if aggregation_level == 1:
            unique_id = 'state_id'
            value_fields.append('state_id')
        else:
            unique_id = 'district_id'
            value_fields.append('district_id')
    order_by = ('state_name', 'district_name')
    if aggregation_level == 1:
        value_fields.remove('district_name')
    response = {}
    queryset = PoshanProgressReportView.objects.filter(**filters).order_by(
        *order_by)
    if not include_test:
        queryset = apply_exclude(domain, queryset)

    if step == 'aggregated':
        data = queryset.aggregate(
            num_launched_states=Sum('num_launched_states'),
            num_launched_districts=Sum('num_launched_districts'),
            num_launched_blocks=Sum('num_launched_blocks'),
            num_launched_awcs=Sum('num_launched_awcs'),
            awc_days_open=Sum('awc_days_open'),
            expected_visits=Sum('expected_visits'),
            valid_visits=Sum('valid_visits'),
            pse_eligible=Sum('pse_eligible'),
            pse_attended_21_days=Sum('pse_attended_21_days'),
            wer_eligible=Sum('wer_eligible'),
            wer_weighed=Sum('wer_weighed'),
            trimester_3=Sum('trimester_3'),
            counsel_immediate_bf=Sum('counsel_immediate_bf'),
            height_eligible=Sum('height_eligible'),
            height_measured_in_month=Sum('height_measured_in_month'),
            thr_eligible=Sum('thr_eligible'),
            thr_rations_21_plus_distributed=Sum(
                'thr_rations_21_plus_distributed'),
            lunch_eligible=Sum('lunch_eligible'),
            lunch_count_21_days=Sum('lunch_count_21_days'),
        )
        response = calculate_aggregated_row(data, aggregation_level,
                                            data_format)
    elif step == 'comparative':
        data = queryset.values(*value_fields)
        response = calculate_comparative_rows(deepcopy(data),
                                              aggregation_level, data_format,
                                              unique_id)
    return response