Esempio n. 1
0
 def submit(self):
     if self.submission.retry_count > 10:
         return
     if self.submission.status == JudgeRequest.status['PENDING'] or \
             self.submission.status == JudgeRequest.status['SEND_FOR_JUDGE_ERROR']:
         account = self.choose_account(self.submission.problem.remote_oj)
         # print('account', account, self.submission.problem.remote_oj)
         if not account:
             self.retry()
             raise SubmissionException
         success_submit = Controller.submit_code(
             self.submission.problem.remote_oj,
             Account(username=account.username,
                     password=account.password), self.submission.source,
             self.submission.language, self.submission.problem.remote_id)
         # print('success_submit', success_submit)
         if success_submit:
             result = Controller.get_result(
                 self.submission.problem.remote_oj,
                 Account(username=account.username,
                         password=account.password),
                 self.submission.problem.remote_id)
             # print('result', result)
             # 结果返回有误
             if not result:
                 if self.submission.status == JudgeRequest.status[
                         'SEND_FOR_JUDGE_ERROR']:
                     self.submission.status = JudgeRequest.status['RETRY']
                 else:
                     self.submission.status = JudgeRequest.status[
                         'SEND_FOR_JUDGE_ERROR']
                 self.release_account(account.id)
                 self.retry()
                 raise Submission
             self.submission.remote_run_id = result.origin_run_id
             self.submission.judge_result = result.verdict
             self.submission.execute_memory = result.execute_memory
             self.submission.execute_time = result.execute_time
             self.submission.save()
             if self.waiting_for_judge():
                 print('submit_success')
                 self.update_statistic()
             else:
                 self.submission.status = JudgeRequest.status['RETRY']
                 self.release_account(account.id)
                 self.retry()
                 raise SubmissionException
         else:
             # 提交失败
             if self.submission.status == JudgeRequest.status[
                     'SEND_FOR_JUDGE_ERROR']:
                 self.submission.status = JudgeRequest.status['RETRY']
             else:
                 self.submission.status = JudgeRequest.status[
                     'SEND_FOR_JUDGE_ERROR']
                 self.retry()
             self.release_account(account.id)
             raise SubmissionException
         self.release_account(account.id)
Esempio n. 2
0
def submit():
    source_code = request.files['source_code']
    if request.form.get('remote_oj') and request.form.get('language') and request.form.get(
            'remote_id') and source_code:
        remote_oj = request.form['remote_oj']
        remote_id = request.form['remote_id']
        language = request.form['language']

        ans = False
        tries = 3
        print('start')
        account = Account('robot4test', 'robot4test')
        while ans is False and tries > 0:
            tries -= 1
            controller = Controller(str(remote_oj))
            ans = controller.submit_code(pid=remote_id, account=account,
                                         code=source_code.read(), language=language)
            account.set_cookies(controller.get_cookies())
        if ans is False:
            return "SUBMIT FAILED"
        controller = Controller(remote_oj)
        result = controller.get_result(account=account, pid=remote_id)
        account.set_cookies(controller.get_cookies())
        print('end')
        tries = 5
        while result.status == Result.Status.STATUS_RESULT and tries > 0:
            time.sleep(2)
            if Controller(remote_oj).is_waiting_for_judge(result.verdict):
                result = Controller(remote_oj).get_result_by_rid_and_pid(rid=result.origin_run_id,
                                                                         pid=remote_id)
            else:
                break
            tries -= 1

        if result.status == Result.Status.STATUS_RESULT:
            return str(result.__dict__)
        return result.status.name
    return "Error"