Index: /WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics.py	(revision 1669)
+++ /WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics.py	(revision 1670)
@@ -12,112 +12,98 @@
 return Student Statistics
 """
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
 import logging
 logger = logging.getLogger('Skins.getNewStudentStatistics')
 
 try:
-    from Products.AdvancedQuery import Eq, Between, Le,In, Ge
+    from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp
     aq_portal = context.portal_catalog.evalAdvancedQuery
     aq_students = context.students_catalog.evalAdvancedQuery
 except:
     evalAdvancedQuery = None
+
+def intersect(m,n):
+    return [i for i in m if i in n]
+    
 logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
-l = []
 if not context.isStaff():
     return l
-dep = {}
+total_dict = {}
 
-dep['id'] = "All Faculties"
+total_dict['id'] = "All Faculties"
 
-freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE'))
-total_new = aq_students(freshquery)
-total_new = float(len(total_new))
-dep['new'] = "%.0f" % total_new
-
-
-#from Products.zdb import set_trace;set_trace()
-
-adm_res = context.portal_catalog(review_state ='admitted')
-adm_ids = [r.getId for r in adm_res]
-adm = len(adm_res)
-dep['admitted'] = adm
-dep['admitted_percent'] =  "%.0f" % round(adm*100/total_new)
-
-cpe_res = context.portal_catalog(review_state ='clearance_pin_entered')
-cpe_ids = [r.getId for r in cpe_res]
-cpe = len(cpe_res)
-dep['clearance_pin_entered'] = cpe
-dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total_new)
-
-cr_res = context.portal_catalog(review_state='clearance_requested')
-cr_ids = [r.getId for r in cr_res]
-cr = len(cr_res)
-dep['clearance_requested'] = cr
-dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total_new)
-
-cav_res = context.portal_catalog(review_state ='cleared_and_validated')
-cav_ids = [r.getId for r in cav_res]
-cav = len(cav_res)
-dep['cleared_and_validated'] = cav
-dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total_new)
-
-or_res = context.portal_catalog(review_state='objection_raised')
-or_ids = [r.getId for r in or_res]
-ora = len(or_res)
-dep['objection_raised'] = ora
-dep['objection_raised_percent'] = "%.0f" % round(ora*100/total_new)
-
-total_sfp = total_new - (cav + cr + cpe + adm + ora)
-dep['rest'] = int(total_sfp)
-dep['rest_percent'] = "%.0f" % round(total_sfp*100/total_new)
-
-
-l.append(dep)
-fs = context.portal_catalog(portal_type="Faculty")
-for fid in [f.getId for f in fs]:
-    dep = {}
-    dep['id'] = fid
-    fquery = Eq('faculty',fid)
-    fac_res = aq_students(fquery & freshquery)
-    fac_ids = [r.id for r in fac_res]
-    total = float(len(fac_res))
-
-    if total == 0:
-        continue
-
-    dep['new'] = "%.0f" % total
-
-    adm = len([s for s in fac_ids if s in adm_ids])
-    dep['admitted'] = adm
-    dep['admitted_percent'] = 0
-    if total:
-        dep['admitted_percent'] = "%.0f" % round(adm*100/total)
-
-    cpe = len([s for s in fac_ids if s in cpe_ids])
-    dep['clearance_pin_entered'] = cpe
-    dep['clearance_pin_entered_percent'] = 0
-    if total:
-        dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total)
-    cr = len([s for s in fac_ids if s in cr_ids])
-    dep['clearance_requested'] = cr
-    dep['clearance_requested_percent'] = 0
-    if total:
-        dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total)
-    cav = len([s for s in fac_ids if s in cav_ids])
-    dep['cleared_and_validated'] = cav
-    dep['cleared_and_validated_percent'] = 0
-    if total:
-        dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total)
-
-    ora = len([s for s in fac_ids if s in or_ids])
-    dep['objection_raised'] = ora
-    dep['objection_raised_percent'] = 0
-    if total:
-        dep['objection_raised_percent'] = "%.0f" % round(ora*100/total)
-
-    rest = int(total - (cav + cr + cpe + adm + ora))
-    dep['rest'] = rest
-    dep['rest_percent'] = "%.0f" % round(rest*100/total)
-
-    l.append(dep)
+##freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE'))
+##total_new = aq_students(freshquery)
+##total_new = float(len(total_new))
+newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*')
+total_res = aq_portal(newquery)
+new_ids = [r.getPath().split('/')[-2] for r in total_res]
+total_new = float(len(total_res))
+total_dict['new'] = "%.0f" % total_new
+special_states =  ('admitted',
+                   'clearance_pin_entered',
+                   'clearance_requested',
+                   'cleared_and_validated',
+                   'objection_raised',
+                   )
+state_count = 0 
+state_ids = {}
+for state in special_states:
+    res = context.portal_catalog(review_state = state)
+    ids = [r.getId for r in res]
+    state_ids[state] = ids 
+    count = len(res)
+    state_count += count
+    total_dict[state] = count
+    total_dict['%s_percent' % state] =  "%.0f" % round(count*100/total_new)
+total_dict['rest'] = "%.0f" % (total_new - state_count)
+total_dict['rest_percent'] = "%.0f" % round((total_new - state_count)*100/total_new)
+fac_res = {}
+#fac_res['total'] = total_dict
+faculties = context.portal_catalog(portal_type="Faculty")
+for f in faculties:
+    dict = {}
+    dict['id'] = f.getId
+    dict['title'] = f.Title
+    sid_in_faculty = [s.id for s in context.students_catalog(faculty=f.getId)]
+    new_in_faculty = intersect(new_ids,sid_in_faculty)
+    rest = len(new_in_faculty)
+    for state in special_states:
+        state_count = len(intersect(state_ids[state], new_in_faculty))
+        rest -= state_count
+        dict[state] = state_count
+    dict['rest'] = rest
+    fac_res[f.getId] = dict
+#set_trace()    
+##for sid,review_state in new_ids:
+##    scat_res = context.students_catalog(id = sid)
+##    if not scat_res:
+##        continue
+##    student = scat_res[0]
+##    faculty = student.faculty
+##    if not fac_res.has_key(faculty):
+##        continue
+##    if review_state in special_states:
+##        fac_res[faculty][review_state] = fac_res[faculty][review_state] + 1
+##    else:
+##        fac_res[faculty]['rest'] = fac_res[faculty]['rest'] + 1
+l = []
+l.append(total_dict)
+fac_ids = [f.getId for f in faculties]
+fac_ids.sort()
+for f in fac_ids:
+    sum = 0
+    for state in special_states:
+        sum += fac_res[f][state]
+        fac_res[f]['%s_percent' % state] = "%.0f" % round(fac_res[f][state]*100/total_new)
+    fac_res[f]['rest_percent'] = "%.0f" % round(fac_res[f]['rest']*100/total_new)
+    sum += fac_res[f]['rest']
+    fac_res[f]['new'] = sum
+    l.append(fac_res[f])
+    
 
 return l
Index: /WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics_old.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics_old.py	(revision 1670)
+++ /WAeUP_SRP/trunk/skins/waeup_student/getNewStudentStatistics_old.py	(revision 1670)
@@ -0,0 +1,127 @@
+## Script (Python) "getNewStudentStatistics"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+return Student Statistics
+"""
+import logging
+logger = logging.getLogger('Skins.getNewStudentStatistics')
+
+try:
+    from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp
+    aq_portal = context.portal_catalog.evalAdvancedQuery
+    aq_students = context.students_catalog.evalAdvancedQuery
+except:
+    evalAdvancedQuery = None
+logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
+l = []
+if not context.isStaff():
+    return l
+dep = {}
+
+dep['id'] = "All Faculties"
+
+freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE'))
+total_new = aq_students(freshquery)
+total_new = float(len(total_new))
+##newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*')
+##total_new = aq_portal(newquery)
+##total_new = float(len(total_new))
+dep['new'] = "%.0f" % total_new
+
+
+#from Products.zdb import set_trace;set_trace()
+
+adm_res = context.portal_catalog(review_state ='admitted')
+adm_ids = [r.getId for r in adm_res]
+adm = len(adm_res)
+dep['admitted'] = adm
+dep['admitted_percent'] =  "%.0f" % round(adm*100/total_new)
+
+cpe_res = context.portal_catalog(review_state ='clearance_pin_entered')
+cpe_ids = [r.getId for r in cpe_res]
+cpe = len(cpe_res)
+dep['clearance_pin_entered'] = cpe
+dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total_new)
+
+cr_res = context.portal_catalog(review_state='clearance_requested')
+cr_ids = [r.getId for r in cr_res]
+cr = len(cr_res)
+dep['clearance_requested'] = cr
+dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total_new)
+
+cav_res = context.portal_catalog(review_state ='cleared_and_validated')
+cav_ids = [r.getId for r in cav_res]
+cav = len(cav_res)
+dep['cleared_and_validated'] = cav
+dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total_new)
+
+or_res = context.portal_catalog(review_state='objection_raised')
+or_ids = [r.getId for r in or_res]
+ora = len(or_res)
+dep['objection_raised'] = ora
+dep['objection_raised_percent'] = "%.0f" % round(ora*100/total_new)
+
+total_sfp = total_new - (cav + cr + cpe + adm + ora)
+dep['rest'] = int(total_sfp)
+dep['rest_percent'] = "%.0f" % round(total_sfp*100/total_new)
+
+
+l.append(dep)
+fs = context.portal_catalog(portal_type="Faculty")
+for fid in [f.getId for f in fs]:
+    dep = {}
+    dep['id'] = fid
+    fquery = Eq('faculty',fid)
+    fac_res = aq_students(fquery & freshquery)
+    fac_ids = [r.id for r in fac_res]
+    total = float(len(fac_res))
+
+    if total == 0:
+        continue
+
+    dep['new'] = "%.0f" % total
+
+    adm = len([s for s in fac_ids if s in adm_ids])
+    dep['admitted'] = adm
+    dep['admitted_percent'] = 0
+    if total:
+        dep['admitted_percent'] = "%.0f" % round(adm*100/total)
+
+    cpe = len([s for s in fac_ids if s in cpe_ids])
+    dep['clearance_pin_entered'] = cpe
+    dep['clearance_pin_entered_percent'] = 0
+    if total:
+        dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total)
+    cr = len([s for s in fac_ids if s in cr_ids])
+    dep['clearance_requested'] = cr
+    dep['clearance_requested_percent'] = 0
+    if total:
+        dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total)
+    cav = len([s for s in fac_ids if s in cav_ids])
+    dep['cleared_and_validated'] = cav
+    dep['cleared_and_validated_percent'] = 0
+    if total:
+        dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total)
+
+    ora = len([s for s in fac_ids if s in or_ids])
+    dep['objection_raised'] = ora
+    dep['objection_raised_percent'] = 0
+    if total:
+        dep['objection_raised_percent'] = "%.0f" % round(ora*100/total)
+
+    rest = int(total - (cav + cr + cpe + adm + ora))
+    dep['rest'] = rest
+    dep['rest_percent'] = "%.0f" % round(rest*100/total)
+
+    l.append(dep)
+
+return l
+
