/soc/2012/sanket/www-statscollector: b73f1fbe465a: Use week inst...
sanket
sanket at soc.pidgin.im
Tue Aug 7 15:04:00 EDT 2012
Changeset: b73f1fbe465a215deff1eb2df5ad31cfe24259b7
Author: sanket <sanket at soc.pidgin.im>
Date: 2012-08-07 12:02 +0530
Branch: default
URL: http://hg.pidgin.im/soc/2012/sanket/www-statscollector/rev/b73f1fbe465a
Description:
Use week instead of open-range
This commit lays out the ``week'' based range format
for the UI. I had also completely forgot to put the
actual query filters according to date (and also ensure
that in a django framework they create SQL queries
INSTEAD of loading into memory). That task is also complete
with this commit.
diffstat:
pidgin_stats_collector/display/views.py | 179 ++++++----
pidgin_stats_collector/media/js/stats.js | 35 +-
pidgin_stats_collector/templates/display/index.html | 69 +---
pidgin_stats_collector/templates/display/plugins-detail.html | 105 +------
4 files changed, 157 insertions(+), 231 deletions(-)
diffs (truncated from 551 to 300 lines):
diff --git a/pidgin_stats_collector/display/views.py b/pidgin_stats_collector/display/views.py
--- a/pidgin_stats_collector/display/views.py
+++ b/pidgin_stats_collector/display/views.py
@@ -100,17 +100,12 @@ def process_stats(from_date, to_date):
stats_plugin = stats_dict[PLUGIN_STR]
stats_ui = stats_dict[UI_STR]
- #for o in \\
- # RawXML.objects.filter(timestamp__gte = from_date, timestamp__lt = to_date):
-
- # Process each element to get stats
-
- #stats_str = o.stats_xml.read()
- #stats_dom = etree.fromstring(stats_str)
-
# Start with cpuinfo
- os_name_dict = Info.objects.values('os_name').\
- annotate(Count('os_name'))
+ os_name_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('os_name') \
+ .annotate(Count('os_name'))
for item in os_name_dict:
stats_os_name[item['os_name']]['y'] = \
@@ -120,51 +115,85 @@ def process_stats(from_date, to_date):
win_v_cat = stats_os_name['windows']['drilldown']['categories']
win_v_dat = stats_os_name['windows']['drilldown']['data']
- win_dict = Info.objects.filter(os_name='windows').\
- values('os_sub_name').annotate(Count('os_sub_name'))
+ print 'Dates ....'
+ print from_date, to_date
+
+ win_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .filter(os_name='windows') \
+ .values('os_sub_name').annotate(Count('os_sub_name'))
for item in win_dict:
win_v_dat[win_v_cat.index(WIN_CAT[item['os_sub_name']])] = item['os_sub_name__count']
# Apple specific info
- apple_dict = Info.objects.filter(os_name='apple').\
- values('os_sub_name').annotate(Count('os_sub_name'))
+ apple_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .filter(os_name='apple') \
+ .values('os_sub_name').annotate(Count('os_sub_name'))
for item in apple_dict:
stats_os_name['apple']['drilldown']['dict'][item['os_sub_name']] = \
item['os_sub_name__count']
# The bitness of the application
- app_bit_dict = Info.objects.values('app_bit').\
- annotate(Count('app_bit'))
+ app_bit_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('app_bit') \
+ .annotate(Count('app_bit'))
+
for app_bit in app_bit_dict:
stats_app_bit[app_bit['app_bit']] = app_bit['app_bit__count']
# The bitness of the kernel
- os_bit_dict = Info.objects.values('os_bit').\
- annotate(Count('os_bit'))
+ os_bit_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('os_bit') \
+ .annotate(Count('os_bit'))
+
for os_bit in os_bit_dict:
stats_os_bit[os_bit['os_bit']] = os_bit['os_bit__count']
# Type of architecture we are dealing with
- arch_dict = Info.objects.values('arch_id').\
- annotate(Count('arch_id'))
+ arch_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('arch_id') \
+ .annotate(Count('arch_id'))
+
for item in arch_dict:
stats_arch_name[item['arch_id']] = item['arch_id__count']
# Version of libpurple installation
- purple_version_dict = Info.objects.values('purple_version').\
- annotate(Count('purple_version')).\
- order_by('-purple_version__count')
+ purple_version_dict = Info.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('purple_version') \
+ .annotate(Count('purple_version')) \
+ .order_by('-purple_version__count')
+
for item in purple_version_dict:
stats_prpl_v[item['purple_version']] = \
item['purple_version__count']
# IM Services used (protocol plugins) and avg users
- account_count_dict = Account.objects.values('prpl_name').\
- annotate(Count('prpl_name')).order_by('-prpl_name__count')
- account_avg_dict = Account.objects.values('prpl_name').\
- annotate(Avg('buddies')).order_by('-buddies__avg')
+ account_f = Account.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date)
+
+ account_count_dict = account_f \
+ .values('prpl_name') \
+ .annotate(Count('prpl_name')) \
+ .order_by('-prpl_name__count')
+
+ account_avg_dict = account_f \
+ .values('prpl_name') \
+ .annotate(Avg('buddies')) \
+ .order_by('-buddies__avg')
for item in account_count_dict:
stats_prpl_p[item['prpl_name']] = {}
@@ -175,46 +204,58 @@ def process_stats(from_date, to_date):
# IM user Jabber split up
- jabber_service_dict = Account.objects.filter(prpl_name='prpl-jabber').\
- values('service').annotate(Count('service')).order_by('-service__count')
+ jabber_service_dict = account_f \
+ .filter(prpl_name='prpl-jabber') \
+ .values('service').annotate(Count('service')) \
+ .order_by('-service__count')
- stats_prpl_p['prpl-jabber']['drilldown'] = {}
- stats_prpl_p['prpl-jabber']['drilldown']['name'] = 'Jabber Services'
- stats_prpl_p['prpl-jabber']['drilldown']['categories'] = []
- stats_prpl_p['prpl-jabber']['drilldown']['data'] = []
+ if 'prpl-jabber' in stats_prpl_p:
+ stats_prpl_p['prpl-jabber']['drilldown'] = {}
+ stats_prpl_p['prpl-jabber']['drilldown']['name'] = 'Jabber Services'
+ stats_prpl_p['prpl-jabber']['drilldown']['categories'] = []
+ stats_prpl_p['prpl-jabber']['drilldown']['data'] = []
- for item in jabber_service_dict:
- stats_prpl_p['prpl-jabber']['drilldown']['categories'].append(item['service'])
- stats_prpl_p['prpl-jabber']['drilldown']['data'].append(item['service__count'])
+ for item in jabber_service_dict:
+ stats_prpl_p['prpl-jabber']['drilldown']['categories'].append(item['service'])
+ stats_prpl_p['prpl-jabber']['drilldown']['data'].append(item['service__count'])
- if 'prpl-irc' not in stats_prpl_p: stats_prpl_p['prpl-irc'] = {}
- stats_prpl_p['prpl-irc']['drilldown'] = {}
- stats_prpl_p['prpl-irc']['drilldown']['name'] = 'IRC servers'
- stats_prpl_p['prpl-irc']['drilldown']['categories'] = []
- stats_prpl_p['prpl-irc']['drilldown']['data'] = []
- irc_service_dict = Account.objects.filter(prpl_name='prpl-irc').\
- values('service').annotate(Count('service')).order_by('-service__count')
+ if 'prpl-irc' in stats_prpl_p:
+ stats_prpl_p['prpl-irc']['drilldown'] = {}
+ stats_prpl_p['prpl-irc']['drilldown']['name'] = 'IRC servers'
+ stats_prpl_p['prpl-irc']['drilldown']['categories'] = []
+ stats_prpl_p['prpl-irc']['drilldown']['data'] = []
- for item in irc_service_dict:
- stats_prpl_p['prpl-irc']['drilldown']['categories'].append(item['service'])
- stats_prpl_p['prpl-irc']['drilldown']['data'].append(item['service__count'])
+ irc_service_dict = account_f \
+ .filter(prpl_name='prpl-irc') \
+ .values('service').annotate(Count('service')) \
+ .order_by('-service__count')
+
+ for item in irc_service_dict:
+ stats_prpl_p['prpl-irc']['drilldown']['categories'].append(item['service'])
+ stats_prpl_p['prpl-irc']['drilldown']['data'].append(item['service__count'])
# Plugins (3rd party/loadable-unloadable)
- plugin_count_dict = Plugin.objects.values('p_id').\
+ plugin_count_dict = Plugin.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('p_id').\
annotate(Count('p_id')).order_by('-p_id__count')
for item in plugin_count_dict:
stats_plugin[item['p_id']] = item['p_id__count']
# UI info
- ui_dict = UI.objects.values('ui_id').\
- annotate(Count('ui_id')).order_by('-ui_id__count')
+ ui_dict = UI.objects \
+ .filter(raw_xml__timestamp__gte=from_date) \
+ .filter(raw_xml__timestamp__lt=to_date) \
+ .values('ui_id') \
+ .annotate(Count('ui_id')).order_by('-ui_id__count')
for item in ui_dict:
stats_ui[item['ui_id']] = item['ui_id__count']
- print stats_ui
+ #print stats_ui
return stats_dict
@@ -254,39 +295,29 @@ def process_date(get_dict):
""" Try to guess from and to parameters of date """
- req_param = ['from_day','from_month', 'from_year', 'to_day', 'to_month',\
- 'to_year']
- from_day, from_month, from_year = -1, -1, -1
- to_day, to_month, to_year = -1, -1, -1
- from_date, to_date = None, None
- delta_one_day = datetime.timedelta(days=1)
+ print 'Guessing date ...'
+ req_param = ['year','week']
# Default from and to dates
- today = datetime.datetime.now()
- from_date = datetime.datetime(today.year, today.month, today.day)
-
- to_date = from_date + delta_one_day
-
for p in req_param:
if p not in get_dict:
- return from_date, to_date
+ return None, None
try:
- from_day = int(get_dict['from_day'])
- from_month = int(get_dict['from_month'])
- from_year = int(get_dict['from_year'])
- to_day = int(get_dict['to_day'])
- to_month = int(get_dict['to_month'])
- to_year = int(get_dict['to_year'])
+ year = int(get_dict['year'])
+ week = int(get_dict['week'])
- from_date = datetime.datetime(from_year, from_month, from_day)
- to_date = datetime.datetime(to_year, to_month, to_day)
+ from_date = \
+ datetime.datetime(year, 1, 1) + datetime.timedelta(days=(1+(week-1)*7))
+ to_date = from_date + datetime.timedelta(days=7)
- except: # if this fails, sorry GET request, ain't no good!
- return form_date, to_date
+ print 'Date: ', from_date, to_date
- return [from_date, to_date + delta_one_day]
+ return [from_date, to_date]
+
+ except Exception: # if this fails, sorry GET request, ain't no good!
+ return datetime.datetime(2012, 1, 1), datetime.datetime(2012, 12, 31)
def index(request):
@@ -324,8 +355,6 @@ def index(request):
simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR], cut=10)[0]),
'plugin_dat_top': \
simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR], cut=10)[1]),
- 'plugin_cat': simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR])[0]),
- 'plugin_dat': simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR])[1]),
'ui_cat': simplejson.dumps(sorted_dict(stats_dict[UI_STR])[0]),
'ui_dat': simplejson.dumps(sorted_dict(stats_dict[UI_STR])[1])
});
diff --git a/pidgin_stats_collector/media/js/stats.js b/pidgin_stats_collector/media/js/stats.js
--- a/pidgin_stats_collector/media/js/stats.js
+++ b/pidgin_stats_collector/media/js/stats.js
@@ -1,9 +1,36 @@
$(document).ready(function() {
- $("#plugins-modal-button").click(function (e) {
- $("#plugins-detail-modal").modal();
+ /* Set the selected year and week
+ * according to the GET parameters
+ */
- return false;
- });
+ var queries = {};
+ $.each(document.location.search.substr(1).split('&'),function(c,q){
+ var i = q.split('=');
+ queries[i[0].toString()] = i[1].toString();
+ });
+
+ /* Week selector */
+ var set=false;
+ for(var i=1;i<=52;i++){
+ if(i.toString() == queries['week']){
+ set=true;
+ $('#week-select').append('<option selected="true">'+i+'</option>');
More information about the Commits
mailing list