## Script (Python) "getNewStudentStatistics" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: getStudentStatistics.py 1277 2007-01-11 21:11:37Z joachim $ """ return Student Statistics """ import logging logger = logging.getLogger('Student.Statistics') try: from Products.AdvancedQuery import Eq, Between, Le,In, Ge aq_portal = context.portal_catalog.evalAdvancedQuery aq_students = context.students_catalog.evalAdvancedQuery except: evalAdvancedQuery = None logger.info('"%s","invoked new statistics"' % context.portal_membership.getAuthenticatedMember()) l = [] if not context.isStaff(): return l dep = {} dep['id'] = "All Faculties" umequery = Eq('level','100') #dequery = Eq('entry_mode','DE') # only correct for 2006/2007 #total_new = aq_students(umequery or dequery) total_new = aq_students(umequery) total_new = float(len(total_new)) dep['new'] = "%.0f" % total_new #from Products.zdb import set_trace;set_trace() adm_res = context.portal_catalog(review_state ='admitted') adm_ids = [r.getId for r in adm_res] adm = len(adm_res) dep['admitted'] = adm dep['admitted_percent'] = "%.0f" % round(adm*100/total_new) 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'] = "%.0f" % round(cpe*100/total_new) 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'] = "%.0f" % round(cr*100/total_new) 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'] = "%.0f" % round(cav*100/total_new) 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'] = "%.0f" % round(ora*100/total_new) l.append(dep) fs = context.portal_catalog(portal_type="Faculty") for fid in [f.getId for f in fs]: dep = {} dep['id'] = fid fquery = Eq('faculty',fid) #umequery = Eq('level','100') #fac_res = aq_students(fquery & umequery & dequery) fac_res = aq_students(fquery & umequery) fac_ids = [r.id for r in fac_res] total = float(len(fac_res)) #if total == 0: # continue dep['new'] = "%.0f" % total adm = len([s for s in fac_ids if s in adm_ids]) dep['admitted'] = adm dep['admitted_percent'] = 0 if total: dep['admitted_percent'] = "%.0f" % round(adm*100/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'] = "%.0f" % round(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'] = "%.0f" % round(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'] = "%.0f" % round(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'] = "%.0f" % round(ora*100/total) if total == 0: continue l.append(dep) return l