Esempio n. 1
0
    def get_months_from_weeks(self, request):
        start_period = request.GET['from_date']
        end_period = request.GET['to_date']
        group_by_column = request.GET['group']

        actual_group_by_column = get_actual_group_by_column(group_by_column)

        results = []
        if group_by_column == 'period':
            for period in periods_in_ranges(start_period, end_period):
                (year, month) = get_year_and_month_from_period(period)
                for week in month_to_weeks(year, month):
                    weekly_period = "%sW%s" % (year, week)
                    year_month = "%s'%s" % (get_month_from_int(month), str(year)[2:])

                    results.append({actual_group_by_column: weekly_period,
                                    'value_aggregate': year_month})

        return results
Esempio n. 2
0
    def get_population(self, request):
        start_period = request.GET['from_date']
        end_period = request.GET['to_date']
        group_by_column = request.GET['group']

        region = self.get_int_with_default(request, 'region', 0)
        district = self.get_int_with_default(request, 'district', 0)

        results = []
        if group_by_column == 'period':
            total_population = District.objects

            if region == 0 and district > 0:
                total_population = total_population.filter(pk=district)
            elif district == 0 and region > 0:
                total_population = total_population.filter(region=region)

            total_population = total_population.aggregate(Sum('population'))

            actual_group_by_column = get_actual_group_by_column(group_by_column)
            for period in periods_in_ranges(start_period, end_period):

                results.append({actual_group_by_column: period,
                                'value_aggregate': total_population['population__sum']})

                (year, month) = get_year_and_month_from_period(period)
                for week in month_to_weeks(year, month):
                    weekly_period = "%sW%s" % (year, week)
                    results.append({actual_group_by_column: weekly_period,
                                    'value_aggregate': total_population['population__sum']})

        elif group_by_column == 'district':
            districts = District.objects.all()
            for district in districts:
                results.append({'district': district.pk, 'value_aggregate': district.population})

        return results