scripts/stats.py
changeset 2079 086c60aad3d8
parent 2063 319d9f05955a
child 2089 b8a9691da6e7
--- a/scripts/stats.py	Fri Apr 03 17:54:57 2009 +0000
+++ b/scripts/stats.py	Fri Apr 03 19:17:08 2009 +0000
@@ -23,6 +23,7 @@
 
 
 import cPickle
+import datetime
 import operator
 import sys
 
@@ -104,20 +105,29 @@
   it = dateFetch(gen, last)
 
   proposals = [(i.key().name(), i.toDict(key_order)) for i in it]
+  if proposals:
+    last = i.last_modified_on # last modified entity
+  else:
+    last = datetime.datetime.now()
 
-  return dict(proposals)
+  return dict(proposals), last
 
 
-def orgStats(target):
+def orgStats(target, orgs):
   """Retrieves org stats.
   """
 
   from soc.logic import dicts
 
+  orgs = [(v.key(), v) for k, v in orgs.iteritems()]
+  orgs = dict(orgs)
+
   grouped = dicts.groupby(target.values(), '_org')
-  popularity = [(k, len(v)) for k,v in grouped.iteritems()]
 
-  return grouped, dict(popularity)
+  grouped = [(orgs[k], v) for k, v in grouped.iteritems()]
+  popularity = [(k.link_id, len(v)) for k, v in grouped]
+
+  return dict(grouped), dict(popularity)
 
 
 def countStudentsWithProposals():