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