scripts/stats.py
changeset 2148 0345046ed7a5
parent 2090 a07ff1e1bd1f
child 2151 f58515b0b2e1
--- a/scripts/stats.py	Fri Apr 10 15:45:52 2009 +0000
+++ b/scripts/stats.py	Fri Apr 10 15:46:05 2009 +0000
@@ -153,7 +153,7 @@
     print "%s: %d" % item
 
 
-def savePopularity(popularities):
+def saveValues(values, saver):
   """Saves the specified popularities.
   """
 
@@ -162,12 +162,12 @@
 
   from soc.models.organization import Organization
 
-  def txn(key_name, popularity):
-    org = Organization.get_by_key_name(key_name)
-    org.nr_applications = popularity
+  def txn(key, value):
+    org = Organization.get_by_key_name(key)
+    saver(org, value)
     org.put()
 
-  for key, value in sorted(popularities.iteritems()):
+  for key, value in sorted(values.iteritems()):
     print key
     db.run_in_transaction_custom_retries(10, txn, key, value)
 
@@ -233,12 +233,19 @@
   from soc.models.mentor import Mentor
   from soc.models.org_admin import OrgAdmin
 
+  def slot_saver(org, value):
+    org.slots = value
+  def pop_saver(org, value):
+    org.nr_applications = value
+  def raw_saver(org, value):
+    org.slots_calculated = value
+
   context = {
       'load': loadPickle,
       'dump': dumpPickle,
       'orgStats': orgStats,
       'printPopularity': printPopularity,
-      'savePopularity': savePopularity,
+      'saveValues': saveValues,
       'getOrgs': getEntities(Organization),
       'getUsers': getEntities(User),
       'getStudents': getEntities(Student),
@@ -252,6 +259,9 @@
       'Student': Student,
       'Mentor': Mentor,
       'OrgAdmin': OrgAdmin,
+      'slot_saver': slot_saver,
+      'pop_saver': pop_saver,
+      'raw_saver': raw_saver,
   }
 
   interactive.remote(args, context)