# HG changeset patch # User Pawel Solyga # Date 1238686296 0 # Node ID a723a2509e216dc0889bb31ceb8c688c24a94a36 # Parent cecbef1289a5e78d1783a885fdc9f508013d0026 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 diff -r cecbef1289a5 -r a723a2509e21 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)