|
1
|
|
|
# coding: utf8 |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
This software is licensed under the Apache 2 license, quoted below. |
|
5
|
|
|
|
|
6
|
|
|
Copyright 2016 Crystalnix Limited |
|
7
|
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
9
|
|
|
use this file except in compliance with the License. You may obtain a copy of |
|
10
|
|
|
the License at |
|
11
|
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
16
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
17
|
|
|
License for the specific language governing permissions and limitations under |
|
18
|
|
|
the License. |
|
19
|
|
|
""" |
|
20
|
|
|
|
|
21
|
|
|
from functools import partial |
|
22
|
|
|
|
|
23
|
|
|
from bitmapist import mark_event, MonthEvents |
|
24
|
|
|
from django.utils import timezone |
|
25
|
|
|
|
|
26
|
|
|
from omaha.statistics import get_id, is_new_install, redis |
|
27
|
|
|
from omaha.settings import DEFAULT_CHANNEL |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
def collect_statistics(request, appid, channel): |
|
31
|
|
|
deviceID = request.GET.get('deviceID') |
|
32
|
|
|
version = request.GET.get('appVersionShort') |
|
33
|
|
|
if not deviceID or not version: |
|
34
|
|
|
return |
|
35
|
|
|
app = dict(appid=appid, |
|
36
|
|
|
version=version, |
|
37
|
|
|
tag=channel) |
|
38
|
|
|
|
|
39
|
|
|
userid_counting(deviceID, app, 'mac') |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def userid_counting(userid, app, platform, now=None): |
|
43
|
|
|
id = get_id(userid) |
|
44
|
|
|
mark_event('request', id, now=now) |
|
45
|
|
|
add_app_statistics(id, platform, app, now=now) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
def add_app_statistics(userid, platform, app, now=None): |
|
49
|
|
|
mark = partial(mark_event, now=now) |
|
50
|
|
|
if not now: |
|
51
|
|
|
now = timezone.now() |
|
52
|
|
|
appid = app.get('appid') |
|
53
|
|
|
version = app.get('version') |
|
54
|
|
|
channel = app.get('tag') or DEFAULT_CHANNEL |
|
55
|
|
|
|
|
56
|
|
|
if is_new_install(appid, userid): |
|
57
|
|
|
mark('new_install:%s' % appid, userid) |
|
58
|
|
|
mark('new_install:{}:{}'.format(appid, platform), userid) |
|
59
|
|
|
redis.setbit("known_users:%s" % appid, userid, 1) |
|
60
|
|
|
elif userid not in MonthEvents('new_install:{}:{}'.format(appid, platform), year=now.year, month=now.month): |
|
61
|
|
|
mark('request:%s' % appid, userid) |
|
62
|
|
|
mark('request:{}:{}'.format(appid, platform), userid) |
|
63
|
|
|
|
|
64
|
|
|
mark('request:{}:{}'.format(appid, version), userid, track_hourly=True) |
|
65
|
|
|
mark('request:{}:{}'.format(appid, channel), userid) |
|
66
|
|
|
mark('request:{}:{}:{}'.format(appid, platform, version), userid, track_hourly=True) |