Add some additional functions for stats to stats.py script.
authorPawel Solyga <Pawel.Solyga@gmail.com>
Thu, 02 Apr 2009 15:31:36 +0000
changeset 2052 a723a2509e21
parent 2051 cecbef1289a5
child 2053 a614b9d4821e
Add some additional functions for stats to stats.py script. This included getStudents, getUsers, getMentors, getOrgAdmins, countStudentsWithProposals and some style fixes. Patch by: Pawel Solyga Reviewed by: to-be-reviewed
scripts/stats.py
--- a/scripts/stats.py	Thu Apr 02 10:11:38 2009 +0000
+++ b/scripts/stats.py	Thu Apr 02 15:31:36 2009 +0000
@@ -50,6 +50,58 @@
   return dict(orgs)
 
 
+def getUsers():
+  """Returns all Users as dictionary.
+  """
+
+  from soc.models.user import User
+
+  gen = lambda: User.all()
+  it = interactive.deepFetch(gen)
+
+  users = [(i.key().name(), i) for i in it]
+  return dict(users)
+
+
+def getStudents():
+  """Returns all Students as dictionary.
+  """
+
+  from soc.models.student import Student
+
+  gen = lambda: Student.all()
+  it = interactive.deepFetch(gen)
+
+  students = [(i.key().name(), i) for i in it]
+  return dict(students)
+
+
+def getMentors():
+  """Returns all Mentors as dictionary.
+  """
+
+  from soc.models.mentor import Mentor
+
+  gen = lambda: Mentor.all()
+  it = interactive.deepFetch(gen)
+
+  mentors = [(i.key().name(), i) for i in it]
+  return dict(mentors)
+
+
+def getOrgAdmins():
+  """Returns all Organization Administrators as dictionary.
+  """
+
+  from soc.models.org_admin import OrgAdmin
+
+  gen = lambda: OrgAdmin.all()
+  it = interactive.deepFetch(gen)
+
+  orgAdmins = [(i.key().name(), i) for i in it]
+  return dict(orgAdmins)
+
+
 def getProps():
   """Returns all proposals as a list of dictionaries.
   """
@@ -69,7 +121,21 @@
   return proposals
 
 
-def orgstats(target):
+def getStudentProposals():
+  """Returns all Student Proposals as dictionary.
+  """
+
+  from soc.models.student_proposal import StudentProposal
+
+  gen = lambda: StudentProposal.all()
+  it = interactive.deepFetch(gen)
+
+  studentProposals = [(i.key().name(), i) for i in it]
+  
+  return dict(studentProposals)
+
+
+def orgStats(target):
   """Retrieves org stats.
   """
 
@@ -82,6 +148,19 @@
   return grouped, dict(popularity)
 
 
+def countStudentsWithProposals():
+  """Retrieves number of Students who have submitted at least one Student Proposal.
+  """
+  
+  proposals = getStudentProposals()
+  students = {}
+  
+  for proposal_key in proposals.keys():
+    students[proposals[proposal_key].scope_path] = True
+  
+  return len(students)
+
+
 def printPopularity(popularity):
   """Prints the popularity for the specified proposals.
   """
@@ -138,11 +217,17 @@
   context = {
       'load': loadPickle,
       'dump': dumpPickle,
-      'orgstats': orgstats,
+      'orgStats': orgStats,
       'printPopularity': printPopularity,
       'savePopularity': savePopularity,
       'getOrgs': getOrgs,
       'getProps': getProps,
+      'getStudents': getStudents,
+      'getMentors': getMentors,
+      'getOrgAdmins': getOrgAdmins,
+      'getUsers': getUsers,
+      'getStudentProposals': getStudentProposals,
+      'countStudentsWithProposals': countStudentsWithProposals
   }
 
   interactive.remote(args, context)