Merge pull request #36 from zhaospei/master

Add resolver page
This commit is contained in:
Phuoc Dinh Le 2022-12-19 21:58:07 -06:00 committed by GitHub
commit e4f46146cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1683 additions and 0 deletions

View file

@ -63,6 +63,7 @@ from judge.views import (
bookmark,
widgets,
internal,
resolver,
)
from judge.views.problem_data import (
ProblemDataView,
@ -1098,6 +1099,7 @@ urlpatterns = [
]
),
),
url(r"^resolver/(?P<contest>\w+)",resolver.Resolver.as_view(), name="resolver")
] + url_static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# if hasattr(settings, "INTERNAL_IPS"):

19
judge/views/resolver.py Normal file
View file

@ -0,0 +1,19 @@
from django.views.generic import TemplateView
from django.utils.translation import gettext as _
from django.http import HttpResponseForbidden
class Resolver(TemplateView):
title = _("Resolver")
template_name = "resolver/resolver.html"
def get_context_data(self, **kwargs):
context = super(Resolver, self).get_context_data(**kwargs)
context["contest_json"] = "/static/contest.json"
return context
def get(self, request, *args, **kwargs):
if request.user.is_superuser:
return super(Resolver, self).get(request, *args, **kwargs)
return HttpResponseForbidden()

5
resources/bootstrap/bootstrap.min.css vendored Executable file

File diff suppressed because one or more lines are too long

470
resources/contest.json Normal file
View file

@ -0,0 +1,470 @@
{
"problem_sub":[6, 3, 3],
"sub_frozen":[6, 3, 4],
"problems":{
"1":{
"1":30,
"2":10,
"3":11,
"4":17,
"5":10,
"6":22
},
"2":{
"1":20,
"2":45,
"3":35
},
"3":{
"1":50,
"2":15,
"3":35
}
},
"users":{
"1":{
"username":"user1",
"name":"Nguyen Van AA",
"school":"School A",
"last_submission":13,
"problems":{
"1":{
"points":{
"1":-1,
"2":-1,
"3":-1,
"4":-1,
"5":-1,
"6":0
},
"frozen_points":{
"1":0,
"2":0,
"3":0,
"4":0,
"5":0,
"6":0
}
},
"2":{
"points":{
"1":20,
"2":1,
"3":0
},
"frozen_points":{
"1":20,
"2":0,
"3":0
}
},
"3":{
"points":{
"1":30,
"2":15,
"3":0
},
"frozen_points":{
"1":29,
"2":0,
"3":0
}
}
}
},
"2":{
"username":"user2",
"name":"Nguyen Van AB",
"school":"School B",
"last_submission":37,
"problems":{
"1":{
"points":{
"1":-1,
"2":-1,
"3":-1,
"4":-1,
"5":-1,
"6":0
},
"frozen_points":{
"1":0,
"2":4,
"3":5,
"4":0,
"5":7,
"6":0
}
},
"2":{
"points":{
"1":0,
"2":21,
"3":35
},
"frozen_points":{
"1":0,
"2":1,
"3":0
}
},
"3":{
"points":{
"1":50,
"2":15,
"3":19
},
"frozen_points":{
"1":45,
"2":1,
"3":1
}
}
}
},
"3":{
"username":"user3",
"name":"Nguyen Van AC",
"school":"School C",
"last_submission":21,
"problems":{
"1":{
"points":{
"1":14,
"2":7,
"3":0,
"4":17,
"5":10,
"6":22
},
"frozen_points":{
"1":5,
"2":5,
"3":0,
"4":1,
"5":10,
"6":4
}
},
"3":{
"points":{
"1":-1,
"2":15,
"3":35
},
"frozen_points":{
"1":50,
"2":15,
"3":35
}
}
}
},
"4":{
"username":"user4",
"name":"Nguyen Van AD",
"school":"School D",
"last_submission":79,
"problems":{
"1":{
"points":{
"1":30,
"2":10,
"3":3,
"4":17,
"5":4,
"6":10
},
"frozen_points":{
"1":19,
"2":8,
"3":0,
"4":17,
"5":2,
"6":7
}
},
"2":{
"points":{
"1":20,
"2":45,
"3":35
},
"frozen_points":{
"1":20,
"2":45,
"3":35
}
},
"3":{
"points":{
"1":50,
"2":15,
"3":35
},
"frozen_points":{
"1":50,
"2":9,
"3":11
}
}
}
},
"5":{
"username":"user5",
"name":"Nguyen Van AE",
"school":"School E",
"last_submission":36,
"problems":{
"1":{
"points":{
"1":30,
"2":7,
"3":11,
"4":17,
"5":10,
"6":1
},
"frozen_points":{
"1":3,
"2":7,
"3":0,
"4":1,
"5":10,
"6":0
}
},
"2":{
"points":{
"1":20,
"2":45,
"3":0
},
"frozen_points":{
"1":11,
"2":0,
"3":0
}
},
"3":{
"points":{
"1":15,
"2":15,
"3":35
},
"frozen_points":{
"1":3,
"2":10,
"3":15
}
}
}
},
"6":{
"username":"user6",
"name":"Nguyen Van AF",
"school":"School F",
"last_submission":17,
"problems":{
}
},
"7":{
"username":"user7",
"name":"Nguyen Van AG",
"school":"School G",
"last_submission":91,
"problems":{
"1":{
"points":{
"1":28,
"2":1,
"3":11,
"4":17,
"5":6,
"6":22
},
"frozen_points":{
"1":7,
"2":0,
"3":1,
"4":9,
"5":1,
"6":7
}
},
"2":{
"points":{
"1":20,
"2":45,
"3":24
},
"frozen_points":{
"1":20,
"2":13,
"3":0
}
},
"3":{
"points":{
"1":29,
"2":13,
"3":35
},
"frozen_points":{
"1":10,
"2":0,
"3":35
}
}
}
},
"8":{
"username":"user8",
"name":"Nguyen Van AH",
"school":"School H",
"last_submission":60,
"problems":{
}
},
"9":{
"username":"user9",
"name":"Nguyen Van AI",
"school":"School I",
"last_submission":89,
"problems":{
"1":{
"points":{
"1":17,
"2":10,
"3":1,
"4":17,
"5":5,
"6":13
},
"frozen_points":{
"1":0,
"2":10,
"3":0,
"4":3,
"5":4,
"6":11
}
}
}
},
"10":{
"username":"user10",
"name":"Nguyen Van AJ",
"school":"School J",
"last_submission":10,
"problems":{
"1":{
"points":{
"1":30,
"2":7,
"3":5,
"4":0,
"5":7,
"6":17
},
"frozen_points":{
"1":12,
"2":1,
"3":0,
"4":0,
"5":3,
"6":0
}
},
"2":{
"points":{
"1":20,
"2":45,
"3":35
},
"frozen_points":{
"1":20,
"2":0,
"3":35
}
},
"3":{
"points":{
"1":50,
"2":0,
"3":35
},
"frozen_points":{
"1":12,
"2":0,
"3":31
}
}
}
},
"11":{
"username":"user11",
"name":"Nguyen Van AK",
"school":"School K",
"last_submission":61,
"problems":{
"1":{
"points":{
"1":30,
"2":10,
"3":11,
"4":17,
"5":10,
"6":0
},
"frozen_points":{
"1":26,
"2":7,
"3":0,
"4":14,
"5":2,
"6":0
}
},
"2":{
"points":{
"1":20,
"2":45,
"3":23
},
"frozen_points":{
"1":12,
"2":45,
"3":1
}
}
}
},
"12":{
"username":"user12",
"name":"Nguyen Van AL",
"school":"School L",
"last_submission":49,
"problems":{
"1":{
"points":{
"1":30,
"2":10,
"3":0,
"4":17,
"5":0,
"6":1
},
"frozen_points":{
"1":19,
"2":1,
"3":0,
"4":10,
"5":0,
"6":0
}
}
}
}
}
}

