Changeset 1670 for WAeUP_SRP/trunk/skins


Ignore:
Timestamp:
5 Apr 2007, 10:06:59 (18 years ago)
Author:
joachim
Message:

implemented a new method for generating the new students statistic,
this statistic is now consistent with cleared student export.

Location:
WAeUP_SRP/trunk/skins/waeup_student
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics.py

    r1571 r1670  
    1212return Student Statistics
    1313"""
     14try:
     15    from Products.zdb import set_trace
     16except:
     17    def set_trace():
     18        pass
    1419import logging
    1520logger = logging.getLogger('Skins.getNewStudentStatistics')
    1621
    1722try:
    18     from Products.AdvancedQuery import Eq, Between, Le,In, Ge
     23    from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp
    1924    aq_portal = context.portal_catalog.evalAdvancedQuery
    2025    aq_students = context.students_catalog.evalAdvancedQuery
    2126except:
    2227    evalAdvancedQuery = None
     28
     29def intersect(m,n):
     30    return [i for i in m if i in n]
     31   
    2332logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
    24 l = []
    2533if not context.isStaff():
    2634    return l
    27 dep = {}
     35total_dict = {}
    2836
    29 dep['id'] = "All Faculties"
     37total_dict['id'] = "All Faculties"
    3038
    31 freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE'))
    32 total_new = aq_students(freshquery)
    33 total_new = float(len(total_new))
    34 dep['new'] = "%.0f" % total_new
    35 
    36 
    37 #from Products.zdb import set_trace;set_trace()
    38 
    39 adm_res = context.portal_catalog(review_state ='admitted')
    40 adm_ids = [r.getId for r in adm_res]
    41 adm = len(adm_res)
    42 dep['admitted'] = adm
    43 dep['admitted_percent'] =  "%.0f" % round(adm*100/total_new)
    44 
    45 cpe_res = context.portal_catalog(review_state ='clearance_pin_entered')
    46 cpe_ids = [r.getId for r in cpe_res]
    47 cpe = len(cpe_res)
    48 dep['clearance_pin_entered'] = cpe
    49 dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total_new)
    50 
    51 cr_res = context.portal_catalog(review_state='clearance_requested')
    52 cr_ids = [r.getId for r in cr_res]
    53 cr = len(cr_res)
    54 dep['clearance_requested'] = cr
    55 dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total_new)
    56 
    57 cav_res = context.portal_catalog(review_state ='cleared_and_validated')
    58 cav_ids = [r.getId for r in cav_res]
    59 cav = len(cav_res)
    60 dep['cleared_and_validated'] = cav
    61 dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total_new)
    62 
    63 or_res = context.portal_catalog(review_state='objection_raised')
    64 or_ids = [r.getId for r in or_res]
    65 ora = len(or_res)
    66 dep['objection_raised'] = ora
    67 dep['objection_raised_percent'] = "%.0f" % round(ora*100/total_new)
    68 
    69 total_sfp = total_new - (cav + cr + cpe + adm + ora)
    70 dep['rest'] = int(total_sfp)
    71 dep['rest_percent'] = "%.0f" % round(total_sfp*100/total_new)
    72 
    73 
    74 l.append(dep)
    75 fs = context.portal_catalog(portal_type="Faculty")
    76 for fid in [f.getId for f in fs]:
    77     dep = {}
    78     dep['id'] = fid
    79     fquery = Eq('faculty',fid)
    80     fac_res = aq_students(fquery & freshquery)
    81     fac_ids = [r.id for r in fac_res]
    82     total = float(len(fac_res))
    83 
    84     if total == 0:
    85         continue
    86 
    87     dep['new'] = "%.0f" % total
    88 
    89     adm = len([s for s in fac_ids if s in adm_ids])
    90     dep['admitted'] = adm
    91     dep['admitted_percent'] = 0
    92     if total:
    93         dep['admitted_percent'] = "%.0f" % round(adm*100/total)
    94 
    95     cpe = len([s for s in fac_ids if s in cpe_ids])
    96     dep['clearance_pin_entered'] = cpe
    97     dep['clearance_pin_entered_percent'] = 0
    98     if total:
    99         dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total)
    100     cr = len([s for s in fac_ids if s in cr_ids])
    101     dep['clearance_requested'] = cr
    102     dep['clearance_requested_percent'] = 0
    103     if total:
    104         dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total)
    105     cav = len([s for s in fac_ids if s in cav_ids])
    106     dep['cleared_and_validated'] = cav
    107     dep['cleared_and_validated_percent'] = 0
    108     if total:
    109         dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total)
    110 
    111     ora = len([s for s in fac_ids if s in or_ids])
    112     dep['objection_raised'] = ora
    113     dep['objection_raised_percent'] = 0
    114     if total:
    115         dep['objection_raised_percent'] = "%.0f" % round(ora*100/total)
    116 
    117     rest = int(total - (cav + cr + cpe + adm + ora))
    118     dep['rest'] = rest
    119     dep['rest_percent'] = "%.0f" % round(rest*100/total)
    120 
    121     l.append(dep)
     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    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()
     98for f in fac_ids:
     99    sum = 0
     100    for state in special_states:
     101        sum += fac_res[f][state]
     102        fac_res[f]['%s_percent' % state] = "%.0f" % round(fac_res[f][state]*100/total_new)
     103    fac_res[f]['rest_percent'] = "%.0f" % round(fac_res[f]['rest']*100/total_new)
     104    sum += fac_res[f]['rest']
     105    fac_res[f]['new'] = sum
     106    l.append(fac_res[f])
     107   
    122108
    123109return l
Note: See TracChangeset for help on using the changeset viewer.