## Script (Python) "getNewStudentStatistics" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: getNewStudentStatistics_old.py 1670 2007-04-05 10:06:59Z joachim $ """ return Student Statistics """ import logging logger = logging.getLogger('Skins.getNewStudentStatistics') try: from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp 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 Faculties" freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE')) total_new = aq_students(freshquery) total_new = float(len(total_new)) ##newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*') ##total_new = aq_portal(newquery) ##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) total_sfp = total_new - (cav + cr + cpe + adm + ora) dep['rest'] = int(total_sfp) dep['rest_percent'] = "%.0f" % round(total_sfp*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) fac_res = aq_students(fquery & freshquery) 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) rest = int(total - (cav + cr + cpe + adm + ora)) dep['rest'] = rest dep['rest_percent'] = "%.0f" % round(rest*100/total) l.append(dep) return l