/soc/2012/sanket/www-statscollector: dd4df2a828da: Sort protocol...

Sanket Agarwal sanket at soc.pidgin.im
Tue Jul 10 02:13:35 EDT 2012


Changeset: dd4df2a828da2e58273cb916edbe672680876687
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-07-10 11:43 +0530
Branch:	 default
URL: http://hg.pidgin.im/soc/2012/sanket/www-statscollector/rev/dd4df2a828da

Description:

Sort protocols list

diffstat:

 pidgin_stats_collector/display/views.py |  20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diffs (65 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
@@ -97,8 +97,6 @@
   stats_prpl_p_u = stats_dict[PRPL_P_U_STR]
   stats_plugin = stats_dict[PLUGIN_STR]
 
-  print 'Dates', from_date, to_date
-
   for o in \
     RawXML.objects.filter(timestamp__gte = from_date, timestamp__lt = to_date):
 
@@ -208,12 +206,16 @@
 
   return stats_dict
 
-def sorted_dict(d, cut=None):
+def sorted_dict(d, f=None, 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])
+  if f:
+    print l[0]
+    l = sorted(l, key=lambda x: f(x))
+  else:
+    l = sorted(l, key=lambda x: -x[1])
 
   k_arr, d_arr = [[i[0] for i in l], [i[1] for i in l]]
 
@@ -225,14 +227,12 @@
     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()
-  print 'STATS DICT', stats_dict
 
   return render_to_response('display/plugins-detail.html',{
       'plugin_cat': simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR])[0]),
@@ -305,14 +305,14 @@
       'arch_pie': simplejson.dumps(list(stats_dict[ARCH_NAME_STR].iteritems())),
       '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]),
-      'purple_p_cat': simplejson.dumps(stats_dict[PRPL_P_STR].keys()),
-      'purple_p_dat': simplejson.dumps(stats_dict[PRPL_P_STR].values()),
+      'purple_p_cat': simplejson.dumps(sorted_dict(stats_dict[PRPL_P_STR], f=lambda x: -x[1]['y'])[0]),
+      'purple_p_dat': simplejson.dumps(sorted_dict(stats_dict[PRPL_P_STR], f=lambda x: -x[1]['y'])[1]),
       'purple_p_u_cat': simplejson.dumps(sorted_dict(stats_dict[PRPL_P_U_STR])[0]),
       'purple_p_u_dat': simplejson.dumps(sorted_dict(stats_dict[PRPL_P_U_STR])[1]),
       'plugin_cat_top': \
-          simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR], 10)[0]),
+          simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR], cut=10)[0]),
       'plugin_dat_top': \
-          simplejson.dumps(sorted_dict(stats_dict[PLUGIN_STR], 10)[1]),
+          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]),
 



More information about the Commits mailing list