@@ 250-267 (lines=18) @@ | ||
247 | try: |
|
248 | return Application.objects.get(name=name) |
|
249 | except Application.DoesNotExist: |
|
250 | raise Http404 |
|
251 | ||
252 | def get(self, request, app_name, format=None): |
|
253 | import logging |
|
254 | logging.info('Starting working in view') |
|
255 | app = self.get_object(app_name) |
|
256 | ||
257 | now = timezone.now() |
|
258 | data = LiveStatisticsInputSerializer(data=request.GET) |
|
259 | data.is_valid() |
|
260 | ||
261 | end = data.validated_data.get('end', now) |
|
262 | start = data.validated_data.get('start', end - datetime.timedelta(hours=24)) |
|
263 | channel = data.validated_data.get('channel') |
|
264 | ||
265 | data = get_users_live_versions(app.id, start, end, channel, tz=request.session.get('django_timezone', 'UTC')) |
|
266 | logging.info('Getting data is finished') |
|
267 | serializer = StatisticsMonthsSerializer(dict(data=dict(data))) |
|
268 | return Response(serializer.data) |
|
269 | ||
270 | ||
@@ 208-225 (lines=18) @@ | ||
205 | for year in range(start.year, end.year+1)] |
|
206 | ||
207 | data = {} |
|
208 | platforms = Platform.objects.values_list('name', flat=True) |
|
209 | for platform in platforms: |
|
210 | if platform == 'mac': |
|
211 | platform_keys = self.MAC_KEYS |
|
212 | else: |
|
213 | platform_keys = self.OMAHA_KEYS |
|
214 | platform_data = {key: [] for key in platform_keys} |
|
215 | for diapason in diapasons: |
|
216 | step = get_users_statistics_months(app_id=app.id, platform=platform, year=diapason[1], |
|
217 | start=diapason[0][0], end=diapason[0][1]) |
|
218 | for key in platform_data: |
|
219 | platform_data[key] += step[key] |
|
220 | data.update({platform: platform_data}) |
|
221 | ||
222 | serializer = StatisticsMonthsSerializer(dict(data=data)) |
|
223 | return Response(serializer.data) |
|
224 | ||
225 | class StatisticsVersionsView(APIView): |
|
226 | def get_object(self, name): |
|
227 | try: |
|
228 | return Application.objects.get(name=name) |