source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/getNewStudentStatistics.py @ 9819

Last change on this file since 9819 was 1673, checked in by joachim, 18 years ago

merge up to 1672

File size: 4.0 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"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19import logging
20logger = logging.getLogger('Skins.getNewStudentStatistics')
21
22try:
23    from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp
24    aq_portal = context.portal_catalog.evalAdvancedQuery
25    aq_students = context.students_catalog.evalAdvancedQuery
26except:
27    evalAdvancedQuery = None
28
29def intersect(m,n):
30    return [i for i in m if i in n]
31   
32logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
33if not context.isStaff():
34    return l
35total_dict = {}
36
37total_dict['id'] = "All Faculties"
38
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))
42newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*')
43total_res = aq_portal(newquery)
44new_ids = [r.getPath().split('/')[-2] for r in total_res]
45total_new = float(len(total_res))
46total_dict['new'] = "%.0f" % total_new
47special_states =  ('admitted',
48                   'clearance_pin_entered',
49                   'clearance_requested',
50                   'cleared_and_validated',
51                   'objection_raised',
52                   )
53state_count = 0
54state_ids = {}
55for 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)
63total_dict['rest'] = "%.0f" % (total_new - state_count)
64total_dict['rest_percent'] = "%.0f" % round((total_new - state_count)*100/total_new)
65fac_res = {}
66#fac_res['total'] = total_dict
67faculties = context.portal_catalog(portal_type="Faculty")
68for 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    dict['new'] = 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
94l = []
95l.append(total_dict)
96fac_ids = [f.getId for f in faculties]
97fac_ids.sort()
98check_dict = {}
99check_dict['id'] = 'Check'
100check_dict['new'] = 0
101check_dict['new_percent'] = 0
102check_dict['rest'] = 0
103check_dict['rest_percent'] = 0
104for state in special_states:
105    check_dict[state] = 0
106    check_dict["%s_percent" % state] = 0
107   
108for f in fac_ids:
109    total_fac = fac_res[f]['new']
110    check_dict['new'] = check_dict['new'] + total_fac
111    check_dict['rest'] = check_dict['rest'] + fac_res[f]['rest']
112    for state in special_states:
113        check_dict[state] = check_dict[state] + fac_res[f][state]
114        if total_fac != 0:
115            fac_res[f]['%s_percent' % state] = "%.0f" % round(fac_res[f][state]*100/total_fac)
116        else:
117            fac_res[f]['%s_percent' % state] = "%.0f" % 0.0
118    if total_fac != 0:
119        fac_res[f]['rest_percent'] = "%.0f" % round(fac_res[f]['rest']*100/total_fac)
120    else:
121        fac_res[f]['rest_percent'] = "%.0f" % 0.0
122    l.append(fac_res[f])
123l.append(check_dict)   
124
125return l
126
Note: See TracBrowser for help on using the repository browser.