## Script (Python) "getStudentStatistics" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: getStudentStatistics.py 1196 2007-01-04 10:30:39Z henrik $ """ return Student Statistics """ import logging logger = logging.getLogger('Student.Statistic') try: from Products.AdvancedQuery import Eq, Between, Le,In aq_portal = context.portal_catalog.evalAdvancedQuery aq_students = context.students_catalog.evalAdvancedQuery except: evalAdvancedQuery = None logger.info('"%s","invoked statistics"' % context.portal_membership.getAuthenticatedMember()) l = [] if not context.isStaff(): return l dep = {} dep['id'] = "All" total = len(context.students_catalog()) dep['students'] = total cpe_res = context.portal_catalog(review_state ='clearance_pin_entered') cpe_ids = [r.getId for r in cpe_res] cpe = len(cpe_res) dep['clearance_pin_entered'] = cpe dep['clearance_pin_entered_percent'] = (cpe*100/total) cr_res = context.portal_catalog(review_state='clearance_requested') cr_ids = [r.getId for r in cr_res] cr = len(cr_res) dep['clearance_requested'] = cr dep['clearance_requested_percent'] = (cr*100/total) cav_res = context.portal_catalog(review_state ='cleared_and_validated') cav_ids = [r.getId for r in cav_res] cav = len(cav_res) dep['cleared_and_validated'] = cav dep['cleared_and_validated_percent'] = (cav*100/total) or_res = context.portal_catalog(review_state='objection_raised') or_ids = [r.getId for r in or_res] ora = len(or_res) dep['objection_raised'] = ora dep['objection_raised_percent'] = (ora*100/total) l.append(dep) fs = context.portal_catalog(portal_type="Faculty") #from Products.zdb import set_trace;set_trace() for fid in [f.getId for f in fs]: dep = {} dep['id'] = fid fquery = Eq('portal_type','Faculty') fac_res = context.students_catalog(faculty=fid) fac_ids = [r.id for r in fac_res] total = len(fac_res) if total == 0: continue dep['students'] = total cpe = len([s for s in fac_ids if s in cpe_ids]) dep['clearance_pin_entered'] = cpe dep['clearance_pin_entered_percent'] = 0 if total: dep['clearance_pin_entered_percent'] = (cpe*100/total) cr = len([s for s in fac_ids if s in cr_ids]) dep['clearance_requested'] = cr dep['clearance_requested_percent'] = 0 if total: dep['clearance_requested_percent'] = (cr*100/total) cav = len([s for s in fac_ids if s in cav_ids]) dep['cleared_and_validated'] = cav dep['cleared_and_validated_percent'] = 0 if total: dep['cleared_and_validated_percent'] = (cav*100/total) ora = len([s for s in fac_ids if s in or_ids]) dep['objection_raised'] = ora dep['objection_raised_percent'] = 0 if total: dep['objection_raised_percent'] = (ora*100/total) l.append(dep) return l