source: WAeUP_SRP/trunk/skins/waeup_statistics/getRetStudentStatistics.py @ 17722

Last change on this file since 17722 was 8029, checked in by Henrik Bettermann, 13 years ago

Fix returning student statistics.

File size: 5.0 KB
Line 
1## Script (Python) "getRetStudentStatistics"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: getStudentStatistics.py 1277 2007-01-11 21:11:37Z joachim $
11"""
12return Student Statistics
13"""
14
15import logging
16logger = logging.getLogger('Skins.getRetStudentStatistics')
17
18logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
19if not context.isStaff():
20    return 'Not allowed'
21
22current_session = context.getSessionId()[0]
23
24
25
26range1 = range(94,100,1)
27range2 = range(0,int(current_session),1)
28missing_values = ['','-1']
29entry_sessions = missing_values + [str(k) for k in range1+range2] + ['0'+str(k) for k in range2]
30
31#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')
32
33ret_states =      ('returning',
34                   'school_fee_paid',
35                   'courses_registered',
36                   'courses_validated',
37                   )
38full_time =       ('ume_ft','de_ft','ug_ft','pg_ft')
39part_time =       (         'de_pt','ug_pt','pg_pt')
40diploma   =       ('dp_ft','dp_pt')
41
42faculties = context.portal_catalog(portal_type="Faculty")
43
44l = []
45
46
47fac_res = {}
48
49dict = {}
50dict['id'] = 'All Faculties'
51dict['title'] = 'All Faculties'
52
53res_ft = context.students_catalog(entry_session = entry_sessions,  mode = full_time, review_state = ret_states)
54dict['total_ft'] = len(res_ft)
55
56res_pt = context.students_catalog(entry_session = entry_sessions,  mode = part_time, review_state = ret_states)
57dict['total_pt'] = len(res_pt)
58
59res_dp = context.students_catalog(entry_session = entry_sessions,  mode = diploma, review_state = ret_states)
60dict['total_dp'] = len(res_dp)
61
62for state in ret_states:
63    # full_time
64    res_ft = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = full_time, session = current_session)
65    state_ft = state + '_ft'
66    dict[state_ft] = len(res_ft)
67    statepercent = state+'_ft_percent'
68    if dict['total_ft'] > 0:
69        dict[statepercent] = "%.0f" % round(dict[state_ft]*100.0/dict['total_ft'])
70    else:
71        dict[statepercent] = 0
72
73    # part_time
74    res_pt = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = part_time, session = current_session)
75    state_pt = state + '_pt'
76    dict[state_pt] = len(res_pt)
77    statepercent = state+'_pt_percent'
78    if dict['total_pt'] > 0:
79        dict[statepercent] = "%.0f" % round(dict[state_pt]*100.0/dict['total_pt'])
80    else:
81        dict[statepercent] = 0
82       
83    # diploma
84    res_dp = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = diploma, session = current_session)
85    state_dp = state + '_dp'
86    dict[state_dp] = len(res_dp)
87    statepercent = state+'_dp_percent'
88    if dict['total_dp'] > 0:
89        dict[statepercent] = "%.0f" % round(dict[state_dp]*100.0/dict['total_dp'])
90    else:
91        dict[statepercent] = 0       
92
93l.append(dict)
94
95
96for f in faculties:
97    dict = {}
98    dict['id'] = f.getId
99    dict['title'] = f.Title
100    res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = full_time, review_state = ret_states)
101    dict['total_ft'] = len(res_ft)
102    res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = part_time, review_state = ret_states)
103    dict['total_pt'] = len(res_pt)
104    res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = diploma, review_state = ret_states)
105    dict['total_dp'] = len(res_dp)   
106    for state in ret_states:
107        # full_time
108        res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = full_time, session = current_session)
109        state_ft = state + '_ft'
110        dict[state_ft] = len(res_ft)
111        statepercent = state+'_ft_percent'
112        if dict['total_ft'] > 0:
113            dict[statepercent] = "%.0f" % round(dict[state_ft]*100.0/dict['total_ft'])
114        else:
115            dict[statepercent] = 0
116
117        # part_time
118        res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = part_time, session = current_session)
119        state_pt = state + '_pt'
120        dict[state_pt] = len(res_pt)
121        statepercent = state+'_pt_percent'
122        if dict['total_pt'] > 0:
123            dict[statepercent] = "%.0f" % round(dict[state_pt]*100.0/dict['total_pt'])
124        else:
125            dict[statepercent] = 0
126           
127        # diploma
128        res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = diploma, session = current_session)
129        state_dp = state + '_dp'
130        dict[state_dp] = len(res_dp)
131        statepercent = state+'_dp_percent'
132        if dict['total_dp'] > 0:
133            dict[statepercent] = "%.0f" % round(dict[state_dp]*100.0/dict['total_dp'])
134        else:
135            dict[statepercent] = 0
136           
137
138    l.append(dict)
139
140return l
141
142
Note: See TracBrowser for help on using the repository browser.