/soc/2012/sanket/www-statscollector: 1939ac09d48e: Update bulk c...
sanket
sanket at sanketagarwal.com
Fri Jun 15 12:35:43 EDT 2012
Changeset: 1939ac09d48ec5e0817d4c2d05fea6f699c57327
Author: sanket <sanket at sanketagarwal.com>
Date: 2012-06-15 09:23 +0530
Branch: default
URL: http://hg.pidgin.im/soc/2012/sanket/www-statscollector/rev/1939ac09d48e
Description:
Update bulk changes
diffstat:
pidgin_stats_collector/display/views.py | 232 +++-
pidgin_stats_collector/media/css/code.css | 164 ++
pidgin_stats_collector/media/css/pidgin-trac.css | 72 +
pidgin_stats_collector/media/css/stats.css | 10 +
pidgin_stats_collector/media/css/style.css | 366 +++++
pidgin_stats_collector/media/css/trac.css | 575 ++++++++
pidgin_stats_collector/media/css/wiki.css | 44 +
pidgin_stats_collector/media/img/__utm.gif | Bin
pidgin_stats_collector/media/img/dots.gif | Bin
pidgin_stats_collector/media/img/extlink.gif | Bin
pidgin_stats_collector/media/img/footer_fade_repeat.jpg | Bin
pidgin_stats_collector/media/img/header.png | Bin
pidgin_stats_collector/media/img/header_fade_repeat.jpg | Bin
pidgin_stats_collector/media/img/pidgin_in_header.jpg | Bin
pidgin_stats_collector/media/img/pidgin_logo.jpg | Bin
pidgin_stats_collector/media/img/topbar_gradient.png | Bin
pidgin_stats_collector/media/img/topbar_gradient2.png | Bin
pidgin_stats_collector/media/img/trac_logo_mini.png | Bin
pidgin_stats_collector/media/js/ga.js | 61 +
pidgin_stats_collector/media/js/search.js | 59 +
pidgin_stats_collector/media/js/simplemodal.js | 712 +++++++++++
pidgin_stats_collector/media/js/stats.js | 9 +
pidgin_stats_collector/media/js/trac.js | 75 +
pidgin_stats_collector/templates/display/index.html | 479 ++++++-
pidgin_stats_collector/templates/display/plugins-detail.html | 197 +++
pidgin_stats_collector/urls.py | 4 +-
26 files changed, 2998 insertions(+), 61 deletions(-)
diffs (truncated from 3689 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
@@ -24,7 +24,7 @@
# Major OS name
OS_NAME_STR = 'os-name'
-OS_NAME = ('linux', 'windows', 'mac', 'unknown')
+OS_NAME = ('linux', 'windows', 'apple', 'unknown')
# Types of architectures
ARCH_NAME_STR = 'arch-name'
@@ -34,6 +34,22 @@
PRPL_V_STR = 'purple-version'
PRPL_V = ('unknown',)
+# Purple protocols information
+PRPL_P_STR = 'purple-protocols'
+PRPL_P_U_STR = 'purple-users-protocol'
+PRPL_P = ('prpl-msn','prpl-yahoo', 'prpl-gtalk', 'prpl-jabber', 'prpl-facebook-xmpp', 'prpl-irc', 'unknown',)
+
+# Loadable/User plugins
+PLUGIN_STR = 'plugins'
+PLUGIN = ('unknown',)
+
+# Categories of Windows Installations
+WIN_CAT = {"6.1":"Windows 7", "6.0":"Windows Vista", "unknown":"unknown", \
+ "5.2":"Windows Server 2003", "5.1":"Windows XP", "5.0":"Windows 2000"}
+
+# Color List, useful for rendering column's/graphs with varying colors
+COLOR_LIST = ('#7D0000','#006699', '#669900', '#996600', '#4C801A',\
+ '#006B6B','#660066')
def init_stats_dict():
@@ -52,7 +68,28 @@
stats_d = {}
# OS-NAME
- stats_d[OS_NAME_STR] = dict(zip(OS_NAME, [0]*len(OS_NAME)))
+ stats_d[OS_NAME_STR] = {}
+ for os_name in OS_NAME:
+ stats_d[OS_NAME_STR][os_name] = \
+ {'y':0, 'color': COLOR_LIST[OS_NAME.index(os_name)]}
+
+ stats_os_name = stats_d[OS_NAME_STR]
+
+ # Windows subcategorization
+ stats_os_name['windows']['drilldown'] = {}
+ stats_os_name['windows']['drilldown']['name'] = 'Windows-Versions'
+ stats_os_name['windows']['drilldown']['categories'] = WIN_CAT.values()
+ stats_os_name['windows']['drilldown']['data'] = [0]*len(WIN_CAT.values())
+ stats_os_name['windows']['drilldown']['color'] = \
+ COLOR_LIST[OS_NAME.index('windows')]
+
+ # Apple subcategorization
+ stats_os_name['apple']['drilldown'] = {}
+ stats_os_name['apple']['drilldown']['name'] = 'Apple-Versions'
+ stats_os_name['apple']['drilldown']['dict'] = {'unknown':0}
+ stats_os_name['apple']['drilldown']['color'] = \
+ COLOR_LIST[OS_NAME.index('apple')]
+
# App bitness
stats_d[APP_BIT_STR] = dict(zip(APP_BIT, [0]*len(APP_BIT)))
@@ -66,9 +103,18 @@
# Purple Version
stats_d[PRPL_V_STR] = dict(zip(PRPL_V, [0]*len(PRPL_V)))
+ # Purple Protocols
+ stats_d[PRPL_P_STR] = dict(zip(PRPL_P, [0]*len(PRPL_P)))
+
+ # Purple Protocols
+ stats_d[PRPL_P_U_STR] = dict(zip(PRPL_P, [0]*len(PRPL_P)))
+
+ # Plugins
+ stats_d[PLUGIN_STR] = dict(zip(PLUGIN, [0]*len(PLUGIN)))
+
return stats_d
-def process_stats():
+def process_stats(from_date, to_date):
"""
Process the XML files (already verified as valid) and get all the
@@ -86,8 +132,14 @@
stats_os_bit = stats_dict[OS_BIT_STR]
stats_arch_name = stats_dict[ARCH_NAME_STR]
stats_prpl_v = stats_dict[PRPL_V_STR]
+ stats_prpl_p = stats_dict[PRPL_P_STR]
+ stats_prpl_p_u = stats_dict[PRPL_P_U_STR]
+ stats_plugin = stats_dict[PLUGIN_STR]
- for o in RawXML.objects.all():
+ print 'Dates', from_date, to_date
+
+ for o in \
+ RawXML.objects.filter(timestamp__gte = from_date, timestamp__lt = to_date):
# Process each element to get stats
@@ -104,9 +156,36 @@
os_name = e1.attrib['id'].lower()
- if os_name in stats_os_name.keys():
- stats_os_name[os_name] += 1
- else: stats_os_name['unkwown'] += 1
+ if os_name in stats_os_name:
+ stats_os_name[os_name]['y'] += 1
+ else: stats_os_name['unknown']['y'] += 1
+
+ if os_name == 'windows':
+
+ win_v_cat = stats_os_name[os_name]['drilldown']['categories']
+ win_v_dat = stats_os_name[os_name]['drilldown']['data']
+
+ win_major_v = e1.xpath("major-version")[0].text
+ win_minor_v = e1.xpath("minor-version")[0].text
+ win_v = "%s.%s" % (win_major_v, win_minor_v)
+
+ if win_v in WIN_CAT:
+ win_v_dat[win_v_cat.index(WIN_CAT[win_v])] += 1
+ else:
+ win_v_dat[win_v_cat.index('unknown')] += 1
+
+ elif os_name == 'apple':
+
+ print 'APPLE XXX'
+ apple_major_v = e1.xpath("major-version")[0].text
+ apple_minor_v = e1.xpath("minor-version")[0].text
+ apple_bug_v = e1.xpath("bug-fix-version")[0].text
+
+ apple_v = "%s.%s.%s" % (apple_major_v, apple_minor_v, apple_bug_v)
+
+ if apple_v not in stats_os_name['apple']['drilldown']['dict']:
+ stats_os_name['apple']['drilldown']['dict'][apple_v] = 1
+ else: stats_os_name['apple']['drilldown']['dict'][apple_v] += 1
# The bitness of the application
e2 = stats_dom.xpath('/stats/cpuinfo/cpu/app-bit')
@@ -114,7 +193,7 @@
if app_bit in stats_app_bit:
stats_app_bit[app_bit] += 1
- else: stats_app_bit['unknwon'] += 1
+ else: stats_app_bit['unknown'] += 1
# The bitness of the kernel
e2 = stats_dom.xpath('/stats/cpuinfo/cpu/os-bit')
@@ -122,7 +201,7 @@
if os_bit in stats_os_bit:
stats_os_bit[os_bit] += 1
- else: stats_os_bit['unknwon'] += 1
+ else: stats_os_bit['unknown'] += 1
# Type of architecture we are dealing with
e3 = stats_dom.xpath('/stats/cpuinfo/cpu/arch')[0]
@@ -160,22 +239,147 @@
else:
stats_prpl_v['unknown'] += 1
+ # IM Services used (protocol plugins) and avg users
+
+ prpl_plugins = stats_dom.xpath('/stats/accounts/account')
+
+ for prpl_plugin in prpl_plugins:
+
+ prpl_name = prpl_plugin.xpath('protocol')[0].text
+ prpl_count=0
+ try:
+ prpl_count = int(prpl_plugin.xpath('buddies')[0].text.strip())
+ except: prpl_count = 0
+
+ if prpl_name in stats_prpl_p:
+ stats_prpl_p[prpl_name] += 1
+ stats_prpl_p_u[prpl_name] += prpl_count
+ else: stats_prpl_p['unknown'] += 1
+
+ # Loadable/User plugins
+
+ plugins = stats_dom.xpath('/stats/plugins/plugin')
+
+ for plugin in plugins:
+
+ plugin_name = plugin.attrib['id'].lower()
+
+ if plugin_name in stats_plugin.keys():
+ stats_plugin[plugin_name] += 1
+ else: stats_plugin[plugin_name] = 1
+
+ for prpl_name in stats_prpl_p_u.keys():
+ if prpl_name!='prpl-irc' and stats_prpl_p[prpl_name]>0:
+ stats_prpl_p_u[prpl_name] /= stats_prpl_p[prpl_name]
+
print stats_dict
return stats_dict
-def index(request):
+def sorted_dict(d, cut=None):
+
+ """ Returns the keys in order sorted by values, and values as a tuple """
+
+ l = [[k,v] for (k,v) in d.iteritems()]
+ l = sorted(l, key=lambda x: -x[1])
+
+ k_arr, d_arr = [[i[0] for i in l], [i[1] for i in l]]
+
+ if(cut):
+ k_arr = k_arr[:cut]
+ k_arr.append('other')
+
+ s = sum(d_arr[cut:])
+ d_arr = d_arr[:cut]
+ d_arr.append(s)
+
+ print k_arr, d_arr
+
+ return [k_arr, d_arr]
+
+def plugins_detail(request):
stats_dict = process_stats()
- stats_prpl_v = stats_dict[PRPL_V_STR]
+ return render_to_response('display/plugins-detail.html',{
+ 'plugin_cat': simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR])[0]),
+ 'plugin_dat': simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR])[1]),
+ });
+
+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)
+
+ # 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
+
+ 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'])
+
+ from_date = datetime.datetime(from_year, from_month, from_day)
+ to_date = datetime.datetime(to_year, to_month, to_day)
+
+ except: # if this fails, sorry GET request, ain't no good!
+ return form_date, to_date
+
+ return [from_date, to_date + delta_one_day]
+
+def index(request):
+
+ # Process what dates the user wants to see collated information for
+ # We expect information of the form from_day, from_month, from_year
+ # to_day, to_month, to_year. This way we can see all sort of variations
+
+ from_date, to_date = process_date(request.GET)
+
+ stats_dict = process_stats(from_date, to_date)
+
+ stats_os_name = stats_dict[OS_NAME_STR]
+
+ stats_os_name['apple']['drilldown']['categories'] = \
+ sorted_dict(stats_os_name['apple']['drilldown']['dict'])[0]
+
+ stats_os_name['apple']['drilldown']['data'] = \
+ sorted_dict(stats_os_name['apple']['drilldown']['dict'])[1]
return render_to_response('display/index.html',{
+ 'os_name_cat': simplejson.dumps(stats_dict[OS_NAME_STR].keys()),
+ 'os_name_dat': simplejson.dumps(stats_dict[OS_NAME_STR].values()),
'os_name': simplejson.dumps(list(stats_dict[OS_NAME_STR].iteritems())),
'app_bit': list(stats_dict[APP_BIT_STR].values()),
'os_bit': list(stats_dict[OS_BIT_STR].values()),
'arch_name': list(stats_dict[ARCH_NAME_STR].values()),
'arch_pie': simplejson.dumps(list(stats_dict[ARCH_NAME_STR].iteritems())),
- 'purple_v_cat': simplejson.dumps(stats_dict[PRPL_V_STR].keys()),
- 'purple_v_dat': simplejson.dumps\
- ({'name':'count', 'data':stats_dict[PRPL_V_STR].values()}),
+ 'purple_v_cat': simplejson.dumps(sorted_dict(stats_dict[PRPL_V_STR])[0]),
+ 'purple_v_dat': simplejson.dumps(sorted_dict(stats_dict[PRPL_V_STR])[1]),
More information about the Commits
mailing list