[1530] | 1 | ## Script (Python) "getRegStatistics" |
---|
| 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 1277 2007-01-11 21:11:37Z joachim $ |
---|
| 11 | """ |
---|
| 12 | return Student Statistics |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
[1596] | 15 | logger = logging.getLogger('Skins.getRegStatistics') |
---|
[1530] | 16 | |
---|
| 17 | try: |
---|
| 18 | from Products.AdvancedQuery import Eq, Between, Le,In, Ge |
---|
| 19 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 20 | students_catalog = context.students_catalog |
---|
| 21 | except: |
---|
| 22 | evalAdvancedQuery = None |
---|
[1596] | 23 | logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember()) |
---|
[1530] | 24 | l = [] |
---|
| 25 | if not context.isStaff(): |
---|
| 26 | return l |
---|
| 27 | dep = {} |
---|
| 28 | |
---|
| 29 | dep['id'] = "All Faculties" |
---|
| 30 | |
---|
| 31 | total = float(len(students_catalog)) |
---|
| 32 | |
---|
| 33 | dep['total'] = "%.0f" % total |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | #from Products.zdb import set_trace;set_trace() |
---|
| 37 | |
---|
| 38 | sfp_res = context.portal_catalog(review_state ='school_fee_paid') |
---|
| 39 | sfp_ids = [r.getId for r in sfp_res] |
---|
| 40 | sfp = len(sfp_res) |
---|
| 41 | dep['school_fee_paid'] = sfp |
---|
| 42 | dep['school_fee_paid_percent'] = "%.0f" % round(sfp*100/total) |
---|
| 43 | |
---|
| 44 | creg_res = context.portal_catalog(review_state ='courses_registered') |
---|
| 45 | creg_ids = [r.getId for r in creg_res] |
---|
| 46 | creg = len(creg_res) |
---|
| 47 | dep['courses_registered'] = creg |
---|
| 48 | dep['courses_registered_percent'] = "%.0f" % round(creg*100/total) |
---|
| 49 | |
---|
| 50 | cval_res = context.portal_catalog(review_state='courses_validated') |
---|
| 51 | cval_ids = [r.getId for r in cval_res] |
---|
| 52 | cval = len(cval_res) |
---|
| 53 | dep['courses_validated'] = cval |
---|
| 54 | dep['courses_validated_percent'] = "%.0f" % round(cval*100/total) |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | l.append(dep) |
---|
| 58 | fs = context.portal_catalog(portal_type="Faculty") |
---|
| 59 | for fid in [f.getId for f in fs]: |
---|
| 60 | dep = {} |
---|
| 61 | dep['id'] = fid |
---|
| 62 | #fquery = Eq('faculty',fid) |
---|
| 63 | fac_res = students_catalog(faculty = fid) |
---|
| 64 | fac_ids = [r.id for r in fac_res] |
---|
| 65 | total = float(len(fac_res)) |
---|
| 66 | |
---|
| 67 | if total == 0: |
---|
| 68 | continue |
---|
| 69 | |
---|
| 70 | dep['total'] = "%.0f" % total |
---|
| 71 | |
---|
| 72 | sfp = len([s for s in fac_ids if s in sfp_ids]) |
---|
| 73 | dep['school_fee_paid'] = sfp |
---|
| 74 | dep['school_fee_paid_percent'] = 0 |
---|
| 75 | if total: |
---|
| 76 | dep['school_fee_paid_percent'] = "%.0f" % round(sfp*100/total) |
---|
| 77 | |
---|
| 78 | creg = len([s for s in fac_ids if s in creg_ids]) |
---|
| 79 | dep['courses_registered'] = creg |
---|
| 80 | dep['courses_registered_percent'] = 0 |
---|
| 81 | if total: |
---|
| 82 | dep['courses_registered_percent'] = "%.0f" % round(creg*100/total) |
---|
[1596] | 83 | |
---|
[1530] | 84 | cval = len([s for s in fac_ids if s in cval_ids]) |
---|
| 85 | dep['courses_validated'] = cval |
---|
| 86 | dep['courses_validated_percent'] = 0 |
---|
| 87 | if total: |
---|
| 88 | dep['courses_validated_percent'] = "%.0f" % round(cval*100/total) |
---|
| 89 | |
---|
| 90 | l.append(dep) |
---|
| 91 | |
---|
| 92 | return l |
---|
| 93 | |
---|