scripts/stats.py
changeset 2148 0345046ed7a5
parent 2090 a07ff1e1bd1f
child 2151 f58515b0b2e1
equal deleted inserted replaced
2147:5dd2091c8f0c 2148:0345046ed7a5
   151 
   151 
   152   for item in sorted(popularity.iteritems(), key=g, reverse=True):
   152   for item in sorted(popularity.iteritems(), key=g, reverse=True):
   153     print "%s: %d" % item
   153     print "%s: %d" % item
   154 
   154 
   155 
   155 
   156 def savePopularity(popularities):
   156 def saveValues(values, saver):
   157   """Saves the specified popularities.
   157   """Saves the specified popularities.
   158   """
   158   """
   159 
   159 
   160   import logging
   160   import logging
   161   from google.appengine.ext import db
   161   from google.appengine.ext import db
   162 
   162 
   163   from soc.models.organization import Organization
   163   from soc.models.organization import Organization
   164 
   164 
   165   def txn(key_name, popularity):
   165   def txn(key, value):
   166     org = Organization.get_by_key_name(key_name)
   166     org = Organization.get_by_key_name(key)
   167     org.nr_applications = popularity
   167     saver(org, value)
   168     org.put()
   168     org.put()
   169 
   169 
   170   for key, value in sorted(popularities.iteritems()):
   170   for key, value in sorted(values.iteritems()):
   171     print key
   171     print key
   172     db.run_in_transaction_custom_retries(10, txn, key, value)
   172     db.run_in_transaction_custom_retries(10, txn, key, value)
   173 
   173 
   174   print "done"
   174   print "done"
   175 
   175 
   231   from soc.models.user import User
   231   from soc.models.user import User
   232   from soc.models.student import Student
   232   from soc.models.student import Student
   233   from soc.models.mentor import Mentor
   233   from soc.models.mentor import Mentor
   234   from soc.models.org_admin import OrgAdmin
   234   from soc.models.org_admin import OrgAdmin
   235 
   235 
       
   236   def slot_saver(org, value):
       
   237     org.slots = value
       
   238   def pop_saver(org, value):
       
   239     org.nr_applications = value
       
   240   def raw_saver(org, value):
       
   241     org.slots_calculated = value
       
   242 
   236   context = {
   243   context = {
   237       'load': loadPickle,
   244       'load': loadPickle,
   238       'dump': dumpPickle,
   245       'dump': dumpPickle,
   239       'orgStats': orgStats,
   246       'orgStats': orgStats,
   240       'printPopularity': printPopularity,
   247       'printPopularity': printPopularity,
   241       'savePopularity': savePopularity,
   248       'saveValues': saveValues,
   242       'getOrgs': getEntities(Organization),
   249       'getOrgs': getEntities(Organization),
   243       'getUsers': getEntities(User),
   250       'getUsers': getEntities(User),
   244       'getStudents': getEntities(Student),
   251       'getStudents': getEntities(Student),
   245       'getMentors': getEntities(Mentor),
   252       'getMentors': getEntities(Mentor),
   246       'getOrgAdmins': getEntities(OrgAdmin),
   253       'getOrgAdmins': getEntities(OrgAdmin),
   250       'Organization': Organization,
   257       'Organization': Organization,
   251       'User': User,
   258       'User': User,
   252       'Student': Student,
   259       'Student': Student,
   253       'Mentor': Mentor,
   260       'Mentor': Mentor,
   254       'OrgAdmin': OrgAdmin,
   261       'OrgAdmin': OrgAdmin,
       
   262       'slot_saver': slot_saver,
       
   263       'pop_saver': pop_saver,
       
   264       'raw_saver': raw_saver,
   255   }
   265   }
   256 
   266 
   257   interactive.remote(args, context)
   267   interactive.remote(args, context)
   258 
   268 
   259 if __name__ == '__main__':
   269 if __name__ == '__main__':