예제 #1
0
def Submissions_All(contest_id):
    try:
        page = int(request.args['page'])
    except:
        page = 1

    contest = db.Read_Contest(contest_id)
    if contest == None:
        flash(r'不存在的比赛', 'error')
        return modules.Page_Back()

    limitations = request.args.to_dict()
    limitations['contest_id'] = contest_id
    submissions = db.Read_Submissions(limitations)

    status_show, total_page = modules.Page_Split(submissions, page,
                                                 status_per_page,
                                                 lambda status: True)

    return render_template('status.html',
                           statuslist=status_show,
                           total_page=total_page,
                           current_page=page,
                           contest=contest,
                           contest_id=contest_id,
                           my=False)
예제 #2
0
def Submissions_My(contest_id):
    try:
        page = int(request.args['page'])
    except:
        page = 1

    if not modules.Is_Loggedin():
        flash(r'请先登录', 'error')
        return modules.Page_Back()

    contest = db.Read_Contest(contest_id)
    if contest == None:
        flash(r'不存在的比赛', 'error')
        return modules.Page_Back()

    limitations = request.args.to_dict()
    limitations['contest_id'] = contest_id
    limitations['username'] = modules.Current_User()
    submissions = db.Read_Submissions(limitations)
    status_show, total_page = modules.Page_Split(submissions, page,
                                                 status_per_page,
                                                 lambda status: True)
    return render_template('status.html',
                           statuslist=status_show,
                           total_page=total_page,
                           current_page=page,
                           contest=contest,
                           contest_id=contest_id,
                           my=True)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
def Run():
    page = int(request.args['page']) if 'page' in request.args else 1

    problemlist = db.Read_Problemlist()

    can_view_hidden = modules.Current_User_Privilege(2)
    problem_show, total_page = modules.Page_Split(
        problemlist, page, problem_per_page,
        lambda problem: problem[9] or can_view_hidden)

    submitted_status = {}
    if modules.Is_Loggedin():

        def Better(new, before):
            if new[4] != before[4]: return new[4] > before[4]
            if new[5] != before[5]: return new[5] > before[5]
            if new[8] != before[8]: return new[8] < before[8]
            if new[9] != before[9]: return new[9] < before[9]
            if new[0] != before[0]: return new[0] > before[0]
            return False

        submissions = db.Read_Submissions(
            {'username': request.cookies['username']}, 'id ASC')
        for submission in submissions:
            problem_id = submission[1]
            if problem_id not in submitted_status or Better(
                    submission, submitted_status[problem_id]):
                submitted_status[problem_id] = submission

    return render_template('problemlist.html',
                           problemlist=problem_show,
                           submitted_status=submitted_status,
                           current_page=page,
                           total_page=total_page)
def Total_Ac_Submit_Recalculate(username):
	print('Updating user %s'%username)
	total_ac = total_submit = 0
	ac_set = set()
	submissions = db.Read_Submissions({'username':username})
	for submission in submissions:
		status = submission['status']
		problem_id = submission['problem_id']
		total_submit += 1
		if status == 10:
			ac_set.add(problem_id)
	total_ac = len(ac_set)
	ac_list = json.dumps(list(ac_set))
	db.Execute('UPDATE users SET total_ac=%s, total_submit=%s, ac_list=%s WHERE username=%s',(total_ac,total_submit,ac_list,username))
예제 #7
0
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)
예제 #8
0
def Contest_Players_Recalculate(contest_id):
    print('Recalculating Contest %d...' % contest_id)
    db.Execute('DELETE FROM contest_players WHERE contest_id=%s', contest_id)
    contest = db.Read_Contest(contest_id)
    submissions = list(db.Read_Submissions({'contest_id': contest_id}))
    submissions.sort(key=lambda x: x[0])
    details = {}
    for submission in submissions:
        if submission[4] <= 3: continue
        username = submission[11]
        if details.get(username) == None: details[username] = {}
        problem_id = submission[1]
        details[username][problem_id] = {
            'record_id':
            submission[0],
            'score':
            modules.Toint(submission[5]),
            'submit_cnt':
            1 if details[username].get(problem_id) == None else
            details[username][problem_id]['submit_cnt'] + 1
        }
    for username, detail in details.items():
        db.Execute('INSERT INTO contest_players VALUES(NULL,%s,%s,%s)',
                   (username, contest_id, json.dumps(detail)))
예제 #9
0
def User_Statistic(username):
	submissions = db.Read_Submissions({'username':username})
	status_cnt = [ 0 for i in range(13) ]
	for submission in submissions:
		status_cnt[submission['status']] += 1
	return status_cnt
예제 #10
0
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)