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 1248 2007-01-09 05:36:35Z henrik $ |
---|
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 | #from Products.zdb import set_trace;set_trace() |
---|
24 | logger.info('"%s","invoked statistics"' % context.portal_membership.getAuthenticatedMember()) |
---|
25 | l = [] |
---|
26 | if not context.isStaff(): |
---|
27 | return l |
---|
28 | dep = {} |
---|
29 | dep['id'] = "All" |
---|
30 | total = len(context.students_catalog()) |
---|
31 | dep['students'] = total |
---|
32 | cpe_res = context.portal_catalog(review_state ='clearance_pin_entered') |
---|
33 | cpe_ids = [r.getId for r in cpe_res] |
---|
34 | cpe = len(cpe_res) |
---|
35 | dep['clearance_pin_entered'] = cpe |
---|
36 | dep['clearance_pin_entered_percent'] = (cpe*100/total) |
---|
37 | cr_res = context.portal_catalog(review_state='clearance_requested') |
---|
38 | cr_ids = [r.getId for r in cr_res] |
---|
39 | cr = len(cr_res) |
---|
40 | dep['clearance_requested'] = cr |
---|
41 | dep['clearance_requested_percent'] = (cr*100/total) |
---|
42 | cav_res = context.portal_catalog(review_state ='cleared_and_validated') |
---|
43 | cav_ids = [r.getId for r in cav_res] |
---|
44 | cav = len(cav_res) |
---|
45 | dep['cleared_and_validated'] = cav |
---|
46 | dep['cleared_and_validated_percent'] = (cav*100/total) |
---|
47 | or_res = context.portal_catalog(review_state='objection_raised') |
---|
48 | or_ids = [r.getId for r in or_res] |
---|
49 | ora = len(or_res) |
---|
50 | dep['objection_raised'] = ora |
---|
51 | dep['objection_raised_percent'] = (ora*100/total) |
---|
52 | l.append(dep) |
---|
53 | fs = context.portal_catalog(portal_type="Faculty") |
---|
54 | for fid in [f.getId for f in fs]: |
---|
55 | dep = {} |
---|
56 | dep['id'] = fid |
---|
57 | fquery = Eq('portal_type','Faculty') |
---|
58 | fac_res = context.students_catalog(faculty=fid) |
---|
59 | fac_ids = [r.id for r in fac_res] |
---|
60 | total = len(fac_res) |
---|
61 | if total == 0: |
---|
62 | continue |
---|
63 | dep['students'] = total |
---|
64 | cpe = len([s for s in fac_ids if s in cpe_ids]) |
---|
65 | dep['clearance_pin_entered'] = cpe |
---|
66 | dep['clearance_pin_entered_percent'] = 0 |
---|
67 | if total: |
---|
68 | dep['clearance_pin_entered_percent'] = (cpe*100/total) |
---|
69 | cr = len([s for s in fac_ids if s in cr_ids]) |
---|
70 | dep['clearance_requested'] = cr |
---|
71 | dep['clearance_requested_percent'] = 0 |
---|
72 | if total: |
---|
73 | dep['clearance_requested_percent'] = (cr*100/total) |
---|
74 | cav = len([s for s in fac_ids if s in cav_ids]) |
---|
75 | dep['cleared_and_validated'] = cav |
---|
76 | dep['cleared_and_validated_percent'] = 0 |
---|
77 | if total: |
---|
78 | dep['cleared_and_validated_percent'] = (cav*100/total) |
---|
79 | ora = len([s for s in fac_ids if s in or_ids]) |
---|
80 | dep['objection_raised'] = ora |
---|
81 | dep['objection_raised_percent'] = 0 |
---|
82 | if total: |
---|
83 | dep['objection_raised_percent'] = (ora*100/total) |
---|
84 | l.append(dep) |
---|
85 | return l |
---|