source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/getRegStatistics.py @ 15344

Last change on this file since 15344 was 1596, checked in by joachim, 18 years ago

merged changes from trunk to joachim-event-branch

File size: 2.5 KB
RevLine 
[1530]1## Script (Python) "getRegStatistics"
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"""
14import logging
[1596]15logger = logging.getLogger('Skins.getRegStatistics')
[1530]16
17try:
18    from Products.AdvancedQuery import Eq, Between, Le,In, Ge
19    aq_portal = context.portal_catalog.evalAdvancedQuery
20    students_catalog = context.students_catalog
21except:
22    evalAdvancedQuery = None
[1596]23logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
[1530]24l = []
25if not context.isStaff():
26    return l
27dep = {}
28
29dep['id'] = "All Faculties"
30
31total = float(len(students_catalog))
32
33dep['total'] = "%.0f" % total
34
35
36#from Products.zdb import set_trace;set_trace()
37
38sfp_res = context.portal_catalog(review_state ='school_fee_paid')
39sfp_ids = [r.getId for r in sfp_res]
40sfp = len(sfp_res)
41dep['school_fee_paid'] = sfp
42dep['school_fee_paid_percent'] =  "%.0f" % round(sfp*100/total)
43
44creg_res = context.portal_catalog(review_state ='courses_registered')
45creg_ids = [r.getId for r in creg_res]
46creg = len(creg_res)
47dep['courses_registered'] = creg
48dep['courses_registered_percent'] = "%.0f" % round(creg*100/total)
49
50cval_res = context.portal_catalog(review_state='courses_validated')
51cval_ids = [r.getId for r in cval_res]
52cval = len(cval_res)
53dep['courses_validated'] = cval
54dep['courses_validated_percent'] = "%.0f" % round(cval*100/total)
55
56
57l.append(dep)
58fs = context.portal_catalog(portal_type="Faculty")
59for fid in [f.getId for f in fs]:
60    dep = {}
61    dep['id'] = fid
62    #fquery = Eq('faculty',fid)
63    fac_res = students_catalog(faculty = fid)
64    fac_ids = [r.id for r in fac_res]
65    total = float(len(fac_res))
66
67    if total == 0:
68        continue
69
70    dep['total'] = "%.0f" % total
71
72    sfp = len([s for s in fac_ids if s in sfp_ids])
73    dep['school_fee_paid'] = sfp
74    dep['school_fee_paid_percent'] = 0
75    if total:
76        dep['school_fee_paid_percent'] = "%.0f" % round(sfp*100/total)
77
78    creg = len([s for s in fac_ids if s in creg_ids])
79    dep['courses_registered'] = creg
80    dep['courses_registered_percent'] = 0
81    if total:
82        dep['courses_registered_percent'] = "%.0f" % round(creg*100/total)
[1596]83
[1530]84    cval = len([s for s in fac_ids if s in cval_ids])
85    dep['courses_validated'] = cval
86    dep['courses_validated_percent'] = 0
87    if total:
88        dep['courses_validated_percent'] = "%.0f" % round(cval*100/total)
89
90    l.append(dep)
91
92return l
93
Note: See TracBrowser for help on using the repository browser.