## Script (Python) "getRetStudentStatistics" ##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('Skins.getRetStudentStatistics') logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember()) if not context.isStaff(): return 'Not allowed' current_session = context.getSessionId()[0] range1 = range(94,100,1) range2 = range(0,int(current_session),1) missing_values = ['','-1'] entry_sessions = missing_values + [str(k) for k in range1+range2] + ['0'+str(k) for k in range2] #entry_sessions = ('','-1','94','95','96','97','98','99','00','01','02','03','04','05','06','07','0','1','2','3','4','5','6','7') ret_states = ('returning', 'school_fee_paid', 'courses_registered', 'courses_validated', ) full_time = ('ume_ft','de_ft','ug_ft','pg_ft') part_time = ( 'de_pt','ug_pt','pg_pt') diploma = ('dp_ft','dp_pt') faculties = context.portal_catalog(portal_type="Faculty") l = [] fac_res = {} dict = {} dict['id'] = 'All Faculties' dict['title'] = 'All Faculties' res_ft = context.students_catalog(entry_session = entry_sessions, mode = full_time, review_state = ret_states) dict['total_ft'] = len(res_ft) res_pt = context.students_catalog(entry_session = entry_sessions, mode = part_time, review_state = ret_states) dict['total_pt'] = len(res_pt) res_dp = context.students_catalog(entry_session = entry_sessions, mode = diploma, review_state = ret_states) dict['total_dp'] = len(res_dp) for state in ret_states: # full_time res_ft = context.students_catalog(entry_session = entry_sessions, review_state = state, mode = full_time, session = current_session) state_ft = state + '_ft' dict[state_ft] = len(res_ft) statepercent = state+'_ft_percent' if dict['total_ft'] > 0: dict[statepercent] = "%.0f" % round(dict[state_ft]*100.0/dict['total_ft']) else: dict[statepercent] = 0 # part_time res_pt = context.students_catalog(entry_session = entry_sessions, review_state = state, mode = part_time, session = current_session) state_pt = state + '_pt' dict[state_pt] = len(res_pt) statepercent = state+'_pt_percent' if dict['total_pt'] > 0: dict[statepercent] = "%.0f" % round(dict[state_pt]*100.0/dict['total_pt']) else: dict[statepercent] = 0 # diploma res_dp = context.students_catalog(entry_session = entry_sessions, review_state = state, mode = diploma, session = current_session) state_dp = state + '_dp' dict[state_dp] = len(res_dp) statepercent = state+'_dp_percent' if dict['total_dp'] > 0: dict[statepercent] = "%.0f" % round(dict[state_dp]*100.0/dict['total_dp']) else: dict[statepercent] = 0 l.append(dict) for f in faculties: dict = {} dict['id'] = f.getId dict['title'] = f.Title res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = full_time) dict['total_ft'] = len(res_ft) res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = part_time) dict['total_pt'] = len(res_pt) res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = diploma) dict['total_dp'] = len(res_dp) for state in ret_states: # full_time res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = full_time, session = current_session) state_ft = state + '_ft' dict[state_ft] = len(res_ft) statepercent = state+'_ft_percent' if dict['total_ft'] > 0: dict[statepercent] = "%.0f" % round(dict[state_ft]*100.0/dict['total_ft']) else: dict[statepercent] = 0 # part_time res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = part_time, session = current_session) state_pt = state + '_pt' dict[state_pt] = len(res_pt) statepercent = state+'_pt_percent' if dict['total_pt'] > 0: dict[statepercent] = "%.0f" % round(dict[state_pt]*100.0/dict['total_pt']) else: dict[statepercent] = 0 # diploma res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = diploma, session = current_session) state_dp = state + '_dp' dict[state_dp] = len(res_dp) statepercent = state+'_dp_percent' if dict['total_dp'] > 0: dict[statepercent] = "%.0f" % round(dict[state_dp]*100.0/dict['total_dp']) else: dict[statepercent] = 0 l.append(dict) return l