395
resources/resolver.css Normal file
View file

@ -0,0 +1,395 @@
/*
main.css
*/
/*
reset bootstrap
*/
::-webkit-scrollbar {
display: none;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
:root {
scrollbar-width: none;
/* color */
--primary_color : #EFF5F5;
--secondary_color : #D6E4E5;
--wa : #EB6440;
--partially : #fff133;
--ac : #80ED99;
--frozen : #497174;
--untouched : #A7BBC7;
--selected : rgb(206, 75, 199);
--theme-text-color : black;
--theme-background-color : white;
}
.navbar {
margin-bottom: 0;
border: none;
}
.navbar-brand {
font-size: 30px;
}
/*
common
*/
.app {
color: white;
background-color: var(--theme-background-color);
letter-spacing: 1px;
}
.item {
border-radius: 10px;
}
.rank,
.content,
.problems li {
float: left;
}
.score,
.penalty {
float: right;
}
.rank,
.score,
.penalty {
font-size: 35px;
text-align: center;
vertical-align: middle;
line-height: 83px;
}
.rank-list-item {
display: flex;
width: 100%;
height: 100px;
padding: 10px;
position: relative;
background: transparent;
-moz-transition-duration: 1s;
-webkit-transition-duration: 1s;
-ms-transition-duration: 1s;
}
.content {
flex-grow: 1;
}
.untouched {
background-color: var(--untouched);
color: transparent;
}
.pro-score.untouched {
color: var(--theme-text-color);
}
.frozen {
background-color: var(--frozen);
}
.failed,
.WA {
background-color: var(--wa);
}
.partially {
background-color: var(--partially);
/* border: 2px solid var(--partially); */
}
.ac {
background-color: var(--ac);
}
.selected {
background-color: var(--selected);
}
.p-content.selected {
border: none;
}
.uncover {
animation: flashing 300ms infinite;
-webkit-animation: flashing 30ms infinite;
/*Safari and Chrome*/
}
@keyframes flashing {
from {
background-color: #8a6d3b
}
to {
background-color: #BD995B
}
}
@-webkit-keyframes flashing {
/*Safari and Chrome*/
from {
background-color: #8a6d3b
}
to {
background-color: #BD995B
}
}
/*
index
*/
.show-rank {
opacity: 0;
top: 0;
width: 100%;
height: 100%;
position: fixed;
background-color: black;
z-index: -1;
-moz-transition-duration: 1s;
-webkit-transition-duration: 1s;
-ms-transition-duration: 1s;
}
.show-rank .name-show {
bottom: 60px;
font-size: 40px;
font-weight: bolder;
position: absolute;
margin-left: 20px;
margin-bottom: 20px;
}
.show-rank .rank-show {
bottom: 120px;
position: absolute;
font-size: 60px;
font-weight: bolder;
margin-left: 20px;
margin-bottom: 20px;
}
.show-rank .school-show {
bottom: 0;
position: absolute;
font-size: 30px;
font-weight: bolder;
margin-left: 20px;
margin-bottom: 30px;
}
.rank {
width: 58px;
height: 58px;
font-size: 35px;
text-align: center;
vertical-align: middle;
line-height: 83px;
margin-right: 15px;
color: var(--theme-text-color);
}
.info-container .name {
font-size: 30px;
font-weight: bold;
margin-bottom: 5px;
line-height: 30px;
color: var(--theme-text-color);
}
.school {
font-size: 20px;
font-weight: normal;
margin-bottom: 5px;
line-height: 30px;
margin-left: 8px;
opacity: 0.8;
}
.problems {
list-style-type: none;
padding: 5px 0;
font-size: 12px;
border-radius: 10px;
margin: 0;
}
.problems .item {
padding: 4px;
margin: 0 5px;
width: 70px;
text-align: center;
border-radius: 10px;
cursor: pointer;
}
.problems .item .p-content {
padding: 0px 0;
font-size: 20px;
font-weight: bold;
border-radius: 10px;
line-height: 20px;
}
.score {
font-weight: bold;
width: 70px;
color: var(--theme-text-color);
}
.penalty {
width: 100px;
}
.problem-container {
display: flex;
border-radius: 10px;
}
.prob-container {
display: flex;
flex-direction: row;
margin-right: 40px;
border-radius: 10px;
overflow: hidden;
}
.pro-score {
position: relative;
font-size: 24px;
line-height: 24px;
font-weight: bolder;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
width: 80px;
cursor: pointer;
color: var(--theme-text-color);
border-radius: 10px 0 0 10px;
}
.pro-score:hover {
/* border: 2px solid white; */
/* padding: 2px 2px; */
/* border-radius: 10px 0 0 10px; */
}
.pro-score.partially {
border: 4px solid var(--partially);
}
.pro-score.ac {
border: 4px solid #2da728;
}
.pro-score.failed {
border: 4px solid #e21919;
}
.pro-score.frozen {
border: 4px solid #004d64;
}
.problems .item:hover {
border: 2px solid white;
padding: 2px 2px;
border-radius: 10px;
}
.pro-score.selected {
border: 4px solid white;
padding: 0 0;
border-radius: 10px 0 0 10px;
}
.problems .item.selected {
border: 4px solid white;
padding: 0 0;
border-radius: 10px;
}
.hidden-board {
width: 100%;
}
.info-bar {
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: space-between;
width: 100%;
height: 30px;
padding: 0 10px;
padding-top: 2px;
padding-bottom: 0;
border-bottom: 2px solid var(--theme-text-color);
z-index: 1000;
font-weight: bolder;
background-color: var(--theme-background-color);
}
.info-bar .rank {
font-size: 20px;
line-height: 20px;
font-weight: lighter;
height: 20px;
margin-top: auto;
margin-bottom: auto;
}
.info-bar .name {
font-size: 20px;
font-weight: lighter;
height: 20px;
margin-top: auto;
margin-bottom: auto;
color: var(--theme-text-color);
}
.info-bar .score {
font-size: 20px;
line-height: 20px;
font-weight: lighter;
height: 20px;
margin-top: auto;
margin-bottom: auto;
}
.sticky {
position: fixed;
top: 0;
width: 100%
}
.info-container {
display: flex;
color: var(--theme-text-color);
}
.background-primary {
background-color: var(--primary_color);
}
.background-secondary {
background-color: var(--secondary_color);
}

318
resources/resolver.js Normal file
View file

@ -0,0 +1,318 @@
function Resolver(problem_sub, sub_frozen, problems, users) {
this.problem_sub = problem_sub;
this.sub_frozen = sub_frozen;
this.problems = problems;
this.users = users;
this.frozen_seconds = 200;
this.operations = [];
this.frozen_op = 0;
this.isshow = [];
this.delay = false;
}
Resolver.prototype.status = function (problem) {
if (problem.old_verdict == 'NA' && problem.new_verdict == 'NA') {
return 'untouched';
} else if (problem.old_verdict == 'AC') {
return 'ac';
} else if (problem.old_verdict == 'PA' && problem.new_verdict == 'NA') {
return 'partially';
} else if (problem.new_verdict == 'NA' && problem.old_verdict == 'WA') {
return 'failed';
} else {
return "frozen";
}
}
Resolver.prototype.substatus = function (problem, subproblem) {
if (problem.old_verdict == 'NA' && problem.new_verdict == 'NA') {
return 'untouched';
} else if (problem[subproblem].old_verdict == 'AC') {
return 'ac';
} else if (problem[subproblem].old_verdict == 'PA' && problem.new_verdict == 'NA') {
return 'partially';
} else if (problem[subproblem].old_verdict == 'WA' && problem.new_verdict == 'NA') {
return 'failed';
}
else {
return 'frozen';
}
}
Resolver.prototype.pointstatus = function (point, problem, sub) {
if (sub == undefined) {
if (point == 100) return 'AC';
if (point == 0) return 'WA';
return 'PA';
}
if (point == this.problems[problem][sub]) return 'AC';
if (point == 0) return 'WA';
return 'PA';
}
Resolver.prototype.calcOperations = function () {
this.rank = {};
this.users_cnt = Object.keys(this.users).length;
for (let id = 1; id <= this.users_cnt; id++) {
this.rank[id] = {
'user_id': id,
'score': 0,
'rank_show': -1,
'last_submission': this.users[id].last_submission,
};
this.rank[id].problem = {}
for (let i = 1; i <= this.problem_sub.length; i++) {
this.rank[id].problem[i] = {
'old_point': 0,
'new_point': 0,
'old_verdict': 'NA',
'new_verdict': 'NA',
}
for (let j = 1; j <= this.problem_sub[i - 1]; j++) {
this.rank[id].problem[i][j] = {
'old_point': 0,
'new_point': 0,
'old_verdict': 'NA',
'new_verdict': 'NA'
};
}
}
for (let problemid in this.users[id].problems) {
for (let j = 1; j <= this.problem_sub[problemid - 1]; j++) {
if (j < this.sub_frozen[problemid - 1]) {
this.rank[id].problem[problemid][j].old_point = this.users[id].problems[problemid].frozen_points[j];
this.rank[id].problem[problemid].old_point += this.rank[id].problem[problemid][j].old_point;
this.rank[id].problem[problemid][j].old_verdict = this.pointstatus(this.users[id].problems[problemid].frozen_points[j], problemid, j);
if (this.users[id].problems[problemid].points[j] != -1) {
this.rank[id].problem[problemid][j].new_point = this.users[id].problems[problemid].points[j];
this.rank[id].problem[problemid].new_point += this.rank[id].problem[problemid][j].new_point;
this.rank[id].problem[problemid][j].new_verdict = this.pointstatus(this.users[id].problems[problemid].points[j], problemid, j);
}
}
}
this.rank[id].problem[problemid].old_verdict = this.pointstatus(this.rank[id].problem[problemid].old_point);
this.rank[id].score += this.rank[id].problem[problemid].old_point;
if (this.users[id].problems[problemid].points[1] != -1) {
this.rank[id].problem[problemid].new_verdict = this.pointstatus(this.rank[id].problem[problemid].new_point);
}
}
}
this.rank_frozen = $.extend(true, [], this.rank);
var uids = Object.keys(this.rank);
this.rankarr = [];
for (let key in uids) {
this.rankarr.push(this.rank[uids[key]]);
}
this.rankarr.sort(function (a, b) {
if (a.score != b.score) {
return (b.score - a.score);
} else {
return (a.last_submission - b.last_submission);
}
});
for (let i = 0; i < this.rankarr.length; i++) {
this.rankarr[i].rank_show = i + 1;
this.rank[this.rankarr[i].user_id].rank_show = i + 1;
this.rank_frozen[this.rankarr[i].user_id].rank_show = i + 1;
}
console.log(this.rank_frozen);
for (let i = this.rankarr.length - 1; i >= 0; i--) {
var flag = true;
while (flag) {
flag = false;
for (let j = 1; j <= this.problem_sub.length; j++) {
if (this.status(this.rankarr[i].problem[j]) == 'frozen') {
frozen_op = true;
flag = true;
for (let sub = 1; sub < this.sub_frozen[j - 1]; sub++) {
if (this.rankarr[i].problem[j][sub].old_verdict == 'AC') continue;
var op = {
id: this.operations.length,
type: 'sub',
frozen: 'no',
user_id: this.rankarr[i].user_id,
problem_index: j,
problem_sub: sub,
old_point: this.rankarr[i].problem[j][sub].old_point,
new_point: this.rankarr[i].problem[j][sub].new_point,
old_verdict: this.rankarr[i].problem[j][sub].old_verdict,
new_verdict: this.rankarr[i].problem[j][sub].new_verdict,
};
var tmp = this.rankarr[i];
tmp.problem[j][sub].old_point = tmp.problem[j][sub].new_point;
tmp.problem[j][sub].new_point = 0;
tmp.problem[j][sub].old_verdict = tmp.problem[j][sub].new_verdict;
tmp.problem[j][sub].new_verdict = 'NA';
this.operations.push(op);
}
var op = {
id: this.operations.length,
type: 'problem',
frozen: 'no',
user_id: this.rankarr[i].user_id,
problem_index: j,
old_point: this.rankarr[i].problem[j].old_point,
new_point: this.rankarr[i].problem[j].new_point,
old_verdict: this.rankarr[i].problem[j].old_verdict,
new_verdict: this.rankarr[i].problem[j].new_verdict,
old_rank: i + 1,
new_rank: -1,
};
var tmp = this.rankarr[i];
if (tmp.problem[j].new_point > tmp.problem[j].old_point) {
tmp.score += tmp.problem[j].new_point - tmp.problem[j].old_point;
}
tmp.problem[j].old_point = tmp.problem[j].new_point;
tmp.problem[j].new_point = 0;
tmp.problem[j].old_verdict = tmp.problem[j].new_verdict;
tmp.problem[j].new_verdict = 'NA';
var k = i - 1;
while (k >= 0 && this.rankarr[k].score < tmp.score) {
tmp.rank_show--;
this.rankarr[k].rank_show++;
this.rankarr[k + 1] = this.rankarr[k];
k--;
}
this.rankarr[k + 1] = tmp;
op.new_rank = k + 2;
this.operations.push(op);
break;
}
}
}
}
this.check = [];
for (let i = 1; i <= this.users_cnt; i++) {
var usercheck = [];
for (let j = 1; j <= this.problem_sub.length; j++) {
var cc = [];
for (let k = 1; k <= this.sub_frozen[j - 1] - 1; k++) {
cc.push(k);
}
usercheck.push(cc);
}
this.check.push(usercheck);
}
}
Resolver.prototype.showrank = function () {
for (let rankid = this.rankarr.length - 1; rankid >= 0; rankid--) {
if (this.isshow.indexOf(this.rankarr[rankid].user_id) != -1) continue;
var ok = true;
for (let problemid in this.users[this.rankarr[rankid].user_id].problems) {
for (let sub = 1; sub <= this.problem_sub[problemid - 1]; sub++) {
if (this.check[this.rankarr[rankid].user_id - 1][problemid - 1].indexOf(sub) == -1) {
ok = false;
}
}
}
if (ok) {
var op = {
id: this.operations.length,
type: 'show',
user_id: this.rankarr[rankid].user_id,
};
this.delay = true;
this.isshow.push(this.rankarr[rankid].user_id);
this.operations.push(op);
return true;
} else {
return false;
}
}
return false;
}
Resolver.prototype.next_operation = function () {
if (this.delay) {
var op = {
id: this.operations.length,
type: 'delay',
};
this.delay = false;
this.operations.push(op);
return true;
}
var isshowrank = this.showrank();
if (isshowrank == true) return true;
for (let i = this.rankarr.length - 1; i >= 0; i--) {
for (let problemid = 1; problemid <= this.problem_sub.length; problemid++) {
let ok = false;
var id = this.rankarr[i].user_id;
for (let cc in this.users[id].problems) {
if (cc == problemid) ok = true;
}
if (ok == false) {
continue;
}
for (let sub = this.sub_frozen[problemid - 1]; sub <= this.problem_sub[problemid - 1]; sub++) {
if (this.check[this.rankarr[i].user_id - 1][problemid - 1].indexOf(sub) == -1) {
this.operation(i, problemid, sub);
return true;
}
}
}
}
return false;
}
Resolver.prototype.operation = function (rankid, problemid, sub) {
var id = this.rankarr[rankid].user_id;
if (this.check[this.rankarr[rankid].user_id - 1][problemid - 1].indexOf(sub) != -1) return false;
this.check[this.rankarr[rankid].user_id - 1][problemid - 1].push(sub);
this.rankarr[rankid].problem[problemid][sub].new_point = this.users[id].problems[problemid].points[sub];
this.rankarr[rankid].problem[problemid][sub].new_verdict = this.pointstatus(this.rankarr[rankid].problem[problemid][sub].new_point, problemid, sub);
this.rankarr[rankid].problem[problemid].new_point =
this.rankarr[rankid].problem[problemid].old_point + this.rankarr[rankid].problem[problemid][sub].new_point - this.rankarr[rankid].problem[problemid][sub].old_point;
this.rankarr[rankid].problem[problemid].new_verdict = this.pointstatus(this.rankarr[rankid].problem[problemid].new_point);
var op = {
id: this.operations.length,
type: 'sub',
frozen: 'ok',
user_id: this.rankarr[rankid].user_id,
problem_index: problemid,
problem_sub: sub,
old_point: this.rankarr[rankid].problem[problemid][sub].old_point,
new_point: this.rankarr[rankid].problem[problemid][sub].new_point,
old_verdict: this.rankarr[rankid].problem[problemid][sub].old_verdict,
new_verdict: this.rankarr[rankid].problem[problemid][sub].new_verdict,
};
var tmp = this.rankarr[rankid];
tmp.problem[problemid][sub].old_point = tmp.problem[problemid][sub].new_point;
tmp.problem[problemid][sub].new_point = 0;
tmp.problem[problemid][sub].old_verdict = tmp.problem[problemid][sub].new_verdict;
tmp.problem[problemid][sub].new_verdict = 'NA';
this.operations.push(op);
var op1 = {
id: this.operations.length,
type: 'problem',
frozen: 'ok',
user_id: this.rankarr[rankid].user_id,
problem_index: problemid,
old_point: this.rankarr[rankid].problem[problemid].old_point,
new_point: this.rankarr[rankid].problem[problemid].new_point,
old_verdict: this.rankarr[rankid].problem[problemid].old_verdict,
new_verdict: this.rankarr[rankid].problem[problemid].new_verdict,
old_rank: rankid + 1,
new_rank: -1,
};
if (tmp.problem[problemid].new_point > tmp.problem[problemid].old_point) {
tmp.score += tmp.problem[problemid].new_point - tmp.problem[problemid].old_point;
}
tmp.problem[problemid].old_point = tmp.problem[problemid].new_point;
tmp.problem[problemid].new_point = 0;
tmp.problem[problemid].old_verdict = tmp.problem[problemid].new_verdict;
tmp.problem[problemid].new_verdict = 'NA';
var k = rankid - 1;
while (k >= 0 && (this.rankarr[k].score < tmp.score || (this.rankarr[k].score == tmp.score && this.rankarr[k].last_submission > tmp.last_submission))) {
tmp.rank_show--;
this.rankarr[k].rank_show++;
this.rankarr[k + 1] = this.rankarr[k];
k--;
}
this.rankarr[k + 1] = tmp;
op1.new_rank = k + 2;
this.operations.push(op1);
return true;
}

View file

@ -22,6 +22,9 @@
{{ make_tab_item('ranking', 'fa fa-bar-chart', None, _('Hidden Rankings')) }}
{% endif %}
{% endif %}
{% if request.user.is_superuser %}
{{ make_tab_item('resolver', 'fa fa-check', url('resolver', contest.key), _('Resolver')) }}
{% endif %}
{% if can_edit %}
{% if perms.judge.moss_contest and has_moss_api_key %}
{{ make_tab_item('moss', 'fa fa-gavel', url('contest_moss', contest.key), _('MOSS')) }}

View file

@ -0,0 +1,428 @@
{% compress js %}
<script type="text/javascript">
var updateInterval = 2000;
var curop = -1;
var lintHeight = 100;
var bonusHeight = 30;
var speed = 700;
var autopress = false;
$(document).ready(function() {
$.getJSON('{{ contest_json }}', function (data) {
console.log("OK");
var resolver = new Resolver(data.problem_sub, data.sub_frozen, data.problems, data.users);
window.resolver = resolver;
resolver.calcOperations();
resolver.frozen_op = resolver.operations.length - 1;
resetCSS();
light_theme();
show_rank();
}).fail(function(){
console.log("An error has occurred.");
});
});
function updateSelector() {
$('.show-rank').css('opacity', '0');
$('.show-rank').css('z-index', '-1');
var operation = resolver.operations[curop];
var tmp = resolver.rank_frozen[operation.user_id];
if (operation.type != 'delay') {
window.scrollTo({
top: (resolver.rank_frozen[operation.user_id].rank_show - 6) * lintHeight + bonusHeight,
left: 0,
behavior: 'smooth'
});
for (let i in resolver.rank_frozen) {
$('#rank-' + i).css({'background-color' : ''});
if (resolver.rank_frozen[i].rank_show % 2 == 0) {
$('#rank-' + i).removeClass('background-secondary');
$("#rank-" + i).addClass('background-primary');
} else {
$("#rank-" + i).removeClass('background-primary');
$("#rank-" + i).addClass('background-secondary');
}
}
$('#rank-' + operation.user_id).css({ "background-color": "#5382DF" });
}
if (operation.type == 'problem') {
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score').removeClass(resolver.status(tmp.problem[operation.problem_index]));
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score').addClass('selected');
} else if (operation.type == 'sub') {
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub).removeClass(resolver.status(tmp.problem[operation.problem_index][operation.problem_sub]));
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub + ' .pro-content').removeClass(resolver.status(tmp.problem[operation.problem_index][operation.problem_sub]));
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub).addClass('selected');
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub + ' .p-content').addClass('selected');
if (operation.frozen == 'ok') {
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub).removeClass('frozen');
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub + ' .pro-content').removeClass('frozen');
}
}
}
function getNewData() {
var operation = resolver.operations[curop];
if (operation.type == 'problem') {
var tmp = resolver.rank_frozen[operation.user_id];
for (let i in resolver.rank_frozen) {
if (resolver.rank_frozen[i].rank_show < operation.old_rank && resolver.rank_frozen[i].rank_show >= operation.new_rank) {
resolver.rank_frozen[i].rank_show++;
}
}
tmp.rank_show = operation.new_rank;
tmp.score += operation.new_point - operation.old_point;
tmp.problem[operation.problem_index].old_verdict = operation.new_verdict;
tmp.problem[operation.problem_index].new_verdict = 'NA';
tmp.problem[operation.problem_index].old_point = operation.new_point;
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score').removeClass('selected');
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score').addClass(resolver.status(tmp.problem[operation.problem_index]));
$('#rank-' + operation.user_id + ' .score').text(tmp.score);
if (operation.new_rank % 2 == 0) {
let per = tmp.problem[operation.problem_index].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${theme_background_color} ${per}%)`;
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score.partially').css("background", linear);
} else {
let per = tmp.problem[operation.problem_index].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${untouched} ${per}%)`;
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score.partially').css("background", linear);
}
for (let i in resolver.rank_frozen) {
$('#rank-' + i + ' .rank').text(resolver.rank_frozen[i].rank_show);
$("#rank-" + i).css('top', (resolver.rank_frozen[i].rank_show - 1) * lintHeight + bonusHeight);
if (resolver.rank_frozen[i].rank_show % 2 == 0) {
if (i != operation.user_id) {
$("#rank-" + i).removeClass('background-secondary');
$("#rank-" + i).addClass('background-primary');
}
$("#rank-" + i + ' .prob-container').removeClass('background-primary');
$("#rank-" + i + ' .problems').removeClass('background-primary');
$("#rank-" + i + ' .prob-container').addClass('background-secondary');
$("#rank-" + i + ' .problems').addClass('background-secondary');
for (let problemid in resolver.rank_frozen[i].problem) {
let per = resolver.rank_frozen[i].problem[problemid].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${primary_color} ${per}%)`;
$('#rank-' + i + ' .p-' + problemid + ' .pro-score.partially').css("background", linear);
}
} else {
if (i != operation.user_id) {
$("#rank-" + i).removeClass('background-primary');
$("#rank-" + i).addClass('background-secondary');
}
$("#rank-" + i + ' .prob-container').removeClass('background-secondary');
$("#rank-" + i + ' .problems').removeClass('background-secondary');
$("#rank-" + i + ' .prob-container').addClass('background-primary');
$("#rank-" + i + ' .problems').addClass('background-primary');
for (let problemid in resolver.rank_frozen[i].problem) {
let per = resolver.rank_frozen[i].problem[problemid].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${secondary_color} ${per}%)`;
$('#rank-' + i + ' .p-' + problemid + ' .pro-score.partially').css("background", linear);
}
}
}
} else if (operation.type == 'sub') {
var tmp = resolver.rank_frozen[operation.user_id];
tmp.problem[operation.problem_index][operation.problem_sub].old_verdict = operation.new_verdict;
tmp.problem[operation.problem_index][operation.problem_sub].new_verdict = 'NA';
tmp.problem[operation.problem_index].old_point += operation.new_point - operation.old_point;
tmp.problem[operation.problem_index][operation.problem_sub].old_point = operation.new_point;
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .pro-score').text(tmp.problem[operation.problem_index].old_point);
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + '.s-' + operation.problem_sub + ' .p-content').text(operation.new_point);
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub).removeClass('selected');
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub + ' .p-content').removeClass('selected');
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub).addClass(resolver.status(tmp.problem[operation.problem_index][operation.problem_sub]));
$('#rank-' + operation.user_id + ' .p-' + operation.problem_index + ' .s-' + operation.problem_sub + ' .p-content').addClass(resolver.status(tmp.problem[operation.problem_index][operation.problem_sub]));
} else if (operation.type == 'show') {
$('.show-rank').css('opacity', '1');
$('.show-rank').css('z-index', '10000');
$('.show-rank .rank-show').text('Rank ' + resolver.rank_frozen[operation.user_id].rank_show);
$('.show-rank .name-show').text(resolver.users[operation.user_id].name);
$('.show-rank .school-show').text(resolver.users[operation.user_id].school);
}
$('.ac').css("background", "");
}
function resetCSS() {
$('.navbar').css('border-radius', '0');
$(".hidden-board").css('height', (window.resolver.rank_frozen.length - 1) * lintHeight);
}
function show_rank() {
for (let i in window.resolver.rank_frozen) {
rank_id = document.createElement('div');
$(rank_id).css('position', 'absolute');
$(rank_id).css('top', (resolver.rank_frozen[i].rank_show - 1) * lintHeight + bonusHeight);
if (resolver.rank_frozen[i].rank_show % 2 == 0) {
$(rank_id).addClass('background-primary');
} else {
$(rank_id).addClass('background-secondary');
}
$(rank_id).attr('id', 'rank-' + i);
$(rank_id).addClass('rank-list-item');
$(".rank-list").append($(rank_id));
rank = document.createElement('div');
$(rank).addClass('rank');
$(rank).text(resolver.rank_frozen[i].rank_show);
$(rank_id).append($(rank));
content = document.createElement('div');
$(content).addClass('content');
$(rank_id).append($(content));
info_div = document.createElement('div');
$(info_div).addClass('info-container');
$(content).append($(info_div));
name_div = document.createElement('div');
$(name_div).addClass('name');
$(name_div).text(window.resolver.users[i].name);
$(info_div).append($(name_div));
school_div = document.createElement('div');
$(school_div).addClass('school');
$(school_div).text("(" + window.resolver.users[i].school + ")");
$(info_div).append($(school_div));
problem_container = document.createElement('div');
$(problem_container).addClass('problem-container');
for (let problem_id in window.resolver.rank_frozen[i].problem) {
problems_con = document.createElement('div');
$(problems_con).addClass('p-' + problem_id);
$(problems_con).addClass('prob-container');
if (resolver.rank_frozen[i].rank_show % 2 == 1) {
$(problems_con).addClass('background-primary');
} else {
$(problems_con).addClass('background-secondary');
}
pro_score = document.createElement('div');
$(pro_score).addClass('pro-score');
$(pro_score).text(resolver.rank_frozen[i].problem[problem_id].old_point);
$(pro_score).addClass(window.resolver.status(window.resolver.rank_frozen[i].problem[problem_id]));
if (resolver.status(window.resolver.rank_frozen[i].problem[problem_id]) == 'partially') {
if (resolver.rank_frozen[i].rank_show % 2 == 1) {
let per = resolver.rank_frozen[i].problem[problem_id].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${secondary_color} ${per}%)`;
$(pro_score).css("background", linear);
} else {
let per = resolver.rank_frozen[i].problem[problem_id].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${primary_color} ${per}%)`;
$(pro_score).css("background", linear);
}
}
$(problems_con).append($(pro_score));
problems = document.createElement('ul');
$(problems).addClass('p-' + problem_id);
$(problems).addClass('problems');
for (let j = 1; j <= resolver.problem_sub[problem_id - 1]; j++) {
problem = document.createElement('li');
$(problem).addClass('item');
$(problem).addClass(window.resolver.substatus(window.resolver.rank_frozen[i].problem[problem_id], j));
$(problem).addClass('p-' + problem_id);
$(problem).addClass('s-' + j);
$(problem).addClass('id-' + i);
$(problems).append($(problem));
p_content = document.createElement('div');
$(p_content).addClass(window.resolver.substatus(window.resolver.rank_frozen[i].problem[problem_id], j));
$(p_content).addClass('p-content');
if (j < resolver.sub_frozen[problem_id - 1]) {
$(p_content).text(window.resolver.rank_frozen[i].problem[problem_id][j].old_point);
} else {
$(p_content).text("?");
}
$(problem).append($(p_content));
}
$(problems_con).append($(problems));
$(problem_container).append($(problems_con));
}
$(content).append($(problem_container));
score = document.createElement('div');
$(score).addClass('score');
$(score).text(window.resolver.rank_frozen[i].score);
$(rank_id).append($(score));
}
}
var theme = 0;
$('body').keydown(function (e) {
if (e.keyCode == 77) {
console.log("Press M!");
}
if (e.keyCode == 13) {
console.log("Press Enter!");
if (curop == resolver.operations.length - 1) {
console.log("Do Enter Pressed!");
resolver.operations = [];
curop = -1;
resolver.next_operation();
if (window.resolver.operations.length == 0) {
$('.show-rank').css('visibility', 'hidden');
$('.show-rank').css('opacity', '0');
for (let i in resolver.rank_frozen) {
if (resolver.rank_frozen[i].rank_show % 2 == 0) {
$("#rank-" + i).removeClass('background-secondary');
$("#rank-" + i).addClass('background-primary');
} else {
$("#rank-" + i).removeClass('background-primary');
$("#rank-" + i).addClass('background-secondary');
}
}
}
console.log(resolver.operations);
if (resolver.operations.length == 1) {
for (let x in window.resolver.operations) {
curop++;
updateSelector();
setTimeout(function () {
getNewData();
}, 500);
}
} else {
for (let x in window.resolver.operations) {
setTimeout(function () {
curop++;
updateSelector();
}, speed * x);
setTimeout(function () {
getNewData();
}, speed * x + speed / 2);
}
}
}
}
if (e.keyCode == 65) {
console.log("A pressed!");
if (autopress == false) {
autopress = true;
// for (let x in resolver.operations) {
// curop++;
// updateSelector();
// getNewData();
// }
for (let x in window.resolver.operations) {
setTimeout(function () {
curop++;
updateSelector();
}, speed * x);
setTimeout(function () {
getNewData();
}, speed * x + speed / 2);
}
}
}
if (e.keyCode == 66) {
theme = 1 - theme;
if (theme) dark_theme();
else light_theme();
}
});
$('.rank-list').on('click', 'li', function () {
if (curop == resolver.operations.length - 1) {
var classstr = $(this).attr('class');
var index = classstr.indexOf('id-');
var useridstr = "";
for (let i = index + 3; i < classstr.length; i++) {
useridstr = useridstr + classstr[i];
}
var userid = parseInt(useridstr);
var problemid = classstr[classstr.indexOf('p-') + 2];
var sub = parseInt(classstr[classstr.indexOf('s-') + 2]);
var rankid = resolver.rank_frozen[userid].rank_show;
resolver.operations = [];
curop = -1;
console.log("Clicked!");
resolver.operation(rankid - 1, problemid, sub);
if (resolver.operations.length == 1) {
for (let x in window.resolver.operations) {
curop++;
updateSelector();
setTimeout(function () {
getNewData();
}, 500);
}
} else {
for (let x in window.resolver.operations) {
setTimeout(function () {
curop++;
updateSelector();
}, speed * x);
setTimeout(function () {
getNewData();
}, speed * x + speed / 2);
}
}
}
});
var primary_color, secondary_color;
var wa, partially, ac, selected, frozen, untouched;
var theme_text_color, theme_background_color;
function dark_theme() {
primary_color = "black";
secondary_color = '#3e3e3e';
frozen = "#34495e";
untouched = "#1f1f1f";
wa = "#B71C0C";
partially = "#A79D03";
ac = "#086d08";
selected = "rgb(206, 75, 199)";
theme_text_color = "white";
theme_background_color = "black";
set_theme();
}
function light_theme() {
primary_color = "#EFF5F5";
secondary_color = "#D6E4E5";
wa = "#EB6440";
partially = "#fff133";
ac = "#80ED99";
// ac = "green";
frozen = "#497174";
untouched = "#A7BBC7";
selected = "rgb(206, 75, 199)";
theme_text_color = "black";
theme_background_color = "white";
set_theme();
}
function set_theme() {
let root = document.querySelector(':root');
root.style.setProperty('--primary_color', primary_color);
root.style.setProperty('--secondary_color', secondary_color);
root.style.setProperty('--wa', wa);
root.style.setProperty('--partially', partially);
root.style.setProperty('--ac', ac);
root.style.setProperty('--selected', selected);
root.style.setProperty('--frozen', frozen);
root.style.setProperty('--untouched', untouched);
root.style.setProperty('--theme-text-color', theme_text_color);
root.style.setProperty('--theme-background-color', theme_background_color);
for (let i in resolver.rank_frozen) {
if (resolver.rank_frozen[i].rank_show % 2 == 0) {
for (let problemid in resolver.rank_frozen[i].problem) {
let per = resolver.rank_frozen[i].problem[problemid].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${primary_color} ${per}%)`;
$('#rank-' + i + ' .p-' + problemid + ' .pro-score.partially').css("background", linear);
}
} else {
for (let problemid in resolver.rank_frozen[i].problem) {
let per = resolver.rank_frozen[i].problem[problemid].old_point;
let linear = `linear-gradient(90deg, ${partially} ${per}%, ${secondary_color} ${per}%)`;
$('#rank-' + i + ' .p-' + problemid + ' .pro-score.partially').css("background", linear);
}
}
}
}
</script>
{% endcompress %}

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
<head>
<title>Contest Resolver</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ static('bootstrap/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ static('resolver.css') }}">
<link rel="shortcut icon" href="#">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script src="{{ static('libs/jquery-3.4.1.min.js') }}"></script>
<script src="{{ static('resolver.js') }}"></script>
<!-- <script src="{{ static('resolver-main.js') }}"></script> -->
</head>
<body class="app">
<div class="hidden-board">
</div>
<div class="info-bar">
<div class="rank">Rank</div>
<div class="content">
<div class="name">Name</div>
</div>
<div class="score">Score</div>
</div>
<div class="rank-list">
</div>
<div class="show-rank">
<div class="rank-show"> X </div>
<div class="name-show"> Y </div>
<div class="school-show"> Z </div>
</div>
{% include "resolver/media-js.html" %}
</body>
</html>