summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--omaha_server/omaha/management/commands/generate_fake_live_data.py41
-rw-r--r--omaha_server/omaha/static/statistics/js/live_charts.js19
-rw-r--r--omaha_server/omaha/statistics.py93
-rw-r--r--omaha_server/omaha/templates/admin/omaha/live_statistics.html6
-rw-r--r--omaha_server/omaha/tests/test_api.py35
-rw-r--r--omaha_server/omaha/tests/test_statistics.py83
-rw-r--r--omaha_server/sparkle/statistics.py12
-rw-r--r--omaha_server/sparkle/tests/test_statistics.py30
8 files changed, 146 insertions, 173 deletions
diff --git a/omaha_server/omaha/management/commands/generate_fake_live_data.py b/omaha_server/omaha/management/commands/generate_fake_live_data.py
index 8438c47..ed3627a 100644
--- a/omaha_server/omaha/management/commands/generate_fake_live_data.py
+++ b/omaha_server/omaha/management/commands/generate_fake_live_data.py
@@ -23,6 +23,7 @@ from builtins import range, bytes
import random
import uuid
+from optparse import make_option
from django.core.management.base import BaseCommand
from django.utils import timezone
@@ -33,33 +34,40 @@ from omaha.parser import parse_request
from omaha.statistics import collect_statistics
from omaha.models import Version
-event_install = b"""<?xml version="1.0" encoding="UTF-8"?>
-<request protocol="3.0" version="1.3.23.0" ismachine="1" sessionid="{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}" userid="{%s}" installsource="otherinstallcmd" testsource="ossdev" requestid="{164FC0EC-8EF7-42cb-A49D-474E20E8D352}">
- <os platform="win" version="6.1" sp="" arch="x64"/>
- <app appid="%s" version="" nextversion="%s" lang="en" brand="" client="" installage="6">
- <event eventtype="9" eventresult="1" errorcode="0" extracode1="0"/>
- <event eventtype="5" eventresult="1" errorcode="0" extracode1="0"/>
- <event eventtype="2" eventresult="1" errorcode="0" extracode1="0"/>
- </app>
-</request>
-"""
+event_updatecheck = b"""<?xml version="1.0" encoding="UTF-8"?>
+<request protocol="3.0"
+ version="1.3.23.0"
+ ismachine="0"
+ sessionid="{5FAD27D4-6BFA-4daa-A1B3-5A1F821FEE0F}"
+ userid="{%s}"
+ installsource="scheduler"
+ testsource="ossdev"
+ requestid="{C8F6EDF3-B623-4ee6-B2DA-1D08A0B4C665}">
+ <os platform="win" version="6.1" sp="" arch="x64"/>
+ <app appid="%s" version="%s" nextversion="" lang="en" brand="GGLS"
+ client="someclientid" installage="39">
+ <updatecheck/>
+ <ping r="1"/>
+ </app>
+</request>"""
def generate_events(app_id, **options):
versions = Version.objects.filter_by_enabled(app__id=app_id)
versions = map(lambda x: x.version, versions)
+ n_hours = options['n_hours']
def generate_fake_hour():
for version in versions:
for i in range(random.randint(0, 20)):
id = uuid.UUID(int=i)
- request = event_install % (id, app_id, version)
+ request = event_updatecheck % (id, app_id, version)
request = bytes(request, 'utf8')
request = parse_request(request)
collect_statistics(request)
- start = timezone.now() - timezone.timedelta(days=1)
+ start = timezone.now() - timezone.timedelta(hours=n_hours)
- for hourdelta in range(1, 25):
+ for hourdelta in range(0, n_hours + 1):
if hourdelta % 10 == 0:
print('=> ', hourdelta)
with freeze_time(start + timezone.timedelta(hours=hourdelta)):
@@ -69,6 +77,13 @@ def generate_events(app_id, **options):
class Command(BaseCommand):
args = '<app_id>'
help = 'A command for generating fake live statistics'
+ option_list = BaseCommand.option_list + (
+ make_option('--hours',
+ dest='n_hours',
+ default='24',
+ type=int,
+ help='For how many hours will be generated fake data(default: 24)'),
+ )
def handle(self, app_id, *args, **options):
generate_events(app_id, **options)
diff --git a/omaha_server/omaha/static/statistics/js/live_charts.js b/omaha_server/omaha/static/statistics/js/live_charts.js
index 42da3c7..429197f 100644
--- a/omaha_server/omaha/static/statistics/js/live_charts.js
+++ b/omaha_server/omaha/static/statistics/js/live_charts.js
@@ -1,4 +1,5 @@
var macChartData, macChart, winChartData, winChart;
+var daily = false;
function applyRange() {
var app_name = document.getElementById('app_name').dataset.name;
@@ -6,7 +7,7 @@ function applyRange() {
var $end = $("#range-end input");
var start = moment($start.val(), 'YYYY-MM-DD HH:mm:ss', true);
var end = moment($end.val(), 'YYYY-MM-DD HH:mm:ss', true);
-
+ daily = start < moment().add(-7, 'd')
if (start > end){
var tmp = start;
start = end;
@@ -79,15 +80,22 @@ function makePlatformGraph(chartName, chartDataName, data, platform){
.useInteractiveGuideline(true)
.showControls(false);
chart.interactiveLayer.tooltip.headerFormatter(function(d) {
- var top_limit = moment(d, 'MMMM DD hh:mm a').add(1, 'h');
- return d + ' - ' + top_limit.format('hh:mm A');
+ var top_limit, res;
+ if (daily) {
+ top_limit = moment(d, 'MMMM DD hh:mm a').add(1, 'd');
+ res = d.substr(0,6) + ' - ' + top_limit.format('MMM DD')
+ } else{
+ top_limit = moment(d, 'MMMM DD hh:mm a').add(1, 'h');
+ res = d + ' - ' + top_limit.format('hh:mm A');
+ }
+ return res;
});
chart.xAxis.showMaxMin(false)
.tickValues(hours.filter(function(d, i){
return !(i % tickSize);
}))
.tickFormat(function (d) {
- return d3.utcFormat('%b %d %I:%M %p')(new Date(d));
+ return daily ? d3.utcFormat('%b %d')(new Date(d)) : d3.utcFormat('%b %d %I:%M %p')(new Date(d));
});
chart.duration(1000);
@@ -103,10 +111,8 @@ function makePlatformGraph(chartName, chartDataName, data, platform){
}
function fillForm(data) {
- console.log(data);
if (Object.keys(data.win).length != 0) {
data = data.win;
- console.log(data);
} else if ((Object.keys(data.mac).length != 0)) {
data = data.mac;
} else {
@@ -114,7 +120,6 @@ function fillForm(data) {
}
var start = data[Object.keys(data)[0]][0][0];
var end = data[Object.keys(data)[0]].slice(-1)[0][0];
- console.log(start);
$("#range-end input").val(moment(end).utc().format('YYYY-MM-DD HH:mm:00'));
$("#range-start input").val(moment(start).utc().format('YYYY-MM-DD HH:mm:00'));
}
diff --git a/omaha_server/omaha/statistics.py b/omaha_server/omaha/statistics.py
index bb730de..c67eae8 100644
--- a/omaha_server/omaha/statistics.py
+++ b/omaha_server/omaha/statistics.py
@@ -54,60 +54,44 @@ def add_app_statistics(userid, platform, app, now=None):
version = app.get('version')
channel = parser.get_channel(app)
events = app.findall('event')
+ nextversion = app.get('nextversion')
+
err_events = filter(lambda x: x.get('eventresult') not in ['1', '2', '3'], events)
if err_events:
return
+
install_event = filter(lambda x: x.get('eventtype') == '2', events)
if is_new_install(appid, userid):
- if install_event and install_event[0].get('eventresult') in ['1', '2', '3']:
+ if install_event:
mark('new_install:%s' % appid, userid)
mark('new_install:{}:{}'.format(appid, platform), userid)
redis.setbit("known_users:%s" % appid, userid, 1)
+ mark('request:{}:{}'.format(appid, nextversion), userid, track_hourly=True)
+ mark('request:{}:{}:{}'.format(appid, platform, nextversion), userid, track_hourly=True)
+ mark('request:{}:{}'.format(appid, channel), userid)
+ return
+
elif userid not in MonthEvents('new_install:{}:{}'.format(appid, platform), year=now.year, month=now.month):
mark('request:%s' % appid, userid)
mark('request:{}:{}'.format(appid, platform), userid)
+ if nextversion:
+ mark('request:{}:{}'.format(appid, nextversion), userid, track_hourly=True)
+ mark('request:{}:{}:{}'.format(appid, platform, nextversion), userid, track_hourly=True)
uninstall_event = filter(lambda x: x.get('eventtype') == '4', events)
- if uninstall_event and uninstall_event[0].get('eventresult') in ['1', '2', '3']:
+ if uninstall_event:
mark('uninstall:%s' % appid, userid)
mark('uninstall:{}:{}'.format(appid, platform), userid)
-
- mark('request:{}:{}'.format(appid, version), userid)
- mark('request:{}:{}'.format(appid, channel), userid)
- mark('request:{}:{}:{}'.format(appid, platform, version), userid)
-
-
-def update_live_statistics(userid, apps_list, platform, now=None):
- id = get_id(userid)
- list(map(partial(add_app_live_statistics, id, platform, now=now), apps_list or []))
-
-
-def add_app_live_statistics(userid, platform, app, now=None):
- mark = partial(mark_event, now=now, track_hourly=True)
- unmark = partial(unmark_event, track_hourly=True)
- appid = app.get('appid')
- version = app.get('version')
- events = app.findall('event')
- nextversion = app.get('nextversion')
-
- install_event = filter(lambda x: x.get('eventtype') == '2', events)
- if install_event and install_event[0].get('eventresult') in ['1', '2', '3']:
- mark('online:{}:{}'.format(appid, nextversion), userid)
- mark('online:{}:{}:{}'.format(appid, platform, nextversion), userid)
- return
-
update_event = filter(lambda x: x.get('eventtype') == '3', events)
- if update_event and update_event[0].get('eventresult') in ['1', '2', '3']:
- unmark('online:{}:{}'.format(appid, version), userid) # necessary for
- unmark('online:{}:{}:{}'.format(appid, platform, version), userid) # 1 hour interval
- mark('online:{}:{}'.format(appid, nextversion), userid)
- mark('online:{}:{}:{}'.format(appid, platform, nextversion), userid)
- return
-
- # updatecheck handling
- if version:
- mark('online:{}:{}'.format(appid, version), userid)
- mark('online:{}:{}:{}'.format(appid, platform, version), userid)
+ if update_event:
+ unmark_event('request:{}:{}'.format(appid, version), userid, track_hourly=True)
+ unmark_event('request:{}:{}:{}'.format(appid, platform, version), userid, track_hourly=True)
+ mark('request:{}:{}'.format(appid, nextversion), userid, track_hourly=True)
+ mark('request:{}:{}:{}'.format(appid, platform, nextversion), userid, track_hourly=True)
+ else:
+ mark('request:{}:{}'.format(appid, version), userid, track_hourly=True)
+ mark('request:{}:{}:{}'.format(appid, platform, version), userid, track_hourly=True)
+ mark('request:{}:{}'.format(appid, channel), userid)
def get_users_statistics_months(app_id, platform=None, year=None, start=1, end=12):
@@ -193,10 +177,10 @@ def get_users_versions(app_id, date=None):
-def get_versions_data_by_platform(app_id, end, n_hours, versions, platform, tz='UTC'):
+def get_hourly_data_by_platform(app_id, end, n_hours, versions, platform, tz='UTC'):
tzinfo = pytz.timezone(tz)
start = end - timezone.timedelta(hours=n_hours)
- event_name = "online:{}:{}:{}"
+ event_name = "request:{}:{}:{}"
hours = [datetime(start.year, start.month, start.day, start.hour, tzinfo=pytz.UTC)
+ timezone.timedelta(hours=x) for x in range(1, n_hours + 1)]
@@ -209,16 +193,32 @@ def get_versions_data_by_platform(app_id, end, n_hours, versions, platform, tz='
return dict(data)
+def get_daily_data_by_platform(app_id, end, n_days, versions, platform):
+ start = end - timezone.timedelta(days=n_days)
+ event_name = "request:{}:{}:{}"
+
+ days = [start + timezone.timedelta(days=x) for x in range(0, n_days+1)]
+ data = [(v, [[day.strftime("%Y-%m-%dT00:%M:%S.%fZ"), len(DayEvents.from_date(event_name.format(app_id, platform, v), day))]
+ for day in days])
+ for v in versions]
+ data = filter(lambda version_data: sum([data[1] for data in version_data[1]]), data)
+ return dict(data)
+
+
def get_users_live_versions(app_id, start, end, tz='UTC'):
win_versions = [str(v.version) for v in Version.objects.filter_by_enabled(app__id=app_id)]
mac_versions = [str(v.short_version) for v in SparkleVersion.objects.filter_by_enabled(app__id=app_id)]
- tmp_hours = divmod((end - start).total_seconds(), 60*60)
- n_hours = tmp_hours[0]+1
- n_hours = int(n_hours)
-
- win_data = get_versions_data_by_platform(app_id, end, n_hours, win_versions, 'win', tz=tz)
- mac_data = get_versions_data_by_platform(app_id, end, n_hours, mac_versions, 'mac', tz=tz)
+ if start < timezone.now() - timedelta(days=7):
+ n_days = (end-start).days
+ win_data = get_daily_data_by_platform(app_id, end, n_days, win_versions, 'win')
+ mac_data = get_daily_data_by_platform(app_id, end, n_days, mac_versions, 'mac')
+ else:
+ tmp_hours = divmod((end - start).total_seconds(), 60*60)
+ n_hours = tmp_hours[0]+1
+ n_hours = int(n_hours)
+ win_data = get_hourly_data_by_platform(app_id, end, n_hours, win_versions, 'win', tz=tz)
+ mac_data = get_hourly_data_by_platform(app_id, end, n_hours, mac_versions, 'mac', tz=tz)
data = dict(win=win_data, mac=mac_data)
@@ -303,7 +303,6 @@ def collect_statistics(request, ip=None):
if userid:
userid_counting(userid, apps, request.os.get('platform'))
- update_live_statistics(userid, apps, request.os.get('platform'))
if not filter(lambda app: bool(app.findall('event')), apps):
return
diff --git a/omaha_server/omaha/templates/admin/omaha/live_statistics.html b/omaha_server/omaha/templates/admin/omaha/live_statistics.html
index d57b74f..5660f5b 100644
--- a/omaha_server/omaha/templates/admin/omaha/live_statistics.html
+++ b/omaha_server/omaha/templates/admin/omaha/live_statistics.html
@@ -51,9 +51,9 @@
format: 'yyyy-MM-dd hh:mm:00',
pickSeconds: false,
startDate: function () {
- var d = new Date();
- d.setDate(d.getDate() - 7);
- return d;
+ var d = moment();
+ d.subtract(6, 'M');
+ return new Date(d);
}(),
endDate: new Date()
});
diff --git a/omaha_server/omaha/tests/test_api.py b/omaha_server/omaha/tests/test_api.py
index 35a33b3..6bbde07 100644
--- a/omaha_server/omaha/tests/test_api.py
+++ b/omaha_server/omaha/tests/test_api.py
@@ -322,15 +322,14 @@ class LiveStatistics(APITestCase):
maxDiff = None
def _generate_fake_statistics(self):
- # now = datetime(2016, 2, 13)
date = datetime(2016, 2, 13, 0)
for i in range(self.n_hours):
for id in range(0, i):
- mark_event('online:app:win:2.0.0.0', id, now=date, track_hourly=True)
- mark_event('online:app:mac:4.0.0.1', id, now=date, track_hourly=True)
+ mark_event('request:app:win:2.0.0.0', id, now=date, track_hourly=True)
+ mark_event('request:app:mac:4.0.0.1', id, now=date, track_hourly=True)
for id in range(i, self.n_hours):
- mark_event('online:app:win:1.0.0.0', id, now=date, track_hourly=True)
- mark_event('online:app:mac:3.0.0.0', id, now=date, track_hourly=True)
+ mark_event('request:app:win:1.0.0.0', id, now=date, track_hourly=True)
+ mark_event('request:app:mac:3.0.0.0', id, now=date, track_hourly=True)
date += timedelta(hours=1)
def setUp(self):
@@ -384,9 +383,13 @@ class LiveStatistics(APITestCase):
for (i, hour)in enumerate(hours)])]
self.mac_statistics.append(('4.0.0.1', [[hour.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), i]
for (i, hour)in enumerate(hours)]))
-
- self.data = dict(data=dict(win=dict(self.win_statistics),
- mac=dict(self.mac_statistics)))
+ self.data = {}
+ self.data['hourly'] = dict(data=dict(win=dict(self.win_statistics),
+ mac=dict(self.mac_statistics)))
+ self.data['daily'] = dict(data=dict(win={'1.0.0.0': [['2016-02-13T00:00:00.000000Z', 36], ['2016-02-14T00:00:00.000000Z', 12]],
+ '2.0.0.0': [['2016-02-13T00:00:00.000000Z', 23], ['2016-02-14T00:00:00.000000Z', 35]]},
+ mac={'4.0.0.1': [['2016-02-13T00:00:00.000000Z', 23], ['2016-02-14T00:00:00.000000Z', 35]],
+ '3.0.0.0': [['2016-02-13T00:00:00.000000Z', 36], ['2016-02-14T00:00:00.000000Z', 12]]}))
@is_private()
def test_unauthorized(self):
@@ -394,15 +397,27 @@ class LiveStatistics(APITestCase):
response = client.get(reverse('api-statistics-live', args=('app',)), format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
+ @freeze_time("2016-02-16")
@is_private()
- def test_list(self):
+ def test_hourly_list(self):
+ start = datetime(2016, 2, 13, 0)
+ end = start + timedelta(hours=self.n_hours-1)
+ response = self.client.get(reverse('api-statistics-live', args=('app',)),
+ dict(start=start.isoformat(), end=end.isoformat()),
+ format='json')
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertDictEqual(StatisticsMonthsSerializer(self.data['hourly']).data, response.data)
+
+ @freeze_time("2016-03-16")
+ @is_private()
+ def test_daily_list(self):
start = datetime(2016, 2, 13, 0)
end = start + timedelta(hours=self.n_hours-1)
response = self.client.get(reverse('api-statistics-live', args=('app',)),
dict(start=start.isoformat(), end=end.isoformat()),
format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertDictEqual(StatisticsMonthsSerializer(self.data).data, response.data)
+ self.assertDictEqual(StatisticsMonthsSerializer(self.data['daily']).data, response.data)
class StatisticsMonthsMixin(object):
diff --git a/omaha_server/omaha/tests/test_statistics.py b/omaha_server/omaha/tests/test_statistics.py
index bff2b98..ea1f5f5 100644
--- a/omaha_server/omaha/tests/test_statistics.py
+++ b/omaha_server/omaha/tests/test_statistics.py
@@ -35,7 +35,6 @@ from omaha.parser import parse_request
from omaha.statistics import (
userid_counting,
add_app_statistics,
- add_app_live_statistics,
is_user_active,
get_kwargs_for_model,
parse_os,
@@ -44,7 +43,6 @@ from omaha.statistics import (
parse_apps,
parse_events,
collect_statistics,
- update_live_statistics,
get_users_statistics_months,
get_channel_statistics,
get_users_versions,
@@ -124,11 +122,11 @@ class StatisticsTest(TestCase):
userid = 1
channel = DEFAULT_CHANNEL
platform = 'win'
- app_kwargs = dict(appid='{F97917B1-20AB-48C1-9802-CEF305B10804}', version='30.0.123.1234')
+ app_kwargs = dict(appid='{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}', nextversion='0.0.0.1')
success_app = create_app_xml(events=fixtures.event_install_success, **app_kwargs)
error_app = create_app_xml(events=fixtures.event_install_error, **app_kwargs)
appid = app_kwargs.get('appid')
- version = app_kwargs.get('version')
+ version = app_kwargs.get('nextversion')
events_request_appid = lambda date=now: DayEvents.from_date('request:%s' % appid, date)
events_new_appid = lambda date=now: DayEvents.from_date('new_install:%s' % appid, date)
@@ -138,7 +136,6 @@ class StatisticsTest(TestCase):
events_request_appid_channel = lambda date=now: DayEvents.from_date('request:{}:{}'.format(appid, channel), date)
events_request_appid_platform_version = lambda date=now: DayEvents.from_date('request:{}:{}:{}'.format(appid, platform, version), date)
-
self.assertEqual(len(events_new_appid()), 0)
self.assertEqual(len(events_request_appid()), 0)
self.assertEqual(len(events_request_appid_version()), 0)
@@ -201,31 +198,6 @@ class StatisticsTest(TestCase):
self.assertIn(userid, events_request_appid(next_month))
self.assertIn(userid, events_request_appid_platform(next_month))
- def test_add_app_live_statistics(self):
- request = parse_request(fixtures.request_update_check)
- app = request.findall('app')[0]
-
- now = datetime.utcnow()
- userid = 1
- platform = 'win'
-
- appid = app.get('appid')
- version = app.get('version')
-
- events_appid_version = HourEvents('online:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
- events_appid_platform_version = HourEvents('online:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
-
- self.assertEqual(len(events_appid_version), 0)
- self.assertEqual(len(events_appid_platform_version), 0)
-
- add_app_live_statistics(userid, platform, app)
-
- self.assertEqual(len(events_appid_version), 1)
- self.assertEqual(len(events_appid_platform_version), 1)
-
- self.assertIn(userid, events_appid_version)
- self.assertIn(userid, events_appid_platform_version)
-
def test_is_user_active(self):
userid = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
id = get_id(userid)
@@ -393,7 +365,7 @@ class StatisticsTest(TestCase):
for e in events:
self.assertIn(e, app_req.events.all())
- def test_update_live_statistics_install(self):
+ def test_live_statistics_install(self):
request = parse_request(fixtures.request_event_install_success)
apps = request.findall('app')
app = apps[0]
@@ -406,46 +378,35 @@ class StatisticsTest(TestCase):
version_1 = '0.0.0.1'
version_2 = '0.0.0.2'
- events_appid_version_1 = HourEvents('online:{}:{}'.format(appid, version_1), now.year, now.month, now.day, now.hour)
- events_appid_platform_version_1 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_1), now.year, now.month, now.day, now.hour)
-
- self.assertEqual(len(events_appid_version_1), 0)
- self.assertEqual(len(events_appid_platform_version_1), 0)
+ events_appid_version = lambda version: HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
+ events_appid_platform_version = lambda version: HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
- update_live_statistics(userid, apps, platform)
+ self.assertEqual(len(events_appid_version(version_1)), 0)
+ self.assertEqual(len(events_appid_platform_version(version_1)), 0)
+ userid_counting(userid, apps, platform)
- self.assertEqual(len(events_appid_version_1), 1)
- self.assertEqual(len(events_appid_platform_version_1), 1)
+ self.assertEqual(len(events_appid_version(version_1)), 1)
+ self.assertEqual(len(events_appid_platform_version(version_1)), 1)
request = parse_request(fixtures.request_event_update_success)
apps = request.findall('app')
- update_live_statistics(userid, apps, platform)
+ userid_counting(userid, apps, platform)
- events_appid_version_1 = HourEvents('online:{}:{}'.format(appid, version_1), now.year, now.month, now.day, now.hour)
- events_appid_platform_version_1 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_1), now.year, now.month, now.day, now.hour)
- events_appid_version_2 = HourEvents('online:{}:{}'.format(appid, version_2), now.year, now.month, now.day, now.hour)
- events_appid_platform_version_2 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_2), now.year, now.month, now.day, now.hour)
-
- self.assertEqual(len(events_appid_version_1), 0)
- self.assertEqual(len(events_appid_platform_version_1), 0)
- self.assertEqual(len(events_appid_version_2), 1)
- self.assertEqual(len(events_appid_platform_version_2), 1)
+ self.assertEqual(len(events_appid_version(version_1)), 0)
+ self.assertEqual(len(events_appid_platform_version(version_1)), 0)
+ self.assertEqual(len(events_appid_version(version_2)), 1)
+ self.assertEqual(len(events_appid_platform_version(version_2)), 1)
request = parse_request(fixtures.request_event_uninstall_success)
apps = request.findall('app')
- update_live_statistics(userid, apps, platform)
-
- events_appid_version_2 = HourEvents('online:{}:{}'.format(appid, version_2),
- now.year, now.month, now.day, now.hour)
- events_appid_platform_version_2 = HourEvents('online:{}:{}:{}'.format(appid, platform, version_2),
- now.year, now.month, now.day, now.hour)
+ userid_counting(userid, apps, platform)
- self.assertEqual(len(events_appid_version_2), 1)
- self.assertEqual(len(events_appid_platform_version_2), 1)
+ self.assertEqual(len(events_appid_version(version_2)), 1)
+ self.assertEqual(len(events_appid_platform_version(version_2)), 1)
- def test_update_live_statistics_updatecheck(self):
+ def test_live_statistics_updatecheck(self):
request = parse_request(fixtures.request_update_check)
apps = request.findall('app')
app = apps[0]
@@ -457,13 +418,13 @@ class StatisticsTest(TestCase):
appid = app.get('appid')
version = app.get('version')
- events_appid_version = HourEvents('online:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
- events_appid_platform_version = HourEvents('online:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
+ events_appid_version = HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
+ events_appid_platform_version = HourEvents('request:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
self.assertEqual(len(events_appid_version), 0)
self.assertEqual(len(events_appid_platform_version), 0)
- update_live_statistics(userid, apps, platform)
+ userid_counting(userid, apps, platform)
self.assertEqual(len(events_appid_version), 1)
self.assertEqual(len(events_appid_platform_version), 1)
diff --git a/omaha_server/sparkle/statistics.py b/omaha_server/sparkle/statistics.py
index debabc2..5072a75 100644
--- a/omaha_server/sparkle/statistics.py
+++ b/omaha_server/sparkle/statistics.py
@@ -37,14 +37,6 @@ def collect_statistics(request, appid, channel):
tag=channel)
userid_counting(deviceID, app, 'mac')
- update_live_statistics(deviceID, appid, version)
-
-
-def update_live_statistics(userid, appid, version, now=None):
- userid = get_id(userid)
- mark = partial(mark_event, now=now, track_hourly=True)
- mark('online:{}:{}'.format(appid, version), userid)
- mark('online:{}:{}:{}'.format(appid, 'mac', version), userid)
def userid_counting(userid, app, platform, now=None):
@@ -69,6 +61,6 @@ def add_app_statistics(userid, platform, app, now=None):
mark('request:%s' % appid, userid)
mark('request:{}:{}'.format(appid, platform), userid)
- mark('request:{}:{}'.format(appid, version), userid)
+ mark('request:{}:{}'.format(appid, version), userid, track_hourly=True)
mark('request:{}:{}'.format(appid, channel), userid)
- mark('request:{}:{}:{}'.format(appid, platform, version), userid) \ No newline at end of file
+ mark('request:{}:{}:{}'.format(appid, platform, version), userid, track_hourly=True) \ No newline at end of file
diff --git a/omaha_server/sparkle/tests/test_statistics.py b/omaha_server/sparkle/tests/test_statistics.py
index efd017d..18febb8 100644
--- a/omaha_server/sparkle/tests/test_statistics.py
+++ b/omaha_server/sparkle/tests/test_statistics.py
@@ -27,8 +27,7 @@ from bitmapist import DayEvents, HourEvents
from freezegun import freeze_time
from omaha.utils import get_id
-from sparkle.statistics import update_live_statistics, collect_statistics
-from sparkle.statistics import add_app_statistics
+from sparkle.statistics import add_app_statistics, userid_counting
redis = get_redis_connection('statistics')
@@ -121,47 +120,34 @@ class StatisticsTest(TestCase):
appid = '{F97917B1-19AB-48C1-9802-CEF305B10804}'
version = '0.0.0.1'
+ test_app = dict(appid=appid, version=version)
+ platform = 'mac'
- request_version_events = HourEvents('online:{}:{}'.format(appid, version))
- request_platform_version_events = HourEvents('online:{}:{}:{}'.format(appid, 'mac', version))
+ request_version_events = HourEvents('request:{}:{}'.format(appid, version))
+ request_platform_version_events = HourEvents('request:{}:{}:{}'.format(appid, 'mac', version))
self.assertFalse(user1_id in request_version_events)
self.assertEqual(len(request_version_events), 0)
self.assertFalse(user1_id in request_platform_version_events)
self.assertEqual(len(request_platform_version_events), 0)
- update_live_statistics(userid1, appid, version)
+ userid_counting(userid1, test_app, platform)
self.assertTrue(user1_id in request_version_events)
self.assertEqual(len(request_version_events), 1)
self.assertTrue(user1_id in request_platform_version_events)
self.assertEqual(len(request_platform_version_events), 1)
- update_live_statistics(userid1, appid, version)
+ userid_counting(userid1, test_app, platform)
self.assertTrue(user1_id in request_version_events)
self.assertEqual(len(request_version_events), 1)
self.assertTrue(user1_id in request_platform_version_events)
self.assertEqual(len(request_platform_version_events), 1)
- update_live_statistics(userid2, appid, version)
+ userid_counting(userid2, test_app, platform)
self.assertTrue(user2_id in request_version_events)
self.assertEqual(len(request_version_events), 2)
self.assertTrue(user2_id in request_platform_version_events)
self.assertEqual(len(request_platform_version_events), 2)
-
- @mock.patch('sparkle.statistics.update_live_statistics')
- def test_collect_statistics(self, mock_update_live_statistics):
- app_id = '00000000-0000-0000-0000-000000000001'
- app_name = "Sparrow"
- channel = "test"
- version = "0.0.0.1"
- deviceID = "A37152BF-A3CB-5FEC-8230-FACF43BDCDDD"
- request = RequestFactory().get('/sparkle/%s/%s/appcast.xml?appVersionShort=%s&deviceID=%s' %
- (app_name, channel, version, deviceID))
-
- collect_statistics(request, app_id, channel)
-
- mock_update_live_statistics.assert_called_with(deviceID, app_id, version)
-