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

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

resolve ticket #462

File size: 4.8 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
22entry_sessions = (context.getSessionId()[0])
23
24# students with entry_session None (-1) are interprteted as new AND returning students if they are
25# in either of the last three states
26
27new_states =      ('student_created',
28                   'admitted',
29                   'clearance_pin_entered',
30                   'objection_raised',
31                   'clearance_requested',
32                   'cleared_and_validated',
33                   'school_fee_paid',
34                   'courses_registered',
35                   'courses_validated',
36                   )
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 = new_states)
54dict['total_ft'] = len(res_ft)
55
56res_pt = context.students_catalog(entry_session = entry_sessions,  mode = part_time, review_state = new_states)
57dict['total_pt'] = len(res_pt)
58
59res_dp = context.students_catalog(entry_session = entry_sessions,  mode = diploma, review_state = new_states)
60dict['total_dp'] = len(res_dp)
61
62for state in new_states:
63    # full_time
64    res_ft = context.students_catalog(entry_session = entry_sessions, review_state = state,  mode = full_time)
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)
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)
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)
101    dict['total_ft'] = len(res_ft)
102    res_pt = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = part_time)
103    dict['total_pt'] = len(res_pt)
104    res_dp = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, mode = diploma)
105    dict['total_dp'] = len(res_dp)   
106    for state in new_states:
107        # full_time
108        res_ft = context.students_catalog(entry_session = entry_sessions, faculty = f.getId, review_state = state, mode = full_time)
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)
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)
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    l.append(dict)
138
139
140
141return l
142
143
Note: See TracBrowser for help on using the repository browser.