Exemplo n.º 1
0
Arquivo: models.py Projeto: YLAsce/oj
    def addCourseClass(cls, course, admin, name, year):
        """
        to add CourseClass
        """
        course_class = CourseClass()
        course_class.course = course
        course_class.admin = admin
        course_class.name = name
        course_class.year = year
        course_class.save()

        flush_transaction()

        return course_class.id
Exemplo n.º 2
0
    def addCourseClass(cls, course, admin, name, year):
        """
        to add CourseClass
        """
        course_class = CourseClass()
        course_class.course = course
        course_class.admin = admin
        course_class.name = name
        course_class.year = year
        course_class.save()

        flush_transaction()

        return course_class.id
Exemplo n.º 3
0
    def rejudgeSubmission(cls, s, no_judge=False):
        """
        func used to rejudge the very submission
        """

        # no need to handle exception?
        # or exception transmission?
        try:
            if no_judge == True:
                s.status = 'Accepted'
                s.save()
                return True
            info = eval(s.other_info)
            s.status = 'Rejudging'
            info['status'] = s.status
            s.run_time = 0
            info['run_time'] = str(s.run_time)
            s.run_memory = 0
            info['run_memory'] = str(s.run_memory)
            s.other_info = str(info)

            # for scoring
            info['score'] = str(0)

            s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(
                        _sid=s.sid,
                        _pid=s.problem_index.problem_id,
                        _lang=s.code_language,
                        _mode='contest',
                        _code_path=s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return True

        except:
            raise
Exemplo n.º 4
0
    def rejudgeGeneralSubmission(cls, g_s):
        """
        func used to rejudge the very general submission
        """

        # no need to handle exception?
        # or exception transmission?

        try:
            info = eval(g_s.other_info)
            g_s.status = 'Rejudging'
            info['status'] = g_s.status
            g_s.run_time = 0
            info['run_time'] = str(g_s.run_time)
            g_s.run_memory = 0
            info['run_memory'] = str(g_s.run_memory)

            info['score'] = str(0)

            g_s.other_info = str(info)

            g_s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(_sid=g_s.id,
                                                    _pid=g_s.problem_id,
                                                    _lang=g_s.code_language,
                                                    _mode='general',
                                                    _code_path=g_s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return True

        except:
            raise
Exemplo n.º 5
0
    def rejudgeSubmission(cls, s, no_judge = False):
        """
        func used to rejudge the very submission
        """

        # no need to handle exception?
        # or exception transmission?
        try:
            if no_judge == True:
                s.status = 'Accepted'
                s.save()
                return True
            info = eval(s.other_info)
            s.status = 'Rejudging'
            info['status'] = s.status
            s.run_time = 0
            info['run_time'] = str(s.run_time)
            s.run_memory = 0
            info['run_memory'] = str(s.run_memory)
            s.other_info = str(info)

            # for scoring
            info['score'] = str(0)

            s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(_sid= s.sid, _pid= s.problem_index.problem_id, _lang= s.code_language,
                            _mode='contest', _code_path=s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return True

        except:
            raise
Exemplo n.º 6
0
Arquivo: models.py Projeto: YLAsce/oj
    def rejudgeGeneralSubmission( cls, g_s):
        """
        func used to rejudge the very general submission
        """

        # no need to handle exception?
        # or exception transmission?

        try:
            info = eval(g_s.other_info)
            g_s.status = 'Rejudging'
            info['status'] = g_s.status
            g_s.run_time = 0
            info['run_time'] = str(g_s.run_time)
            g_s.run_memory = 0
            info['run_memory'] = str(g_s.run_memory)

            info['score'] = str(0)

            g_s.other_info = str(info)

            g_s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(_sid= g_s.id, _pid= g_s.problem_id, _lang= g_s.code_language,
                            _mode='general', _code_path=g_s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return True

        except:
            raise
Exemplo n.º 7
0
Arquivo: models.py Projeto: YLAsce/oj
    def addSubmission( cls, user = None, problem_index = None, code_file_path = '', code_language = '', code_length = 0, ad_info = {}):
        """
        add Submission, with user, problem_index( combined with contest and problem_id), data_count, code_file_path, code_language, code_length
        ( now general submission is handled in another model)
        """
        # use instances as params to omit the validation, cause validation has been done in vies
        # we should add validator in views module

        try:
            s = Submission()
            other_info = ad_info.copy()

            s.user = user # user.submission_set.add may also be okay
            other_info['username'] = s.user.username

            s.problem_index = problem_index
            other_info['pid'] = s.problem_index.problem_id
            other_info['cid'] = s.problem_index.contest_id

            s.status = 'Pending'
            other_info['status'] = s.status

            s.data_cnt = s.problem_index.problem.data_count
            other_info['data_cnt'] = str(s.data_cnt)

            s.code_language = code_language
            other_info['code_language'] = code_language

            s.code_length = code_length
            other_info['code_length'] = str(code_length)

            s.run_time = 0
            other_info['run_time'] = str(s.run_time)
            s.run_memory = 0
            other_info['run_memory'] = str(s.run_memory)

            # for scoring
            other_info['score'] = str(0)

            s.other_info = str(other_info)

            s.submission_time = datetime.now()

            s.save()
            flush_transaction()

            import os
            true_addr = os.path.join( Const.SUBMISSION_CODE_PATH, str(s.sid))
            if default_storage.exists( true_addr): # bugs came out as versions updated
                default_storage.delete( true_addr)

            default_storage.save( true_addr, default_storage.open(code_file_path))
            # the second param is a FILE object or its subclass
            default_storage.delete( code_file_path)
            s.code_file = true_addr

            other_info = eval(s.other_info)
            other_info['code_file_path'] = s.code_file

            # cause we don't have it at former time
            other_info['submit_time'] = str(s.submission_time)

            s.other_info = str(other_info)

            s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(_sid= s.sid, _pid= s.problem_index.problem_id, _lang= s.code_language,
                            _mode='contest', _code_path=s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return s.sid

        except:
            raise
Exemplo n.º 8
0
Arquivo: models.py Projeto: YLAsce/oj
    def updateGeneralSubmission( cls, gsid, judge_info):
        """
        called by JudgeQueue
        save dict in other_info as str
        """

        try:
            s = cls.getById( gsid)

            print judge_info
            s.status = SUB_STATUS[judge_info['status']]
            #s.status = 'Accepted'

#debug 
            #s.save()
            #flush_transaction()

            info = eval( s.other_info)

            if s.status == 'Init':
                s.status = 'System Error'
                s.run_time = 0
                s.run_memory = 0
                info['run_time'] = str(s.run_time)
                info['run_memory'] = str(s.run_memory)
                info['case_judged'] = str(0)
                info['score'] = str(0)

            elif s.status == 'Compile Error':
                s.run_time = 0
                s.run_memory = 0
                info['run_time'] = str(s.run_time)
                info['run_memory'] = str(s.run_memory)
                info['ce'] = judge_info['ce']
                info['case_judged'] = str(0) 
                info['score'] = str(0)

            elif s.status != 'Compiling' and s.status != 'Judging':
                s.run_time = judge_info['time']
                s.run_memory = judge_info['mem']
                info['run_time'] = str(s.run_time)
                info['run_memory'] = str(s.run_memory)

                s.status = 'Judging'
                seq = []
                jd_cnt = 0
                case_dict = json.loads(s.problem.case_info)
                temp_score = 0

                for seq_res in judge_info['case_res']:
                    if jd_cnt >= judge_info['case_done']:
                        break

                    if seq_res['res'] == 're':
                        s.status = JUDGE_RES['re']
                    elif seq_res['res'] == 'mle':
                        s.status = JUDGE_RES['mle']
                    elif seq_res['res'] == 'tle':
                        s.status = JUDGE_RES['tle']
                    elif seq_res['res'] == 'wa':
                        s.status = JUDGE_RES['wa']
                    elif seq_res['res'] == 'pe':
                        s.status = JUDGE_RES['pe']
                    elif seq_res['res'] == 'ole':
                        s.status = JUDGE_RES['ole']

                    if seq_res['res'] == 'ac':
                        if not case_dict[str(jd_cnt)].isdigit():
                            raise Exception( "Invalid Score")
                        temp_score += int(case_dict[str(jd_cnt)])
                        seq_res['score'] = case_dict[str(jd_cnt)]

                    seq.append(seq_res)
                    jd_cnt += 1

                info['case_judged'] = judge_info['case_done']
                info['case_result'] = seq
                info['score'] = str(temp_score)
                if s.status == 'Judging':
                    s.status = 'Accepted'

            info['status'] = s.status

            s.other_info = str( info)
            s.save() # without such sentence, no data modification will be updated
            flush_transaction()

            return True

        except:
            raise
Exemplo n.º 9
0
Arquivo: models.py Projeto: YLAsce/oj
    def addGeneralSubmission( cls, user = None, problem = None, code_file_path = '', code_language = '', code_length = 0):
        """
        add GeneralSubmission, with user, problem, data_count, code_file_path, code_language, code_length
        """
        # use instances as params to omit the validation, cause validation has been done in vies
        # we should add validator in views module

        try:
            g_s = GeneralSubmission()
            other_info = {}
            g_s.user = user # user.submission_set.add may also be okay
            other_info['username'] = g_s.user.username

            g_s.problem = problem
            other_info['pid'] = g_s.problem_id

            g_s.status = 'Pending'
            other_info['status'] = g_s.status

            g_s.data_cnt = g_s.problem.data_count
            other_info['data_cnt'] = str(g_s.data_cnt)

            g_s.code_language = code_language
            other_info['code_language'] = g_s.code_language

            g_s.code_length = code_length
            other_info['code_length'] = str(g_s.code_length)

            g_s.run_time = 0
            other_info['run_time'] = str(g_s.run_time)
            g_s.run_memory = 0
            other_info['run_memory'] = str(g_s.run_memory)

            other_info['score'] = str(0)

            g_s.other_info = str(other_info)

            g_s.submission_time = datetime.now()

            g_s.save()
            flush_transaction()

            import os
            true_addr = os.path.join( Const.GENERAL_SUBMISSION_CODE_PATH, str(g_s.id))
            if default_storage.exists( true_addr): # bugs came out as versions updated
                default_storage.delete( true_addr)

            default_storage.save( true_addr, default_storage.open(code_file_path))
            # the second param is a FILE object or its subclass
            default_storage.delete( code_file_path)
            g_s.code_file = true_addr

            other_info = eval(g_s.other_info)
            other_info['code_file_path'] = g_s.code_file

            # cause we don't have it at former time
            other_info['submit_time'] = str(g_s.submission_time)

            g_s.other_info = str(other_info)

            g_s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(_sid= g_s.id, _pid= g_s.problem_id, _lang= g_s.code_language,
                            _mode='general', _code_path=g_s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return g_s.id

        except:
            raise
Exemplo n.º 10
0
    def addSubmission(cls,
                      user=None,
                      problem_index=None,
                      code_file_path='',
                      code_language='',
                      code_length=0,
                      ad_info={}):
        """
        add Submission, with user, problem_index( combined with contest and problem_id), data_count, code_file_path, code_language, code_length
        ( now general submission is handled in another model)
        """
        # use instances as params to omit the validation, cause validation has been done in vies
        # we should add validator in views module

        try:
            s = Submission()
            other_info = ad_info.copy()

            s.user = user  # user.submission_set.add may also be okay
            other_info['username'] = s.user.username

            s.problem_index = problem_index
            other_info['pid'] = s.problem_index.problem_id
            other_info['cid'] = s.problem_index.contest_id

            s.status = 'Pending'
            other_info['status'] = s.status

            s.data_cnt = s.problem_index.problem.data_count
            other_info['data_cnt'] = str(s.data_cnt)

            s.code_language = code_language
            other_info['code_language'] = code_language

            s.code_length = code_length
            other_info['code_length'] = str(code_length)

            s.run_time = 0
            other_info['run_time'] = str(s.run_time)
            s.run_memory = 0
            other_info['run_memory'] = str(s.run_memory)

            # for scoring
            other_info['score'] = str(0)

            s.other_info = str(other_info)

            s.submission_time = datetime.now()

            s.save()
            flush_transaction()

            import os
            true_addr = os.path.join(Const.SUBMISSION_CODE_PATH, str(s.sid))
            if default_storage.exists(
                    true_addr):  # bugs came out as versions updated
                default_storage.delete(true_addr)

            default_storage.save(true_addr,
                                 default_storage.open(code_file_path))
            # the second param is a FILE object or its subclass
            default_storage.delete(code_file_path)
            s.code_file = true_addr

            other_info = eval(s.other_info)
            other_info['code_file_path'] = s.code_file

            # cause we don't have it at former time
            other_info['submit_time'] = str(s.submission_time)

            s.other_info = str(other_info)

            s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(
                        _sid=s.sid,
                        _pid=s.problem_index.problem_id,
                        _lang=s.code_language,
                        _mode='contest',
                        _code_path=s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return s.sid

        except:
            raise
Exemplo n.º 11
0
    def updateGeneralSubmission(cls, gsid, judge_info):
        """
        called by JudgeQueue
        save dict in other_info as str
        """

        try:
            s = cls.getById(gsid)

            print judge_info
            s.status = SUB_STATUS[judge_info['status']]
            #s.status = 'Accepted'

            #debug
            #s.save()
            #flush_transaction()

            info = eval(s.other_info)

            if s.status == 'Init':
                s.status = 'System Error'
                s.run_time = 0
                s.run_memory = 0
                info['run_time'] = str(s.run_time)
                info['run_memory'] = str(s.run_memory)
                info['case_judged'] = str(0)
                info['score'] = str(0)

            elif s.status == 'Compile Error':
                s.run_time = 0
                s.run_memory = 0
                info['run_time'] = str(s.run_time)
                info['run_memory'] = str(s.run_memory)
                info['ce'] = judge_info['ce']
                info['case_judged'] = str(0)
                info['score'] = str(0)

            elif s.status != 'Compiling' and s.status != 'Judging':
                s.run_time = judge_info['time']
                s.run_memory = judge_info['mem']
                info['run_time'] = str(s.run_time)
                info['run_memory'] = str(s.run_memory)

                s.status = 'Judging'
                seq = []
                jd_cnt = 0
                case_dict = json.loads(s.problem.case_info)
                temp_score = 0

                for seq_res in judge_info['case_res']:
                    if jd_cnt >= judge_info['case_done']:
                        break

                    if seq_res['res'] == 're':
                        s.status = JUDGE_RES['re']
                    elif seq_res['res'] == 'mle':
                        s.status = JUDGE_RES['mle']
                    elif seq_res['res'] == 'tle':
                        s.status = JUDGE_RES['tle']
                    elif seq_res['res'] == 'wa':
                        s.status = JUDGE_RES['wa']
                    elif seq_res['res'] == 'pe':
                        s.status = JUDGE_RES['pe']
                    elif seq_res['res'] == 'ole':
                        s.status = JUDGE_RES['ole']

                    if seq_res['res'] == 'ac':
                        if not case_dict[str(jd_cnt)].isdigit():
                            raise Exception("Invalid Score")
                        temp_score += int(case_dict[str(jd_cnt)])
                        seq_res['score'] = case_dict[str(jd_cnt)]

                    seq.append(seq_res)
                    jd_cnt += 1

                info['case_judged'] = judge_info['case_done']
                info['case_result'] = seq
                info['score'] = str(temp_score)
                if s.status == 'Judging':
                    s.status = 'Accepted'

            info['status'] = s.status

            s.other_info = str(info)
            s.save(
            )  # without such sentence, no data modification will be updated
            flush_transaction()

            return True

        except:
            raise
Exemplo n.º 12
0
    def addGeneralSubmission(cls,
                             user=None,
                             problem=None,
                             code_file_path='',
                             code_language='',
                             code_length=0):
        """
        add GeneralSubmission, with user, problem, data_count, code_file_path, code_language, code_length
        """
        # use instances as params to omit the validation, cause validation has been done in vies
        # we should add validator in views module

        try:
            g_s = GeneralSubmission()
            other_info = {}
            g_s.user = user  # user.submission_set.add may also be okay
            other_info['username'] = g_s.user.username

            g_s.problem = problem
            other_info['pid'] = g_s.problem_id

            g_s.status = 'Pending'
            other_info['status'] = g_s.status

            g_s.data_cnt = g_s.problem.data_count
            other_info['data_cnt'] = str(g_s.data_cnt)

            g_s.code_language = code_language
            other_info['code_language'] = g_s.code_language

            g_s.code_length = code_length
            other_info['code_length'] = str(g_s.code_length)

            g_s.run_time = 0
            other_info['run_time'] = str(g_s.run_time)
            g_s.run_memory = 0
            other_info['run_memory'] = str(g_s.run_memory)

            other_info['score'] = str(0)

            g_s.other_info = str(other_info)

            g_s.submission_time = datetime.now()

            g_s.save()
            flush_transaction()

            import os
            true_addr = os.path.join(Const.GENERAL_SUBMISSION_CODE_PATH,
                                     str(g_s.id))
            if default_storage.exists(
                    true_addr):  # bugs came out as versions updated
                default_storage.delete(true_addr)

            default_storage.save(true_addr,
                                 default_storage.open(code_file_path))
            # the second param is a FILE object or its subclass
            default_storage.delete(code_file_path)
            g_s.code_file = true_addr

            other_info = eval(g_s.other_info)
            other_info['code_file_path'] = g_s.code_file

            # cause we don't have it at former time
            other_info['submit_time'] = str(g_s.submission_time)

            g_s.other_info = str(other_info)

            g_s.save()
            flush_transaction()

            sent_to_queue = False
            while not sent_to_queue:
                try:
                    Core.tasks.JudgeQueue.sendJudge(_sid=g_s.id,
                                                    _pid=g_s.problem_id,
                                                    _lang=g_s.code_language,
                                                    _mode='general',
                                                    _code_path=g_s.code_file)
                    sent_to_queue = True
                except Exception as e:
                    print str(e)

            return g_s.id

        except:
            raise