def get_period_list(self):
        if self.data_set.period_type.lower() == 'weekly':
            year = int(str(self.period)[0:4])
            month = int(str(self.period)[4:])

            weeks = utils.month_to_weeks(year, month)
            period_list = utils.create_period_list(year, weeks)
        else:
            period_list = self.period
        return period_list
Example #2
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
Example #3
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
Example #4
0
 def test_that_month_to_weeks_compares_years_too(self):
     weeks = utils.month_to_weeks(2015, 12)
     self.assertEqual(weeks, [50, 51, 52, 53])
Example #5
0
 def test_convert_weeks_to_period_list(self):
     weeks = utils.month_to_weeks(2016, 12)
     period_list = utils.create_period_list(2016, weeks)
     self.assertEqual(period_list, "2016W49,2016W50,2016W51,2016W52")
Example #6
0
 def test_conversion_of_december_month_to_weeks(self):
     weeks = utils.month_to_weeks(2016, 12)
     self.assertEqual(weeks, [49, 50, 51, 52])
Example #7
0
 def test_conversion_of_february_month_to_weeks(self):
     weeks = utils.month_to_weeks(2016, 02)
     self.assertEqual(weeks, [5, 6, 7, 8, 9])
Example #8
0
 def test_conversion_of_january_month_to_weeks(self):
     weeks = utils.month_to_weeks(2016, 01)
     self.assertEqual(weeks, [1, 2, 3, 4])