def Run(problem_id): problem = db.Read_Problem(problem_id) args = request.args page = int(args['page']) if 'page' in args else 1 order = args['order'] if 'order' in args else 'time_usage' submissions = db.Read_Submissions({ 'problem_id': problem_id, 'status': 10 }, order) submission_shown = [] counted = {} for submission in submissions: if counted.get(submission[11]) != None: continue counted[submission[11]] = 1 submission_shown.append(submission) submission_shown_inpage, total_page = modules.Page_Split( submission_shown, page, status_per_page, lambda status: True) return render_template('problem_ranklist.html', problem=problem, submissions=submission_shown_inpage, total_page=total_page, current_page=page)
def Contestadd(req): id = 1 count = int(db.Fetchone('SELECT COUNT(*) FROM contests')[0]) if count > 0: id = int(db.Fetchone('SELECT MAX(id) FROM contests')[0]) + 1 req_problems = req['problems'].split(',') problems = [] for problem in req_problems: if db.Read_Problem(problem) == None: flash(r'题目#%s不存在' % problem, 'error') return modules.Page_Back() problems.append({'id': int(problem)}) try: begin_time = datetime.datetime.strptime(req['begin_time'], date_format) end_time = datetime.datetime.strptime(req['end_time'], date_format) except: flash(r'日期格式不对. 应为 yyyy-mm-dd HH:MM:SS', 'error') return modules.Page_Back() db.Execute('INSERT INTO contests VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', (id, req['title'], req['subtitle'], req['begin_time'], req['end_time'], req['description'], '{"type":"oi-intoj"}', request.cookies['username'], json.dumps(problems), '')) flash('添加成功', 'ok') return redirect('/contest/%d' % id)
def Init_Judge(): global problem, time_limit, memory_limit problem = db.Read_Problem(record['problem_id']) time_limit = problem['time_limit'] memory_limit = problem['memory_limit'] with open(cpppath, "w") as f: f.write(record['code'])
def Get(id): record = db.Read_Record(id) if record == None: flash(r'### 提交记录R%d没找着! \n 可能是因为编号不对.' % id, 'error') return redirect('/status') if record[12]: end_time = datetime.datetime.strptime( db.Read_Contest(record[12])[4], '%Y-%m-%d %H:%M:%S') now_time = datetime.datetime.now() if now_time < end_time: if request.cookies['username'] != record[ 11] and not modules.Current_User_Privilege(3): flash(r'这是比赛时的提交, 您无权查看', 'error') return modules.Page_Back() elif not db.Read_Problem( record[1])[9] and not modules.Current_User_Privilege( 2) and record[11] != modules.Current_User(): flash(r'该题目尚未公开, 您无权查看', 'error') return modules.Page_Back() result = json.loads(record[7]) subtasks = result['subtasks'] contest = db.Read_Contest(record[12]) if record[12] else None return render_template('record.html', record=record, subtasks=subtasks, contest=contest)
def Run(): args = dict(request.args) if args.get('contest_id') == None: args['contest_id'] = 0 page = int(request.args['page']) if 'page' in args else 1 statuslist = db.Read_Submissions(args) status_show, total_page = modules.Page_Split( statuslist, page, status_per_page, lambda status: status[11] == modules.Current_User() or modules. Current_User_Privilege(2) or db.Read_Problem(status[1])[9]) if args['contest_id'] == 0: return render_template('status.html', statuslist=status_show, total_page=total_page, current_page=page, contest=None, contest_id=0) else: contest_id = args['contest_id'] contest = db.Read_Contest(contest_id) return render_template('status.html', statuslist=status_show, total_page=total_page, current_page=page, contest=contest, contest_id=contest_id)
def Run(id): contest = db.Read_Contest(id) if contest == None: flash('不存在的比赛', 'error') return modules.Page_Back() problem_list = json.loads(contest[8]) problems = [db.Read_Problem(problem['id']) for problem in problem_list] rule_name = json.loads(contest[6])['type'] return render_template('contest.html', contest=contest, problems=problems, rule_name=rule_name)
def Run(origin_id): if not modules.Current_User_Privilege(2): flash(r'无此权限', 'error') return modules.Page_Back() problem = db.Read_Problem(origin_id) if problem == None: flash(r'### 题目 P%d 没找着! \n 可能是因为编号不对.' % origin_id, 'error') return modules.Page_Back() if request.method == 'GET': return render_template("problemedit.html", problem=problem) else: return Change(origin_id, request.form)
def Run(problem_id): problem = db.Read_Problem(problem_id) if problem == None: flash(r'### 题目 P%d 没找着! \n 可能是因为编号不对.' % problem_id, 'error') return modules.Page_Back() if not problem[9] and not modules.Current_User_Privilege(2): flash(r'无此权限', 'error') return modules.Page_Back() if request.method == 'GET': return render_template('problem.html', problem=problem) else: return newsubmit.Submit(problem_id, request.form)
def Is_Exist(contest_id, problem_id): contest = db.Read_Contest(contest_id) if contest == None: flash('不存在的比赛', 'error') return 0, modules.Page_Back() begin_time = datetime.datetime.strptime(contest[3], '%Y-%m-%d %H:%M:%S') if begin_time > datetime.datetime.now(): flash('比赛还未开始', 'error') return 0, modules.Page_Back() problem = db.Read_Problem(problem_id) if problem == None: flash('题目 P%d 没找着!' % problem_id, 'error') return 0, modules.Page_Back() return 1, (problem, contest)
def Run(contest_id): contest = db.Read_Contest(contest_id) if contest == None: flash('不存在的比赛', 'error') return modules.Page_Back() problems = json.loads(contest[8]) problems = list(map(lambda x: db.Read_Problem(x['id']), problems)) # print(problems) problems.sort(key=lambda x: x[0]) ranklist = db.Read_Contest_Ranklist(contest_id) if ranklist == None: return render_template('contest_ranklist.html', contest=contest, ranklist=None) def Loadjson(x): x = list(x) if x[3] == '': x[3] = {'score': 0, 'submit_cnt': 0} return x x[3] = json.loads(x[3]) score = submit_cnt = 0 for problem_id_str, results in x[3].items(): problem_id = int(problem_id_str) score += results['score'] submit_cnt += results['submit_cnt'] x[3]['score'] = score x[3]['submit_cnt'] = submit_cnt return x ranklist = list(map(Loadjson, ranklist)) ranklist.sort(key=lambda x: (-x[3]['score'], x[3]['submit_cnt'])) length = len(ranklist) for i in range(length): if i != 0 and ranklist[i][3]['score'] == ranklist[ i - 1][3]['score'] and ranklist[i][3]['submit_cnt'] == ranklist[ i - 1][3]['submit_cnt']: ranklist[i][3]['rank'] = ranklist[i - 1][3]['rank'] else: ranklist[i][3]['rank'] = i + 1 return render_template('contest_ranklist.html', contest=contest, ranklist=ranklist, problems=problems, full_score=len(problems) * 100)
def Run(problem_id): problem = db.Read_Problem(problem_id) submissions = db.Read_Submissions({'problem_id': problem_id}) score_count = {} status_count = [0 for i in range(12)] for submission in submissions: if submission[12] != 0: continue status_count[submission[4]] += 1 if submission[4] >= 4: score_count[submission[5]] = 1 if submission[ 5] not in score_count else score_count[submission[5]] + 1 score_count = sorted(score_count.items()) return render_template('problem_statistic.html', problem=problem, score_count=score_count, status_count=status_count)
def Run(contest_id): contest = db.Read_Contest(contest_id) submissions = db.Read_Submissions({'contest_id': contest_id}) groups = {} for submission in submissions: user = db.Read_User_Byname(submission[11]) group = user[7] if group == None or group.strip() == '': continue if groups.get(group) == None: groups[group] = { 'tot_score_all': 0, 'tot_submit_all': 0, 'average_score_all': 0, 'tot_score_finally': 0, 'tot_submit_finally': 0, 'average_score_finally': 0 } groups[group]['tot_score_all'] += submission[5] groups[group]['tot_submit_all'] += 1 groups[group]['average_score_all'] = round( groups[group]['tot_score_all'] / groups[group]['tot_submit_all'], 2) overall = { 'tot_submit_all': 0, 'tot_score_all': 0, 'average_score_all': 0, 'status_cnt_all': [0 for i in range(13)], 'score_count_all': {}, 'tot_submit_finally': 0, 'tot_score_finally': 0, 'average_score_finally': 0, 'status_cnt_finally': [0 for i in range(13)], 'score_count_finally': {} } problems = {} for submission in submissions: if submission[4] <= 3: continue problem = db.Read_Problem(submission[1]) if problem == None: continue problem_id = problem[0] if problems.get(problem_id) == None: problems[problem_id] = { 'tot_submit_all': 0, 'tot_score_all': 0, 'average_score_all': 0, 'status_cnt_all': [0 for i in range(13)], 'score_count_all': {}, 'tot_submit_finally': 0, 'tot_score_finally': 0, 'average_score_finally': 0, 'status_cnt_finally': [0 for i in range(13)], 'score_count_finally': {}, 'name': problem[1] } problems[problem_id]['tot_submit_all'] += 1 problems[problem_id]['tot_score_all'] += submission[5] problems[problem_id]['status_cnt_all'][submission[4]] += 1 problems[problem_id]['average_score_all'] = round( problems[problem_id]['tot_score_all'] / problems[problem_id]['tot_submit_all'], 2) problems[problem_id]['score_count_all'][ submission[5]] = 1 if submission[5] not in problems[problem_id][ 'score_count_all'] else problems[problem_id][ 'score_count_all'][submission[5]] + 1 overall['tot_submit_all'] += 1 overall['tot_score_all'] += submission[5] overall['status_cnt_all'][submission[4]] += 1 overall['average_score_all'] = round( overall['tot_score_all'] / overall['tot_submit_all'], 2) overall['score_count_all'][ submission[5]] = 1 if submission[5] not in overall[ 'score_count_all'] else overall['score_count_all'][ submission[5]] + 1 overall['score_count_all'] = sorted(overall['score_count_all'].items()) problems = dict(sorted(problems.items(), key=operator.itemgetter(0))) players = db.Read_Contest_Ranklist(contest_id) for player in players: details = json.loads(player[3]) for problem_id, detail in details.items(): problem_id = int(problem_id) if problems.get(problem_id) == None: continue record = db.Read_Record(detail['record_id']) if record == None: continue if record[4] <= 3: continue problems[problem_id]['tot_submit_finally'] += 1 problems[problem_id]['tot_score_finally'] += record[5] problems[problem_id]['status_cnt_finally'][record[4]] += 1 problems[problem_id]['average_score_finally'] = round( problems[problem_id]['tot_score_finally'] / problems[problem_id]['tot_submit_finally'], 2) problems[problem_id]['score_count_finally'][ record[5]] = 1 if record[5] not in problems[problem_id][ 'score_count_finally'] else problems[problem_id][ 'score_count_finally'][record[5]] + 1 for problem_id, detail in details.items(): record = db.Read_Record(detail['record_id']) if record == None: continue if record[4] <= 3: continue user = db.Read_User_Byname(player[1]) group = user[7] if group == None or group.strip() == '': continue if groups.get(group) == None: continue groups[group]['tot_submit_finally'] += 1 groups[group]['tot_score_finally'] += record[5] groups[group]['average_score_finally'] = round( groups[group]['tot_score_finally'] / groups[group]['tot_submit_finally'], 2) for problem_id, detail in details.items(): record = db.Read_Record(detail['record_id']) if record == None: continue if record[4] <= 3: continue overall['tot_submit_finally'] += 1 overall['tot_score_finally'] += record[5] overall['status_cnt_finally'][record[4]] += 1 overall['average_score_finally'] = round( overall['tot_score_finally'] / overall['tot_submit_finally'], 2) overall['score_count_finally'][ record[5]] = 1 if record[5] not in overall[ 'score_count_finally'] else overall['score_count_finally'][ record[5]] + 1 overall['score_count_finally'] = sorted( overall['score_count_finally'].items()) for problem_id in problems.keys(): problems[problem_id]['score_count_all'] = sorted( problems[problem_id]['score_count_all'].items()) problems[problem_id]['score_count_finally'] = sorted( problems[problem_id]['score_count_finally'].items()) return render_template('contest_statistic.html', contest=contest, groups=groups, problems=problems, overall=overall)