48 |
48 |
49 orgs = [(i.key().name(), i) for i in it] |
49 orgs = [(i.key().name(), i) for i in it] |
50 return dict(orgs) |
50 return dict(orgs) |
51 |
51 |
52 |
52 |
|
53 def getUsers(): |
|
54 """Returns all Users as dictionary. |
|
55 """ |
|
56 |
|
57 from soc.models.user import User |
|
58 |
|
59 gen = lambda: User.all() |
|
60 it = interactive.deepFetch(gen) |
|
61 |
|
62 users = [(i.key().name(), i) for i in it] |
|
63 return dict(users) |
|
64 |
|
65 |
|
66 def getStudents(): |
|
67 """Returns all Students as dictionary. |
|
68 """ |
|
69 |
|
70 from soc.models.student import Student |
|
71 |
|
72 gen = lambda: Student.all() |
|
73 it = interactive.deepFetch(gen) |
|
74 |
|
75 students = [(i.key().name(), i) for i in it] |
|
76 return dict(students) |
|
77 |
|
78 |
|
79 def getMentors(): |
|
80 """Returns all Mentors as dictionary. |
|
81 """ |
|
82 |
|
83 from soc.models.mentor import Mentor |
|
84 |
|
85 gen = lambda: Mentor.all() |
|
86 it = interactive.deepFetch(gen) |
|
87 |
|
88 mentors = [(i.key().name(), i) for i in it] |
|
89 return dict(mentors) |
|
90 |
|
91 |
|
92 def getOrgAdmins(): |
|
93 """Returns all Organization Administrators as dictionary. |
|
94 """ |
|
95 |
|
96 from soc.models.org_admin import OrgAdmin |
|
97 |
|
98 gen = lambda: OrgAdmin.all() |
|
99 it = interactive.deepFetch(gen) |
|
100 |
|
101 orgAdmins = [(i.key().name(), i) for i in it] |
|
102 return dict(orgAdmins) |
|
103 |
|
104 |
53 def getProps(): |
105 def getProps(): |
54 """Returns all proposals as a list of dictionaries. |
106 """Returns all proposals as a list of dictionaries. |
55 """ |
107 """ |
56 |
108 |
57 key_order = [ |
109 key_order = [ |
67 proposals = [i.toDict(key_order) for i in it] |
119 proposals = [i.toDict(key_order) for i in it] |
68 |
120 |
69 return proposals |
121 return proposals |
70 |
122 |
71 |
123 |
72 def orgstats(target): |
124 def getStudentProposals(): |
|
125 """Returns all Student Proposals as dictionary. |
|
126 """ |
|
127 |
|
128 from soc.models.student_proposal import StudentProposal |
|
129 |
|
130 gen = lambda: StudentProposal.all() |
|
131 it = interactive.deepFetch(gen) |
|
132 |
|
133 studentProposals = [(i.key().name(), i) for i in it] |
|
134 |
|
135 return dict(studentProposals) |
|
136 |
|
137 |
|
138 def orgStats(target): |
73 """Retrieves org stats. |
139 """Retrieves org stats. |
74 """ |
140 """ |
75 |
141 |
76 from soc.logic import dicts |
142 from soc.logic import dicts |
77 |
143 |
78 target = [addKey(i, 'org') for i in target] |
144 target = [addKey(i, 'org') for i in target] |
79 grouped = dicts.groupby(target, 'org_key') |
145 grouped = dicts.groupby(target, 'org_key') |
80 popularity = [(k, len(v)) for k,v in grouped.iteritems()] |
146 popularity = [(k, len(v)) for k,v in grouped.iteritems()] |
81 |
147 |
82 return grouped, dict(popularity) |
148 return grouped, dict(popularity) |
|
149 |
|
150 |
|
151 def countStudentsWithProposals(): |
|
152 """Retrieves number of Students who have submitted at least one Student Proposal. |
|
153 """ |
|
154 |
|
155 proposals = getStudentProposals() |
|
156 students = {} |
|
157 |
|
158 for proposal_key in proposals.keys(): |
|
159 students[proposals[proposal_key].scope_path] = True |
|
160 |
|
161 return len(students) |
83 |
162 |
84 |
163 |
85 def printPopularity(popularity): |
164 def printPopularity(popularity): |
86 """Prints the popularity for the specified proposals. |
165 """Prints the popularity for the specified proposals. |
87 """ |
166 """ |
136 interactive.setup() |
215 interactive.setup() |
137 |
216 |
138 context = { |
217 context = { |
139 'load': loadPickle, |
218 'load': loadPickle, |
140 'dump': dumpPickle, |
219 'dump': dumpPickle, |
141 'orgstats': orgstats, |
220 'orgStats': orgStats, |
142 'printPopularity': printPopularity, |
221 'printPopularity': printPopularity, |
143 'savePopularity': savePopularity, |
222 'savePopularity': savePopularity, |
144 'getOrgs': getOrgs, |
223 'getOrgs': getOrgs, |
145 'getProps': getProps, |
224 'getProps': getProps, |
|
225 'getStudents': getStudents, |
|
226 'getMentors': getMentors, |
|
227 'getOrgAdmins': getOrgAdmins, |
|
228 'getUsers': getUsers, |
|
229 'getStudentProposals': getStudentProposals, |
|
230 'countStudentsWithProposals': countStudentsWithProposals |
146 } |
231 } |
147 |
232 |
148 interactive.remote(args, context) |
233 interactive.remote(args, context) |
149 |
234 |
150 if __name__ == '__main__': |
235 if __name__ == '__main__': |