Example #1
0
    def doMatch(self, subtask):
        import rate_run
        rawResults = []
        timelimit = subtask['timelimit']
        memlimit = subtask['memlimit']
        matchEXE = os.path.join(WORKER_RATE_ROOT, subtask['matchEXE']).replace('/', os.path.sep)
        for tinytask in subtask['tinytasks']:
            u1 = tinytask['uuid1']
            u2 = tinytask['uuid2']
            f1 = tinytask['file1']#.replace('/', os.path.sep)
            f2 = tinytask['file2']#.replace('/', os.path.sep)
            f1 = "/".join((WORKER_RATE_ROOT, f1))
            f2 = "/".join((WORKER_RATE_ROOT, f2))
            rawResult = {}
            rawResult['uuid1'] = u1
            rawResult['uuid2'] = u2
            rawResult['match_type'] = tinytask['match_type']
            rawResult['result'] = 'failed'
            #cmd = '.\\rate_run.exe %s %s %s %s %s' % (str(timelimit), str(memlimit), matchEXE, f1, f2)
            cmd = '%s %s %s' % (matchEXE, f1, f2)
            #print cmd
#            cmdlogfile = open('./matchcmd-%d.log' % self.worker_num , 'a')
#            print>>cmdlogfile, cmd
#            cmdlogfile.close()

            try:
                (returncode, output) = rate_run.rate_run_main(int(timelimit), int(memlimit), str(cmd))
                #os.system("del *.tmp")
                #print type(output)
                #print output
                #p = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=open(os.devnull, "w"))
                #returncode = p.wait()
                if returncode != 0:
                    rawResult['result'] = 'failed'
                    #print 'returncode: %d' % returncode
                else:
                    score = output.strip()
                    #print "score string: %s" % score
                    score = float(score)
                    #print "score float: %f" % score
                    rawResult['result'] = 'ok'
                    rawResult['score'] = str(score)
            except Exception, e:
                print e
                traceback.print_exc()
                rawResult['result'] = 'failed'
            rawResults.append(rawResult)
Example #2
0
    def doEnroll(self, subtask):
        import rate_run
        enrollEXE = os.path.join(WORKER_RATE_ROOT, subtask['enrollEXE'])
        timelimit = subtask['timelimit']
        memlimit = subtask['memlimit']
        rawResults = []
        ftp = self.openUploadFTP(subtask)
        for tinytask in subtask['tinytasks']:
            u = tinytask['uuid']
            rawResult = { 'uuid': u,'result':'failed' }
            f = tinytask['file']
            self.checkFile(f)
            absImagePath = os.path.join(WORKER_RATE_ROOT, f).replace('/', os.path.sep)
            absTemplatePath = os.path.join(WORKER_RATE_ROOT,'temp',subtask['producer_uuid'][-12:],u[-12:-10], "%s.t" % u[-10:]).replace('/', os.path.sep)
            self.checkDir(os.path.dirname(absTemplatePath))
            #cmd = '.\\rate_run.exe %s %s %s %s %s' % (str(timelimit), str(memlimit), enrollEXE, absImagePath, absTemplatePath)
            cmd = '%s %s %s' % (enrollEXE, absImagePath, absTemplatePath)

#            cmdlogfile = open('./enrollcmd-%d.log' % self.worker_num, 'a')
#            print>>cmdlogfile, cmd
#            cmdlogfile.close()
            try:
                (returncode, output) = rate_run.rate_run_main(int(timelimit), int(memlimit), cmd)
#                print returncode
                if returncode == 0 and os.path.exists(absTemplatePath):
                    template_file = open(absTemplatePath, 'rb')
                    tried = 0
                    while True:
                        try:
                            ftp.storbinary('STOR ' + "%s/%s.t" % (u[-12:-10], u[-10:]), template_file)
                            break
                        except Exception, e:
                            print e
                            traceback.print_exc()
                            print "%d: upload: retry %d" % (self.worker_num, tried)
                            tried = tried + 1
                            ftp = self.openUploadFTP(subtask)
                    template_file.close()
                    rawResult['result'] = 'ok'
            except Exception, e:
                print e
                traceback.print_exc()
                rawResult['result'] = 'failed'
            rawResults.append(rawResult)
