Changeset 3349
- Timestamp:
- 18 Mar 2008, 17:54:22 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTool.py
r3346 r3349 885 885 ###) 886 886 887 def init_timing(self): ###( 888 if self.with_timing: 889 if not hasattr(self,'_v_step_times'): 890 self._v_timer_count = 0 891 self._v_total = 0 892 self._v_step_times = {} 893 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 894 self._v_timer_file = "%s/export/timing_%s.csv" % (i_home,current,) 895 self.timer_step = 0 896 self.total_time = 0 897 self.elapse = time.time() 898 self.i_elapse = time.time() 899 self.c_elapse = time.clock() 900 901 ###) 902 903 def do_timing(self): ###( 904 if self.with_timing: 905 try: 906 raise 'dummy' 907 except: 908 frame = sys.exc_traceback.tb_frame.f_back 909 locals = frame.f_locals 910 globals = frame.f_globals 911 functionname = frame.f_code.co_name 912 filename = os.path.basename(frame.f_code.co_filename) 913 lineno = frame.f_lineno 914 mod_line = "%(functionname)s:%(lineno)s" % vars() 915 i_time = time.time() - self.i_elapse 916 td = {} 917 if self._v_step_times.has_key(mod_line): 918 a_time = self._v_step_times[mod_line]['a_time'] + i_time 919 td['a_time'] = a_time 920 else: 921 td['a_time'] = i_time 922 td['i_time'] = i_time 923 self._v_step_times[mod_line] = td 924 self.i_time = i_time 925 self.total_time += i_time 926 self.timer_step +=1 927 self.i_elapse = time.time() 928 929 ###) 930 931 security.declareProtected(ModifyPortalContent,'print_timing') ###( ###( 932 def print_timing(self): 933 if self.with_timing: 934 l = [] 935 timer_count = self._v_timer_count + 1 936 mod_lines = self._v_step_times.keys() 937 mod_lines.sort(cmp,reverse=0) 938 for mod_line in mod_lines: 939 td = self._v_step_times[mod_line] 940 i_time = td['i_time'] 941 a_time = td['a_time']/(self._v_timer_count + 1) 942 l += ("%(mod_line)s,%(i_time)6.2f,%(a_time)6.2f,%(timer_count)d" % vars()), 943 total_time = self.total_time 944 total_avarage = self._v_total / timer_count 945 l += ("total,%(total_time)6.4f,%(total_avarage)6.4f,%(timer_count)d" % vars()), 946 print "\r\n".join(l) 947 out = open(self._v_timer_file,'a') 948 out.write("\r\n".join(l)) 949 out.close() 950 951 ###) 952 953 security.declareProtected(ModifyPortalContent,'get_timing_data') ###( ###( 954 def get_timing_data(self): 955 if self.with_timing: 956 timer_count = self._v_timer_count + 1 957 results = {} 958 for k,d in self._v_step_times.items(): 959 dd = {} 960 dd['a_time'] = d['a_time']/timer_count 961 dd['i_time'] = d['i_time'] 962 dd['count'] = timer_count 963 results[k] = dd 964 dd = {} 965 dd['a_time'] = self._v_total / timer_count 966 dd['i_time'] = self.total_time 967 dd['count'] = timer_count 968 results["total"] = dd 969 return results 970 ###) 971 887 972 security.declareProtected(ModifyPortalContent,'admitOneStudent') ###( 888 def admitOneStudent(self,brain,entry_session,pin_password ):973 def admitOneStudent(self,brain,entry_session,pin_password,with_timing=False): 889 974 "create Datastructure for an admitted Student" 890 975 #import pdb;pdb.set_trace() 976 logger = logging.getLogger('WAeUPTool.admitOneStudent') 977 self.with_timing = with_timing 891 978 if not hasattr(self,"_v_certificates"): 892 979 self._v_certificates = self.getCertificatesDict() 893 980 students_folder = self.portal_url.getPortalObject().campus.students 894 logger = logging.getLogger('WAeUPTool.admitOneStudent')895 981 if brain.screening_type in ('cest','sandwich',): 896 982 reg_no = "%s%s/07" % (brain.course1,brain.serial) … … 914 1000 logger.info('sex of %s not available' % (reg_no)) 915 1001 return 1002 self.init_timing() 916 1003 student_id = self.generateStudentId('?') 917 1004 students_folder.invokeFactory('Student', student_id) 918 1005 student_object = getattr(students_folder,student_id) 1006 self.do_timing() 919 1007 if pin_password: 920 1008 password = pin_parts[2] 921 1009 self.makeStudentMember(student_id,password = password) 922 1010 student_object.manage_setLocalRoles(student_id, ['Owner',]) 1011 self.do_timing() 923 1012 #logger.info("creating %s reg_no %s" % (student_id,reg_no)) 924 1013 # … … 928 1017 application = student_object.application 929 1018 #self.portal_workflow.doActionFor(application,'open',dest_container=application) 1019 self.do_timing() 930 1020 da = {'Title': 'Application Data'} 931 1021 da['jamb_reg_no'] = reg_no … … 944 1034 945 1035 da['entry_mode'] = self._v_certificates[brain.course_admitted]['study_mode'] 946 947 #if brain.entry_mode:948 # da['entry_mode'] = brain.entry_mode949 #elif brain.screening_type == 'pume':950 # da['entry_mode'] = 'ume_ft'951 #elif brain.screening_type == 'pde':952 # da['entry_mode'] = 'de_ft'953 #elif brain.screening_type == 'pce':954 # da['entry_mode'] = 'pce'955 #elif brain.screening_type == 'prence':956 # da['entry_mode'] = 'prence'957 #else:958 # da['entry_mode'] = ''959 960 1036 961 1037 da['entry_session'] = entry_session … … 976 1052 977 1053 application.getContent().edit(mapping=da) 1054 self.do_timing() 978 1055 #self.portal_workflow.doActionFor(application,'close',dest_container=application) 979 1056 # … … 983 1060 personal = student_object.personal 984 1061 #self.portal_workflow.doActionFor(personal,'open',dest_container=personal) 1062 self.do_timing() 985 1063 dp = {'Title': 'Personal Data'} 986 1064 dp['sex'] = brain.sex … … 991 1069 dp['firstname'] = brain.firstname 992 1070 personal.getContent().edit(mapping=dp) 1071 self.do_timing() 993 1072 # 994 1073 # clearance … … 1001 1080 dc['birthday'] = brain.date_of_birth 1002 1081 clearance.getContent().edit(mapping=dc) 1082 self.do_timing() 1003 1083 #self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance) 1004 1084 # … … 1008 1088 studycourse = student_object.study_course 1009 1089 #self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse) 1090 self.do_timing() 1010 1091 dsc = {} 1011 1092 dsc['study_course'] = brain.course_admitted … … 1020 1101 dsc['current_session'] = entry_session 1021 1102 studycourse.getContent().edit(mapping=dsc) 1103 self.do_timing() 1022 1104 # 1023 1105 # payments folder 1024 1106 student_object.invokeFactory('PaymentsFolder','payments') 1025 1107 payments = getattr(student_object,'payments') 1108 self.do_timing() 1026 1109 dpay = {} 1027 1110 dpay['Title'] = 'Payments' 1028 1111 payments.getContent().edit(mapping=dpay) 1029 1112 self.portal_workflow.doActionFor(payments,'open') 1113 self.do_timing() 1030 1114 # 1031 1115 # passport foto … … 1048 1132 app_picture)) 1049 1133 1134 self.do_timing() 1135 self.print_timing() 1136 if with_timing: 1137 self.timer_step = 0 1138 self._v_timer_count += 1 1139 self._v_total += self.total_time 1050 1140 return student_id 1051 1141 ###) -
WAeUP_SRP/base/skins/waeup_student/admitStudents.py
r3340 r3349 44 44 admitted = 0 45 45 cocount = 0 46 commit_after = 20 46 old_commit_count = -1 47 commit_after = 40 47 48 d = {'status': 'created'} 48 49 reg_nos = [brain.reg_no for brain in brains] 50 with_timing = True 49 51 for reg_no in reg_nos: 50 52 count += 1 51 if admitted and not admitted % commit_after: 53 must_commit = (admitted != old_commit_count) and (not admitted % commit_after) 54 if must_commit: 55 old_commit_count = admitted 52 56 context.waeup_tool.doCommit() 53 57 logger.info("Committing %s transactions, total %s" % (commit_after,count)) 54 58 cocount += 1 55 #if cocount > 1:56 #break59 if cocount > 2: 60 break 57 61 brain = aq_applicants(Eq('reg_no',reg_no))[0] 58 62 #logger.info("start creating objects of student %s" % (brain.reg_no)) 59 sid = d['student_id'] = context.waeup_tool.admitOneStudent(brain,entry_session,pin_password) 63 sid = d['student_id'] = context.waeup_tool.admitOneStudent(brain, 64 entry_session, 65 pin_password, 66 with_timing = with_timing) 67 60 68 if sid is not None: 61 69 d['reg_no'] = reg_no 62 70 context.applicants_catalog.modifyRecord(**d) 63 71 logger.info("created objects of student %s with id %s" % (reg_no,sid)) 72 if with_timing: 73 data = context.waeup_tool.get_timing_data() 74 logger.info("timing %(i_time)6.2f/%(a_time)6.2f" % data['total']) 64 75 admitted += 1 65 76 else:
Note: See TracChangeset for help on using the changeset viewer.