/soc/2012/sanket/www-statscollector: b76235d1906d: Add User Inte...

sanket sanket at soc.pidgin.im
Sun Aug 5 05:46:04 EDT 2012


Changeset: b76235d1906d513e76251cf7c8441893c43f75b7
Author:	 sanket <sanket at soc.pidgin.im>
Date:	 2012-08-04 02:37 +0530
Branch:	 default
URL: http://hg.pidgin.im/soc/2012/sanket/www-statscollector/rev/b76235d1906d

Description:

Add User Interface chart

UI's can be basically Finch/Pidgin (as of supported by Pidgin's package)
and if possible some custom clients such as InstantBird or even Adium *if*
we manage to make our plugin work on that :-)!

diffstat:

 pidgin_stats_collector/display/views.py             |  177 ++++----
 pidgin_stats_collector/media/js/charts.js           |  384 ++++++++++----------
 pidgin_stats_collector/statscollector/constants.py  |    3 +
 pidgin_stats_collector/templates/display/index.html |    8 +-
 4 files changed, 296 insertions(+), 276 deletions(-)

diffs (truncated from 680 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
@@ -73,6 +73,8 @@ def init_stats_dict():
   stats_d[PRPL_P_U_STR] = {}
   # Plugins
   stats_d[PLUGIN_STR] = {}
+  # UI's
+  stats_d[UI_STR] = {}
   return stats_d
 
 def process_stats(from_date, to_date):
@@ -96,113 +98,123 @@ def process_stats(from_date, to_date):
   stats_prpl_p = stats_dict[PRPL_P_STR]
   stats_prpl_p_u = stats_dict[PRPL_P_U_STR]
   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):
+  #for o in \\
+  #  RawXML.objects.filter(timestamp__gte = from_date, timestamp__lt = to_date):
 
-    # Process each element to get stats
+  # Process each element to get stats
 
-    stats_str = o.stats_xml.read()
-    stats_dom = etree.fromstring(stats_str)
+  #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'))
+  # Start with cpuinfo
+  os_name_dict = Info.objects.values('os_name').\
+      annotate(Count('os_name'))
 
-    for item in os_name_dict:
-      stats_os_name[item['os_name']]['y'] = \
-          item['os_name__count']
+  for item in os_name_dict:
+    stats_os_name[item['os_name']]['y'] = \
+        item['os_name__count']
 
-    # Windows specific info
-    win_v_cat = stats_os_name['windows']['drilldown']['categories']
-    win_v_dat = stats_os_name['windows']['drilldown']['data']
+  # Windows specific info
+  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'))
+  win_dict = Info.objects.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']
+  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 specific info
+  apple_dict = Info.objects.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']
+  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'))
-    for app_bit in app_bit_dict:
-      stats_app_bit[app_bit['app_bit']] = app_bit['app_bit__count']
+  # The bitness of the application
+  app_bit_dict = Info.objects.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'))
-    for os_bit in os_bit_dict:
-      stats_os_bit[os_bit['os_bit']] = os_bit['os_bit__count']
+  # The bitness of the kernel
+  os_bit_dict = Info.objects.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'))
-    for item in arch_dict:
-      stats_arch_name[item['arch_id']] = item['arch_id__count']
+  # Type of architecture we are dealing with
+  arch_dict = Info.objects.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')
-    for item in purple_version_dict:
-      stats_prpl_v[item['purple_version']] = \
-          item['purple_version__count']
+  # Version of libpurple installation
+  purple_version_dict = Info.objects.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')
+  # 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')
 
-    for item in account_count_dict:
-      stats_prpl_p[item['prpl_name']] = {}
-      stats_prpl_p[item['prpl_name']]['y'] = item['prpl_name__count']
+  for item in account_count_dict:
+    stats_prpl_p[item['prpl_name']] = {}
+    stats_prpl_p[item['prpl_name']]['y'] = item['prpl_name__count']
 
-    for item in account_avg_dict:
-      stats_prpl_p_u[item['prpl_name']] = item['buddies__avg']
+  for item in account_avg_dict:
+    stats_prpl_p_u[item['prpl_name']] = item['buddies__avg']
 
-    # IM user Jabber split up
+  # 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.objects.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'] = []
+  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'] = []
+  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')
+  irc_service_dict = Account.objects.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'])
+  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').\
-        annotate(Count('p_id')).order_by('-p_id__count')
+  # Plugins (3rd party/loadable-unloadable)
+  plugin_count_dict = Plugin.objects.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']
+  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')
+
+  for item in ui_dict:
+    stats_ui[item['ui_id']] = item['ui_id__count']
+
+  print stats_ui
 
   return stats_dict
 
@@ -314,5 +326,6 @@ def index(request):
           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/charts.js b/pidgin_stats_collector/media/js/charts.js
--- a/pidgin_stats_collector/media/js/charts.js
+++ b/pidgin_stats_collector/media/js/charts.js
@@ -47,220 +47,220 @@ function drawChart(cat, dat, e, title)
     var drilled_color = '#7D0000';
     var undirlled_color = '#666699';
     
-       $.each(dat, function(key){
-        		if(dat[key]['drilldown']){
-        			dat[key]['color'] = drilled_color;
-                }
-                else dat[key]['color'] = undirlled_color;
+   $.each(dat, function(key){
+            if(dat[key]['drilldown']){
+                dat[key]['color'] = drilled_color;
+            }
+            else dat[key]['color'] = undirlled_color;
+    });
+
+
+    var colors = Highcharts.getOptions().colors,
+        categories = cat,
+        name = title,
+        data = dat;
+
+
+    function setChart(name, categories, data, color) {
+        chart.xAxis[0].setCategories(categories);
+        chart.series[0].remove();
+        chart.addSeries({
+            name: name,
+            data: data,
+            color: color || undirlled_color
         });
- 
-    
-        var colors = Highcharts.getOptions().colors,
-            categories = cat,
-            name = title,
-            data = dat;
-        
-    
-        function setChart(name, categories, data, color) {
-            chart.xAxis[0].setCategories(categories);
-            chart.series[0].remove();
-            chart.addSeries({
-                name: name,
-                data: data,
-                color: color || undirlled_color
-            });
-        }
-    
-        chart = new Highcharts.Chart({
-            chart: {
-                renderTo: e,
-                type: 'column'
-            },
+    }
+
+    chart = new Highcharts.Chart({
+        chart: {
+            renderTo: e,
+            type: 'column'
+        },
+        title: {
+            text: title
+        },
+        xAxis: {
+            categories: categories
+        },
+        yAxis: {
             title: {
-                text: title
-            },
-            xAxis: {



More information about the Commits mailing list