示例#1
0
    def get(self, request, app_name, format=None):
        app = self.get_object(app_name)
        dates = MonthRangeSerializer(data=request.GET)
        dates.is_valid()

        start, end = get_month_range_from_dict(dates.validated_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 = {}
        platforms = Platform.objects.values_list('name', flat=True)
        for platform in platforms:
            if platform == 'mac':
                platform_keys = self.MAC_KEYS
            else:
                platform_keys = self.OMAHA_KEYS
            platform_data = {key: [] for key in platform_keys}
            for diapason in diapasons:
                step = get_users_statistics_months(app_id=app.id,
                                                   platform=platform,
                                                   year=diapason[1],
                                                   start=diapason[0][0],
                                                   end=diapason[0][1])
                for key in platform_data:
                    platform_data[key] += step[key]
            data.update({platform: platform_data})

        serializer = StatisticsMonthsSerializer(dict(data=data))
        return Response(serializer.data)
示例#2
0
    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
示例#3
0
    def get(self, request, app_name, format=None):
        app = self.get_object(app_name)
        dates = MonthRangeSerializer(data=request.GET)
        dates.is_valid()

        start, end = get_month_range_from_dict(dates.validated_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)]

        win_data = dict(new=[], updates=[], uninstalls=[])
        mac_data = dict(new=[], updates=[])
        for diapason in diapasons:
            step = get_users_statistics_months(app_id=app.id,
                                               platform='win',
                                               year=diapason[1],
                                               start=diapason[0][0],
                                               end=diapason[0][1])
            win_data['new'] += step['new']
            win_data['updates'] += step['updates']
            win_data['uninstalls'] += step['uninstalls']
            step = get_users_statistics_months(app_id=app.id,
                                               platform='mac',
                                               year=diapason[1],
                                               start=diapason[0][0],
                                               end=diapason[0][1])
            mac_data['new'] += step['new']
            mac_data['updates'] += step['updates']

        serializer = StatisticsMonthsSerializer(
            dict(data=dict(win=win_data, mac=mac_data)))
        return Response(serializer.data)
示例#4
0
    def get(self, request, app_name, format=None):
        app = self.get_object(app_name)
        dates = MonthRangeSerializer(data=request.GET)
        dates.is_valid()

        start, end = get_month_range_from_dict(dates.validated_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 = {}
        platforms = Platform.objects.values_list('name', flat=True)
        for platform in platforms:
            if platform == 'mac':
                platform_keys = self.MAC_KEYS
            else:
                platform_keys = self.OMAHA_KEYS
            platform_data = {key: [] for key in platform_keys}
            for diapason in diapasons:
                step = get_users_statistics_months(app_id=app.id, platform=platform, year=diapason[1],
                                                   start=diapason[0][0], end=diapason[0][1])
                for key in platform_data:
                    platform_data[key] += step[key]
            data.update({platform: platform_data})

        serializer = StatisticsMonthsSerializer(dict(data=data))
        return Response(serializer.data)
示例#5
0
    def get(self, request, format=None):
        dates = MonthRangeSerializer(data=request.GET)
        dates.is_valid()

        start, end = get_month_range_from_dict(dates.validated_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(year=diapason[1], start=diapason[0][0], end=diapason[0][1])

        serializer = StatisticsMonthsSerializer(dict(data=dict(data)))
        return Response(serializer.data)
示例#6
0
    def get_context_data(self, **kwargs):
        context = super(StatisticsView, self).get_context_data(**kwargs)

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

        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(year=diapason[1], start=diapason[0][0], end=diapason[0][1])

        context['range_start'] = start.strftime('%B %Y')
        context['range_end'] = end.strftime('%B %Y')
        context['months'] = make_discrete_bar_chart('months', data)
        context['weeks'] = make_discrete_bar_chart('weeks', get_users_statistics_weeks())
        context['form'] = form
        return context
示例#7
0
    def get(self, request, app_name, format=None):
        app = self.get_object(app_name)
        dates = MonthRangeSerializer(data=request.GET)
        dates.is_valid()

        start, end = get_month_range_from_dict(dates.validated_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)]

        win_data = dict(new=[], updates=[])
        mac_data = dict(new=[], updates=[])
        for diapason in diapasons:
            step = get_users_statistics_months(app_id=app.id, platform='win', year=diapason[1], start=diapason[0][0], end=diapason[0][1])
            win_data['new'] += step['new']
            win_data['updates'] += step['updates']
            step = get_users_statistics_months(app_id=app.id, platform='mac', year=diapason[1], start=diapason[0][0], end=diapason[0][1])
            mac_data['new'] += step['new']
            mac_data['updates'] += step['updates']

        serializer = StatisticsMonthsSerializer(dict(data=dict(win=win_data, mac=mac_data)))
        return Response(serializer.data)
示例#8
0
    def get(self, request, app_name, format=None):
        app = self.get_object(app_name)

        now = timezone.now()
        last_week = now - datetime.timedelta(days=7)
        dates = MonthRangeSerializer(data=request.GET)
        dates.is_valid()

        start, end = get_month_range_from_dict(dates.validated_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])
        data.append(('install_count', qs.filter(events__eventtype=2).count()))
        data.append(('update_count', qs.filter(events__eventtype=3).count()))
        serializer = StatisticsMonthsSerializer(dict(data=dict(data)))
        return Response(serializer.data)