def get_context_data(self, **kwargs):
        context = super(StatisticsDetailView, self).get_context_data(**kwargs)

        app = self.object
        form = self.get_form()
        form.is_valid()

        now = timezone.now()
        last_week = now - datetime.timedelta(days=7)

        start, end = get_month_range_from_dict(form.cleaned_data)

        diapasons = [((start.month if year == start.year else 1, end.month if year == end.year else 12), year)
                     for year in range(start.year, end.year+1)]

        data = []
        for diapason in diapasons:
            data += get_users_statistics_months(app_id=app.id, year=diapason[1], start=diapason[0][0], end=diapason[0][1])

        qs = AppRequest.objects.filter(appid=app.id,
                                       request__created__range=[last_week, now])

        context['range_start'] = start.strftime('%B %Y')
        context['range_end'] = end.strftime('%B %Y')
        context['install_count'] = qs.filter(events__eventtype=2).count()
        context['update_count'] = qs.filter(events__eventtype=3).count()

        context['months'] = make_discrete_bar_chart('months', data)
        context['weeks'] = make_discrete_bar_chart('weeks', get_users_statistics_weeks(app_id=app.id))
        context['versions'] = make_piechart('versions', get_users_versions(app.id))
        context['channels'] = make_piechart('channels', get_channel_statistics(app.id))
        versions_data = [dict(version=x[0], number=x[1]) for x in get_users_versions(app.id)]
        context['versions_table'] = VersionsTable(versions_data)
        context['form'] = form
        return context
Exemple #2
0
    def get(self, request, app_name, format=None):
        now = timezone.now()
        app = self.get_object(app_name)

        date = MonthInputSerializer(data=request.GET)
        date.is_valid()
        date = date.validated_data.get('date', now)

        data = get_users_versions(app.id, date=date)
        serializer = StatisticsMonthsSerializer(dict(data=dict(data)))
        return Response(serializer.data)
Exemple #3
0
    def get(self, request, app_name, format=None):
        now = timezone.now()
        app = self.get_object(app_name)

        date = MonthInputSerializer(data=request.GET)
        date.is_valid()
        date = date.validated_data.get('date', now)

        data = get_users_versions(app.id, date=date)
        serializer = StatisticsMonthsSerializer(dict(data=dict(data)))
        return Response(serializer.data)
    def get_context_data(self, **kwargs):
        context = super(StatisticsDetailView, self).get_context_data(**kwargs)

        app = self.object

        now = timezone.now()
        last_week = now - datetime.timedelta(days=7)

        qs = AppRequest.objects.filter(appid=app.id,
                                       request__created__range=[last_week, now])

        context['install_count'] = qs.filter(events__eventtype=2).count()
        context['update_count'] = qs.filter(events__eventtype=3).count()

        context['months'] = make_discrete_bar_chart('months', get_users_statistics_months(app_id=app.id))
        context['weeks'] = make_discrete_bar_chart('weeks', get_users_statistics_weeks(app_id=app.id))
        context['versions'] = make_piechart('versions', get_users_versions(app.id))
        context['channels'] = make_piechart('channels', get_channel_statistics(app.id))

        return context
Exemple #5
0
    def get_context_data(self, **kwargs):
        context = super(StatisticsDetailView, self).get_context_data(**kwargs)

        app = self.object

        now = timezone.now()
        last_week = now - datetime.timedelta(days=7)

        qs = AppRequest.objects.filter(
            appid=app.id, request__created__range=[last_week, now])

        context['install_count'] = qs.filter(events__eventtype=2).count()
        context['update_count'] = qs.filter(events__eventtype=3).count()

        context['months'] = make_discrete_bar_chart(
            'months', get_users_statistics_months(app_id=app.id))
        context['weeks'] = make_discrete_bar_chart(
            'weeks', get_users_statistics_weeks(app_id=app.id))
        context['versions'] = make_piechart('versions',
                                            get_users_versions(app.id))
        context['channels'] = make_piechart('channels',
                                            get_channel_statistics(app.id))

        return context
Exemple #6
0
 def setUp(self):
     super(StatisticsVersionsTest, self).setUp()
     data = get_users_versions(self.app.id)
     self.data = dict(data=dict(data))
 def test_get_users_versions(self):
     now = datetime.now()
     expected = dict(win={"1.0.0.0": now.month}, mac={"13.0.782.112": now.month})
     with freeze_time(datetime(year=now.year, month=now.month, day=10)):
         self.assertDictEqual(get_users_versions(self.app.id), expected)
Exemple #8
0
 def setUp(self):
     super(StatisticsVersionsTest, self).setUp()
     data = get_users_versions(self.app.id)
     self.data = dict(data=dict(data))
Exemple #9
0
 def get(self, request, app_name, format=None):
     app = self.get_object(app_name)
     data = get_users_versions(app.id)
     serializer = StatisticsMonthsSerializer(dict(data=dict(data)))
     return Response(serializer.data)
Exemple #10
0
 def get(self, request, app_name, format=None):
     app = self.get_object(app_name)
     data = get_users_versions(app.id)
     serializer = StatisticsMonthsSerializer(dict(data=dict(data)))
     return Response(serializer.data)
Exemple #11
0
 def test_get_users_versions(self):
     now = datetime.now()
     expected = dict(win={'1.0.0.0': now.month},
                     mac={'13.0.782.112': now.month})
     with freeze_time(datetime(year=now.year, month=now.month, day=10)):
         self.assertDictEqual(get_users_versions(self.app.id), expected)
 def test_get_users_versions(self):
     now = datetime.now()
     with freeze_time(datetime(year=now.year, month=now.month, day=10)):
         self.assertListEqual(get_users_versions(self.app.id), [('1.0.0.0', now.month), ('2.0.0.0', 0)])
Exemple #13
0
 def test_get_users_versions(self):
     now = datetime.now()
     with freeze_time(datetime(year=now.year, month=now.month, day=1)):
         self.assertListEqual(get_users_versions(self.app.id),
                              [('1.0.0.0', now.month), ('2.0.0.0', 0)])