Changeset 3349 for WAeUP_SRP


Ignore:
Timestamp:
18 Mar 2008, 17:54:22 (17 years ago)
Author:
joachim
Message:

include timing functions,
to enable set with_timing to True

Location:
WAeUP_SRP/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTool.py

    r3346 r3349  
    885885###)
    886886
     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
    887972    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):
    889974        "create Datastructure for an admitted Student"
    890975        #import pdb;pdb.set_trace()
     976        logger = logging.getLogger('WAeUPTool.admitOneStudent')
     977        self.with_timing = with_timing
    891978        if not hasattr(self,"_v_certificates"):
    892979            self._v_certificates = self.getCertificatesDict()
    893980        students_folder = self.portal_url.getPortalObject().campus.students
    894         logger = logging.getLogger('WAeUPTool.admitOneStudent')
    895981        if brain.screening_type in ('cest','sandwich',):
    896982            reg_no = "%s%s/07" % (brain.course1,brain.serial)
     
    9141000            logger.info('sex of %s not available' % (reg_no))
    9151001            return
     1002        self.init_timing()
    9161003        student_id = self.generateStudentId('?')
    9171004        students_folder.invokeFactory('Student', student_id)
    9181005        student_object = getattr(students_folder,student_id)
     1006        self.do_timing()
    9191007        if pin_password:
    9201008            password = pin_parts[2]
    9211009            self.makeStudentMember(student_id,password = password)
    9221010        student_object.manage_setLocalRoles(student_id, ['Owner',])
     1011        self.do_timing()
    9231012        #logger.info("creating %s reg_no %s" % (student_id,reg_no))
    9241013        #
     
    9281017        application = student_object.application
    9291018        #self.portal_workflow.doActionFor(application,'open',dest_container=application)
     1019        self.do_timing()
    9301020        da = {'Title': 'Application Data'}
    9311021        da['jamb_reg_no'] = reg_no
     
    9441034
    9451035        da['entry_mode'] = self._v_certificates[brain.course_admitted]['study_mode']
    946 
    947         #if brain.entry_mode:
    948         #    da['entry_mode'] = brain.entry_mode
    949         #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 
    9601036
    9611037        da['entry_session'] = entry_session
     
    9761052
    9771053        application.getContent().edit(mapping=da)
     1054        self.do_timing()
    9781055        #self.portal_workflow.doActionFor(application,'close',dest_container=application)
    9791056        #
     
    9831060        personal = student_object.personal
    9841061        #self.portal_workflow.doActionFor(personal,'open',dest_container=personal)
     1062        self.do_timing()
    9851063        dp = {'Title': 'Personal Data'}
    9861064        dp['sex'] = brain.sex
     
    9911069        dp['firstname'] = brain.firstname
    9921070        personal.getContent().edit(mapping=dp)
     1071        self.do_timing()
    9931072        #
    9941073        # clearance
     
    10011080        dc['birthday'] = brain.date_of_birth
    10021081        clearance.getContent().edit(mapping=dc)
     1082        self.do_timing()
    10031083        #self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance)
    10041084        #
     
    10081088        studycourse = student_object.study_course
    10091089        #self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse)
     1090        self.do_timing()
    10101091        dsc = {}
    10111092        dsc['study_course'] = brain.course_admitted
     
    10201101        dsc['current_session'] = entry_session
    10211102        studycourse.getContent().edit(mapping=dsc)
     1103        self.do_timing()
    10221104        #
    10231105        # payments folder
    10241106        student_object.invokeFactory('PaymentsFolder','payments')
    10251107        payments = getattr(student_object,'payments')
     1108        self.do_timing()
    10261109        dpay = {}
    10271110        dpay['Title'] = 'Payments'
    10281111        payments.getContent().edit(mapping=dpay)
    10291112        self.portal_workflow.doActionFor(payments,'open')
     1113        self.do_timing()
    10301114        #
    10311115        # passport foto
     
    10481132                                                             app_picture))
    10491133
     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
    10501140        return student_id
    10511141    ###)
  • WAeUP_SRP/base/skins/waeup_student/admitStudents.py

    r3340 r3349  
    4444admitted = 0
    4545cocount = 0
    46 commit_after = 20
     46old_commit_count = -1
     47commit_after = 40
    4748d = {'status': 'created'}
    4849reg_nos = [brain.reg_no for brain in brains]
     50with_timing = True
    4951for reg_no in reg_nos:
    5052    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
    5256        context.waeup_tool.doCommit()
    5357        logger.info("Committing %s transactions, total %s" % (commit_after,count))
    5458        cocount += 1
    55         #if cocount > 1:
    56         #    break
     59        if cocount > 2:
     60            break
    5761    brain = aq_applicants(Eq('reg_no',reg_no))[0]
    5862    #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       
    6068    if sid is not None:
    6169        d['reg_no'] = reg_no
    6270        context.applicants_catalog.modifyRecord(**d)
    6371        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'])
    6475        admitted += 1
    6576    else:
Note: See TracChangeset for help on using the changeset viewer.