コード例 #1
0
def test_case2():
    problem = ProblemRecored()
    problem_dict = {'code': '#include <stdio.h>\n int main(){ printf("\n"); }', 'lang': 'c', 'test_cases': [{'input': '1', 'output': '2'}, ], 'notify1': 'http://localhost/ok'}
    problem.updateProblem(problem_dict)

    otherProblem = ProblemRecored()
    otherProblem.fromString(problem.toString())
    print(otherProblem.toString())
    print(otherProblem.problem_judge_result_status_list)
    print(otherProblem.problem_judge_status_list)
コード例 #2
0
    def get_result_dict_by_problem_id(
            self, problem_id_str):  #This function is call by judge client
        if self.connection.exists(problem_id_str):
            record_string_in_redis = self.connection.get(problem_id_str)

            problem_record = ProblemRecored()
            problem_record.fromString(record_string_in_redis)
            result_dict = problem_record.getJudgeResult()
            return result_dict
        else:
            logger.error(
                'Problem \"{}\" not exist when call judgeclient_view.get_result_dict_by_problem_id() !'
                .format(problem_id_str))
            raise MessageException('The problem is not exist !')
コード例 #3
0
    def get_lang_extension_by_problem_id(self,
                                         problem_id_str):  ##to be continue
        #print("problem id:{}".format(problem_id_str))
        if self.connection.exists(problem_id_str):
            record_string_in_redis = self.connection.get(problem_id_str)

            problem_record = ProblemRecored()
            problem_record.fromString(record_string_in_redis)
            lang_extension_str = problem_record.getProblem()['lang']
            return lang_extension_str
            #return ProblemRecored.getLangExtensionNameById(int(problem_id))
        else:
            logger.critical(
                'Problem \"{}\" not exist ! Error happen in Database.get_lang_extension_by_problem_id()'
                .format(problem_id_str))
            raise MessageException(
                'Problem not exist when get its extension !')
コード例 #4
0
    def add_problem(self, problem_dict):
        # Add a problem into redis and return the dict for problem : {"problem_id":problem_id_str, "secret":secret}
        assert type(problem_dict) == dict

        if self._check_queue_is_full():
            raise QueueFullException("One of queue is full !")

        problem_id_str = self._get_unused_problem_id_str()
        secret = str(uuid4().hex)
        judge_dict = {
            'problem_id': problem_id_str,
            'secret': secret,
            'status': str(ProblemJudgeStatusEnum.waiting)
        }

        problem_record = ProblemRecored()
        problem_record.updateProblem(problem_dict)
        problem_record.updateJudge(judge_dict)

        self.connection.set(problem_id_str, problem_record.toString())
        self.connection.expire(
            problem_id_str,
            timedelta(minutes=30))  #record will expire at 1 hour later
        self._put_problem_id_into_unsolved_queue(problem_id_str)

        return {"problem_id": problem_id_str, "secret": secret}
コード例 #5
0
def test_case1():
    problem = ProblemRecored()
    print(problem.toString())
    #problem_dict = {'code': '#include <stdio.h>\n int main(){ printf("\n"); }', 'lang': 'c', 'test_cases': [{'input': '1', 'output': '2'}, ], 'notify': 'http://localhost/ok'}
    problem_dict = {'code': '#include <stdio.h>\n int main(){ printf("\n"); }', 'lang': 'c', 'test_cases': [{'input': '1', 'output': '2'}, ], 'notify1': 'http://localhost/ok'}
    problem.updateProblem(problem_dict)
    print(problem.toString())
コード例 #6
0
    def get_problem_judge_and_result_status(
        self, problem_id_str, secret
    ):  #web client use this to get the judge status of a given problem
        if self.connection.exists(problem_id_str):
            record_string_in_redis = self.connection.get(problem_id_str)

            problem_record = ProblemRecored()
            problem_record.fromString(record_string_in_redis)
            problem_judge = problem_record.getJudge()

            problem_secret = problem_judge["secret"]
            if secret != problem_secret:
                raise MessageException('Secret not match with is problem !')
            else:
                problem_record.data.pop(
                    'problem')  #return the ProblemRecord without problem field
                return problem_record.data
        else:
            self._remove_problem_from_queue_by_problem_id(problem_id_str)
            logger.error(
                'Problem \"{}\" not exist , delete from waiting and judging queue !'
                .format(problem_id_str))
            raise MessageException('The problem is not exist !')
コード例 #7
0
    def update_judge_status_by_problem_id(self, problem_id_str, judge_status):
        if self.connection.exists(problem_id_str):
            record_string_in_redis = self.connection.get(problem_id_str)

            problem_record = ProblemRecored()
            problem_record.fromString(record_string_in_redis)
            new_judge_dict = {'status': judge_status}
            problem_record.updateJudge(new_judge_dict)

            self.connection.set(problem_id_str, problem_record.toString())
            self.connection.expire(problem_id_str, timedelta(minutes=30))
        else:
            logger.error(
                'Problem \"{}\" not exist when call judgeclient_view.update_judge_status_by_problem_id() !'
                .format(problem_id_str))
            raise MessageException('The problem is not exist !')
コード例 #8
0
 def get_lang_id_by_by_problem_id(self, problem_id_str):  ##to be continue
     #print("problem id:{}".format(problem_id_str))
     lang_extension_str = self.get_lang_extension_by_problem_id(
         problem_id_str)
     return ProblemRecored.getLangIdByExtensionName(lang_extension_str)