Example #3
0
 def doEnroll(self, subtask):
     import rate_run
     enrollEXE = os.path.join(WORKER_RATE_ROOT, subtask['enrollEXE'])
     timelimit = subtask['timelimit']
     memlimit = subtask['memlimit']
     rawResults = []
     ftp = self.openUploadFTP(subtask)
     for tinytask in subtask['tinytasks']:
         u = tinytask['uuid']
         rawResult = { 'uuid': u,'result':'failed' }
         f = tinytask['file']
         self.checkFile(f)
         absImagePath = os.path.join(WORKER_RATE_ROOT, f).replace('/', os.path.sep)
         absTemplatePath = os.path.join(WORKER_RATE_ROOT,'temp',subtask['producer_uuid'][-12:],u[-12:-10], "%s.t" % u[-10:]).replace('/', os.path.sep)
         self.checkDir(os.path.dirname(absTemplatePath))
         cmd = '%s %s %s' % (enrollEXE, absImagePath, absTemplatePath)
         rawResult['result'] = 'ok'
         try:
             start = time.clock()
             (returncode, output) = rate_run.rate_run_main(int(3000), int(memlimit), cmd)
             elapsed = int(100 * (time.clock() - start))
             if returncode == 0 and os.path.exists(absTemplatePath):
                 template_file = open(absTemplatePath, 'rb')
                 tried = 0
                 while True:
                     try:
                         ftp.storbinary('STOR ' + "%s.t" % (tinytask['uuid']), template_file)
                         print 'store', tinytask['uuid'], '.t from', absTemplatePath
                         break
                     except Exception, e:
                         print e
                         traceback.print_exc()
                         print "%d: upload: retry %d" % (self.worker_num, tried)
                         tried = tried + 1
                         ftp = self.openUploadFTP(subtask)
                         if tried == 16:
                             break
                 template_file.close()
                 rawResult['result'] = 'ok'
                 rawResult['time'] = str(elapsed)
             else:
                 print 'did not exit with 0 or did not create template file'
                 rawResult['result'] = 'failed'
Example #4
0
    def doMatch(self, subtask):
        import rate_run
        rawResults = []
        timelimit = subtask['timelimit']
        memlimit = subtask['memlimit']
        matchEXE = os.path.join(WORKER_RATE_ROOT, subtask['matchEXE']).replace('/', os.path.sep)

        block_no = subtask['block_no']
        for tinytask in subtask['tinytasks']:
            u1 = tinytask['uuid1']
            u2 = tinytask['uuid2']
            f1 = tinytask['file1']#.replace('/', os.path.sep)
            f2 = tinytask['file2']#.replace('/', os.path.sep)
            f1 = "/".join((WORKER_RATE_ROOT, f1))
            f2 = "/".join((WORKER_RATE_ROOT, f2))
            rawResult = {}
            rawResult['uuid1'] = u1
            rawResult['uuid2'] = u2
            rawResult['match_type'] = tinytask['match_type']

            cmd = '%s %s %s' % (matchEXE, f1, f2)

            try:
                start = time.clock()
                (returncode, output) = rate_run.rate_run_main(int(500), int(memlimit), str(cmd))
                elapsed = int(100 * (time.clock() - start))
                if returncode != 0:
                    rawResult['result'] = 'failed'
                else:
                    score = output.strip()
                    score = float(score)
                    rawResult['result'] = 'ok'
                    rawResult['score'] = str(score)
                    rawResult['time'] = str(elapsed)
            except Exception, e:
                print e
                traceback.print_exc()
                rawResult['result'] = 'failed'
            rawResults.append(rawResult)