Changeset 1670 for WAeUP_SRP/trunk/skins
- Timestamp:
- 5 Apr 2007, 10:06:59 (18 years ago)
- Location:
- WAeUP_SRP/trunk/skins/waeup_student
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics.py
r1571 r1670 12 12 return Student Statistics 13 13 """ 14 try: 15 from Products.zdb import set_trace 16 except: 17 def set_trace(): 18 pass 14 19 import logging 15 20 logger = logging.getLogger('Skins.getNewStudentStatistics') 16 21 17 22 try: 18 from Products.AdvancedQuery import Eq, Between, Le,In, Ge 23 from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp 19 24 aq_portal = context.portal_catalog.evalAdvancedQuery 20 25 aq_students = context.students_catalog.evalAdvancedQuery 21 26 except: 22 27 evalAdvancedQuery = None 28 29 def intersect(m,n): 30 return [i for i in m if i in n] 31 23 32 logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember()) 24 l = []25 33 if not context.isStaff(): 26 34 return l 27 dep= {}35 total_dict = {} 28 36 29 dep['id'] = "All Faculties"37 total_dict['id'] = "All Faculties" 30 38 31 freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE')) 32 total_new = aq_students(freshquery) 33 total_new = float(len(total_new)) 34 dep['new'] = "%.0f" % total_new 35 36 37 #from Products.zdb import set_trace;set_trace() 38 39 adm_res = context.portal_catalog(review_state ='admitted') 40 adm_ids = [r.getId for r in adm_res] 41 adm = len(adm_res) 42 dep['admitted'] = adm 43 dep['admitted_percent'] = "%.0f" % round(adm*100/total_new) 44 45 cpe_res = context.portal_catalog(review_state ='clearance_pin_entered') 46 cpe_ids = [r.getId for r in cpe_res] 47 cpe = len(cpe_res) 48 dep['clearance_pin_entered'] = cpe 49 dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total_new) 50 51 cr_res = context.portal_catalog(review_state='clearance_requested') 52 cr_ids = [r.getId for r in cr_res] 53 cr = len(cr_res) 54 dep['clearance_requested'] = cr 55 dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total_new) 56 57 cav_res = context.portal_catalog(review_state ='cleared_and_validated') 58 cav_ids = [r.getId for r in cav_res] 59 cav = len(cav_res) 60 dep['cleared_and_validated'] = cav 61 dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total_new) 62 63 or_res = context.portal_catalog(review_state='objection_raised') 64 or_ids = [r.getId for r in or_res] 65 ora = len(or_res) 66 dep['objection_raised'] = ora 67 dep['objection_raised_percent'] = "%.0f" % round(ora*100/total_new) 68 69 total_sfp = total_new - (cav + cr + cpe + adm + ora) 70 dep['rest'] = int(total_sfp) 71 dep['rest_percent'] = "%.0f" % round(total_sfp*100/total_new) 72 73 74 l.append(dep) 75 fs = context.portal_catalog(portal_type="Faculty") 76 for fid in [f.getId for f in fs]: 77 dep = {} 78 dep['id'] = fid 79 fquery = Eq('faculty',fid) 80 fac_res = aq_students(fquery & freshquery) 81 fac_ids = [r.id for r in fac_res] 82 total = float(len(fac_res)) 83 84 if total == 0: 85 continue 86 87 dep['new'] = "%.0f" % total 88 89 adm = len([s for s in fac_ids if s in adm_ids]) 90 dep['admitted'] = adm 91 dep['admitted_percent'] = 0 92 if total: 93 dep['admitted_percent'] = "%.0f" % round(adm*100/total) 94 95 cpe = len([s for s in fac_ids if s in cpe_ids]) 96 dep['clearance_pin_entered'] = cpe 97 dep['clearance_pin_entered_percent'] = 0 98 if total: 99 dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total) 100 cr = len([s for s in fac_ids if s in cr_ids]) 101 dep['clearance_requested'] = cr 102 dep['clearance_requested_percent'] = 0 103 if total: 104 dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total) 105 cav = len([s for s in fac_ids if s in cav_ids]) 106 dep['cleared_and_validated'] = cav 107 dep['cleared_and_validated_percent'] = 0 108 if total: 109 dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total) 110 111 ora = len([s for s in fac_ids if s in or_ids]) 112 dep['objection_raised'] = ora 113 dep['objection_raised_percent'] = 0 114 if total: 115 dep['objection_raised_percent'] = "%.0f" % round(ora*100/total) 116 117 rest = int(total - (cav + cr + cpe + adm + ora)) 118 dep['rest'] = rest 119 dep['rest_percent'] = "%.0f" % round(rest*100/total) 120 121 l.append(dep) 39 ##freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE')) 40 ##total_new = aq_students(freshquery) 41 ##total_new = float(len(total_new)) 42 newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*') 43 total_res = aq_portal(newquery) 44 new_ids = [r.getPath().split('/')[-2] for r in total_res] 45 total_new = float(len(total_res)) 46 total_dict['new'] = "%.0f" % total_new 47 special_states = ('admitted', 48 'clearance_pin_entered', 49 'clearance_requested', 50 'cleared_and_validated', 51 'objection_raised', 52 ) 53 state_count = 0 54 state_ids = {} 55 for state in special_states: 56 res = context.portal_catalog(review_state = state) 57 ids = [r.getId for r in res] 58 state_ids[state] = ids 59 count = len(res) 60 state_count += count 61 total_dict[state] = count 62 total_dict['%s_percent' % state] = "%.0f" % round(count*100/total_new) 63 total_dict['rest'] = "%.0f" % (total_new - state_count) 64 total_dict['rest_percent'] = "%.0f" % round((total_new - state_count)*100/total_new) 65 fac_res = {} 66 #fac_res['total'] = total_dict 67 faculties = context.portal_catalog(portal_type="Faculty") 68 for f in faculties: 69 dict = {} 70 dict['id'] = f.getId 71 dict['title'] = f.Title 72 sid_in_faculty = [s.id for s in context.students_catalog(faculty=f.getId)] 73 new_in_faculty = intersect(new_ids,sid_in_faculty) 74 rest = len(new_in_faculty) 75 for state in special_states: 76 state_count = len(intersect(state_ids[state], new_in_faculty)) 77 rest -= state_count 78 dict[state] = state_count 79 dict['rest'] = rest 80 fac_res[f.getId] = dict 81 #set_trace() 82 ##for sid,review_state in new_ids: 83 ## scat_res = context.students_catalog(id = sid) 84 ## if not scat_res: 85 ## continue 86 ## student = scat_res[0] 87 ## faculty = student.faculty 88 ## if not fac_res.has_key(faculty): 89 ## continue 90 ## if review_state in special_states: 91 ## fac_res[faculty][review_state] = fac_res[faculty][review_state] + 1 92 ## else: 93 ## fac_res[faculty]['rest'] = fac_res[faculty]['rest'] + 1 94 l = [] 95 l.append(total_dict) 96 fac_ids = [f.getId for f in faculties] 97 fac_ids.sort() 98 for f in fac_ids: 99 sum = 0 100 for state in special_states: 101 sum += fac_res[f][state] 102 fac_res[f]['%s_percent' % state] = "%.0f" % round(fac_res[f][state]*100/total_new) 103 fac_res[f]['rest_percent'] = "%.0f" % round(fac_res[f]['rest']*100/total_new) 104 sum += fac_res[f]['rest'] 105 fac_res[f]['new'] = sum 106 l.append(fac_res[f]) 107 122 108 123 109 return l
Note: See TracChangeset for help on using the changeset viewer.