Changeset 1941 for WAeUP_SRP


Ignore:
Timestamp:
21 Jun 2007, 14:36:15 (17 years ago)
Author:
joachim
Message:

faster version of exportStudents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Students.py

    r1940 r1941  
    942942                                'courses_validated'))
    943943        students = aq_students(query)
    944         logger.info('%s starts exportStudents, %s student records to export' % (member,len(students)))
    945         chunk = 100
     944        nr2export = len(students)
     945        logger.info('%s starts exportStudents, %s student records to export' % (member,nr2export))
     946        chunk = 2000
    946947        total = 0
     948        start = DateTime.DateTime().timeTime()
     949        start_chunk = DateTime.DateTime().timeTime()
     950        ## alternative method slightly slower
     951        # student_recs = {}
     952        # for s in students:
     953        #      student_recs[s.id] = s
     954        # catalog_recs = {}
     955        # brains = self.portal_catalog(portal_type = 'Student')
     956        # for cat_rec in brains:
     957        #     sid = cat_rec.getId
     958        #     catalog_recs[sid] = cat_rec
     959        # #import pdb;pdb.set_trace()
     960        # start = DateTime.DateTime().timeTime()
     961        # start_chunk = DateTime.DateTime().timeTime()
     962        # for student in students:
     963        #     if student.id not in student_recs.keys():
     964        #         continue
     965        #     not_all = False
     966        #     d = self.getFormattedStudentEntry(student_recs[student.id])
     967        #     student_obj = catalog_recs[student.id].getObject()
    947968        for student in students:
    948969            not_all = False
    949970            d = self.getFormattedStudentEntry(student)
     971            student_obj = getattr(students_folder,student.id)
    950972            for k in toexport.keys()[1:]:
    951973                try:
    952                     object = getattr(getattr(students_folder,student.id),k)
     974                    object = getattr(student_obj,k)
    953975                    object_doc = object.getContent()
    954976                except:
     
    967989                open(export_file,"a").write('\n'.join(lines) +'\n')
    968990                anz = len(lines)
    969                 logger.info("wrote %(anz)d to %(export_file)s" % vars())
     991                logger.info("wrote %(anz)d  total written %(total)d" % vars())
     992                end_chunk = DateTime.DateTime().timeTime()
     993                duration = end_chunk-start_chunk
     994                per_record = duration/anz
     995                till_now = end_chunk - start
     996                avarage_per_record = till_now/total
     997                estimated_end = DateTime.DateTime(start + avarage_per_record * nr2export)
     998                estimated_end = estimated_end.strftime("%H:%M:%S")
     999                logger.info('%(duration)4.1f, %(per_record)4.3f,end %(estimated_end)s' % vars())
     1000                start_chunk = DateTime.DateTime().timeTime()
    9701001                lines = []
     1002        end = DateTime.DateTime().timeTime()
     1003        logger.info('total time %6.2f m' % ((end-start)/60))
    9711004        filename, extension = os.path.splitext(export_file)
    972         os.system('zip %s %s' % (filename,export_file))
    973         os.system('rm %s' % (export_file))
    974         msg = "finished wrote %(total)d records to %(filename)s.zip" % vars()
     1005        from subprocess import call
     1006        msg = "wrote %(total)d records to %(export_file)s" % vars()
     1007        try:
     1008            retcode = call('gzip %s' % (export_file),shell=True)
     1009            if retcode == 0:
     1010                msg = "wrote %(total)d records to %(export_file)s.gz" % vars()
     1011        except OSError, e:
     1012            retcode = -99
     1013            logger.info("zip failed with %s" % e)
    9751014        logger.info(msg)
    9761015        args = {'portal_status_message': msg}
    977         #url = self.REQUEST.get('URL1') + '?' + urlencode(args)
    978         url = self.REQUEST.get('URL1')
     1016        #url = self.REQUEST.get('URL1') + '?' + urlencode(args) 
     1017        url = self.REQUEST.get('URL2')
    9791018        return self.REQUEST.RESPONSE.redirect(url)
    9801019    ###)
Note: See TracChangeset for help on using the changeset viewer.