1 | ## Script (Python) "getStudentStatistics" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: getStudentStatistics.py 1251 2007-01-09 18:10:22Z joachim $ |
---|
11 | """ |
---|
12 | return Student Statistics |
---|
13 | """ |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Student.Statistics') |
---|
16 | |
---|
17 | try: |
---|
18 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
19 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
20 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
21 | except: |
---|
22 | evalAdvancedQuery = None |
---|
23 | logger.info('"%s","invoked statistics"' % context.portal_membership.getAuthenticatedMember()) |
---|
24 | l = [] |
---|
25 | if not context.isStaff(): |
---|
26 | return l |
---|
27 | dep = {} |
---|
28 | dep['id'] = "All" |
---|
29 | #total = len(context.students_catalog()) |
---|
30 | freshmen = aq_portal(Eq('portal_type','Student') \ |
---|
31 | & Le('created',context.ZopeTime("2006/12/20"))) |
---|
32 | total = len(freshmen) |
---|
33 | dep['students'] = total |
---|
34 | #from Products.zdb import set_trace;set_trace() |
---|
35 | cpe_res = context.portal_catalog(review_state ='clearance_pin_entered') |
---|
36 | cpe_ids = [r.getId for r in cpe_res] |
---|
37 | cpe = len(cpe_res) |
---|
38 | dep['clearance_pin_entered'] = cpe |
---|
39 | dep['clearance_pin_entered_percent'] = (cpe*100/total) |
---|
40 | cr_res = context.portal_catalog(review_state='clearance_requested') |
---|
41 | cr_ids = [r.getId for r in cr_res] |
---|
42 | cr = len(cr_res) |
---|
43 | dep['clearance_requested'] = cr |
---|
44 | dep['clearance_requested_percent'] = (cr*100/total) |
---|
45 | cav_res = context.portal_catalog(review_state ='cleared_and_validated') |
---|
46 | cav_ids = [r.getId for r in cav_res] |
---|
47 | cav = len(cav_res) |
---|
48 | dep['cleared_and_validated'] = cav |
---|
49 | dep['cleared_and_validated_percent'] = (cav*100/total) |
---|
50 | or_res = context.portal_catalog(review_state='objection_raised') |
---|
51 | or_ids = [r.getId for r in or_res] |
---|
52 | ora = len(or_res) |
---|
53 | dep['objection_raised'] = ora |
---|
54 | dep['objection_raised_percent'] = (ora*100/total) |
---|
55 | l.append(dep) |
---|
56 | fs = context.portal_catalog(portal_type="Faculty") |
---|
57 | for fid in [f.getId for f in fs]: |
---|
58 | dep = {} |
---|
59 | dep['id'] = fid |
---|
60 | fquery = Eq('portal_type','Faculty') |
---|
61 | fac_res = context.students_catalog(faculty=fid) |
---|
62 | fac_ids = [r.id for r in fac_res] |
---|
63 | total = len(fac_res) |
---|
64 | if total == 0: |
---|
65 | continue |
---|
66 | dep['students'] = total |
---|
67 | cpe = len([s for s in fac_ids if s in cpe_ids]) |
---|
68 | dep['clearance_pin_entered'] = cpe |
---|
69 | dep['clearance_pin_entered_percent'] = 0 |
---|
70 | if total: |
---|
71 | dep['clearance_pin_entered_percent'] = (cpe*100/total) |
---|
72 | cr = len([s for s in fac_ids if s in cr_ids]) |
---|
73 | dep['clearance_requested'] = cr |
---|
74 | dep['clearance_requested_percent'] = 0 |
---|
75 | if total: |
---|
76 | dep['clearance_requested_percent'] = (cr*100/total) |
---|
77 | cav = len([s for s in fac_ids if s in cav_ids]) |
---|
78 | dep['cleared_and_validated'] = cav |
---|
79 | dep['cleared_and_validated_percent'] = 0 |
---|
80 | if total: |
---|
81 | dep['cleared_and_validated_percent'] = (cav*100/total) |
---|
82 | ora = len([s for s in fac_ids if s in or_ids]) |
---|
83 | dep['objection_raised'] = ora |
---|
84 | dep['objection_raised_percent'] = 0 |
---|
85 | if total: |
---|
86 | dep['objection_raised_percent'] = (ora*100/total) |
---|
87 | l.append(dep) |
---|
88 | return l |
---|