source: WAeUP_SRP/trunk/skins/waeup_statistics/getNewStudentStatistics.py @ 4853

Last change on this file since 4853 was 3959, checked in by Henrik Bettermann, 16 years ago

resolve #611 (part 3)

File size: 4.9 KB
Line 
1## Script (Python) "getNewStudentStatistics"
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.getNewStudentStatistics')
17
18logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
19if not context.isStaff():
20    return
21
22session_id = context.getSessionId()[0]
23session_id_num = int(session_id)
24entry_sessions = (session_id,str(session_id_num))
25
26# students with entry_session None (-1) are interprteted as new AND returning students if they are
27# in either of the last three states
28
29new_states =      ('student_created',
30                   'admitted',
31                   'clearance_pin_entered',
32                   'objection_raised',
33                   'clearance_requested',
34                   'cleared_and_validated',
35                   'school_fee_paid',
36                   'courses_registered',
37                   'courses_validated',
38                   )
39
40full_time =       ('ume_ft','de_ft','ug_ft','pg_ft')
41part_time =       (         'de_pt','ug_pt','pg_pt')
42diploma   =       ('dp_ft','dp_pt')
43
44faculties = context.portal_catalog(portal_type="Faculty")
45
46l = []
47
48
49fac_res = {}
50
51dict = {}
52dict['id'] = 'All Faculties'
53dict['title'] = 'All Faculties'
54
55res_ft = context.students_catalog(entry_session = entry_sessions,  mode = full_time, review_state = new_states)
56dict['total_ft'] = len(res_ft)
57
58res_pt = context.students_catalog(entry_session = entry_sessions,  mode = part_time, review_state = new_states)
59dict['total_pt'] = len(res_pt)
60
61res_dp = context.students_catalog(entry_session = entry_sessions,  mode = diploma, review_state = new_states)
62dict['total_dp'] = len(res_dp)
63
64for state in new_states:
65    # full_time
66    res_ft = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = full_time)
67    state_ft = state + '_ft'
68    dict[state_ft] = len(res_ft)
69    statepercent = state+'_ft_percent'
70    if dict['total_ft'] > 0:
71        dict[statepercent] = "%.0f" % round(dict[state_ft]*100.0/dict['total_ft'])
72    else:
73        dict[statepercent] = 0
74
75    # part_time
76    res_pt = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = part_time)
77    state_pt = state + '_pt'
78    dict[state_pt] = len(res_pt)
79    statepercent = state+'_pt_percent'
80    if dict['total_pt'] > 0:
81        dict[statepercent] = "%.0f" % round(dict[state_pt]*100.0/dict['total_pt'])
82    else:
83        dict[statepercent] = 0
84       
85    # diploma
86    res_dp = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = diploma)
87    state_dp = state + '_dp'
88    dict[state_dp] = len(res_dp)
89    statepercent = state+'_dp_percent'
90    if dict['total_dp'] > 0:
91        dict[statepercent] = "%.0f" % round(dict[state_dp]*100.0/dict['total_dp'])
92    else:
93        dict[statepercent] = 0       
94
95l.append(dict)
96
97
98for f in faculties:
99    dict = {}
100    dict['id'] = f.getId
101    dict['title'] = f.Title
102    res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = full_time)
103    dict['total_ft'] = len(res_ft)
104    res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = part_time)
105    dict['total_pt'] = len(res_pt)
106    res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = diploma)
107    dict['total_dp'] = len(res_dp)   
108    for state in new_states:
109        # full_time
110        res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = full_time)
111        state_ft = state + '_ft'
112        dict[state_ft] = len(res_ft)
113        statepercent = state+'_ft_percent'
114        if dict['total_ft'] > 0:
115            dict[statepercent] = "%.0f" % round(dict[state_ft]*100.0/dict['total_ft'])
116        else:
117            dict[statepercent] = 0
118
119        # part_time
120        res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = part_time)
121        state_pt = state + '_pt'
122        dict[state_pt] = len(res_pt)
123        statepercent = state+'_pt_percent'
124        if dict['total_pt'] > 0:
125            dict[statepercent] = "%.0f" % round(dict[state_pt]*100.0/dict['total_pt'])
126        else:
127            dict[statepercent] = 0
128           
129        # diploma
130        res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = diploma)
131        state_dp = state + '_dp'
132        dict[state_dp] = len(res_dp)
133        statepercent = state+'_dp_percent'
134        if dict['total_dp'] > 0:
135            dict[statepercent] = "%.0f" % round(dict[state_dp]*100.0/dict['total_dp'])
136        else:
137            dict[statepercent] = 0           
138
139    l.append(dict)
140
141
142
143return l
144
145
Note: See TracBrowser for help on using the repository browser.