Skip to content

Commit 36f996c

Browse files
committed
Various fixes
1 parent 55a9d26 commit 36f996c

File tree

23 files changed

+176
-48
lines changed

23 files changed

+176
-48
lines changed

deploy/host.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@
1818
src: ./packages/omogenjudge-host.deb
1919
dest: omogenjudge-host.deb
2020
- name: Install omogenjudge-host.deb
21-
ansible.builtin.apt:
22-
deb: omogenjudge-host.deb
23-
state: present
21+
ansible.builtin.command: sudo dpkg -i omogenjudge-host.deb

judgehost/judgehost/eval.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ var langMap = map[string]apipb.LanguageGroup{
2323
"ruby": apipb.LanguageGroup_RUBY,
2424
"rust": apipb.LanguageGroup_RUST,
2525
"java": apipb.LanguageGroup_JAVA,
26-
"csharp": apipb.LanguageGroup_CSHARP,
26+
"csharp": apipb.LanguageGroup_CSHARP,
2727
}
2828

2929
type submissionJson struct {
3030
Files map[string]string
3131
}
3232

33+
type includedCodeJson struct {
34+
FilesByLanguage map[string]map[string]string `json:"files_by_language"`
35+
}
36+
3337
var evalMutex sync.Mutex
3438

3539
func toStorageVerdict(verdict apipb.Verdict) storage.Verdict {
@@ -62,18 +66,27 @@ func evaluate(runId int64) error {
6266
}
6367
lang, ok := langMap[run.Submission.Language]
6468
if !ok {
65-
return fmt.Errorf("run has unknown language %s", run.Submission.Language)
69+
return fmt.Errorf("run has unknown language %s", run.Submission.Language)
6670
}
6771
program := &apipb.Program{
6872
Language: lang,
6973
}
7074
submissionFiles := submissionJson{}
71-
err := json.Unmarshal(run.Submission.SubmissionFiles, &submissionFiles)
72-
if err != nil {
75+
if err := json.Unmarshal(run.Submission.SubmissionFiles, &submissionFiles); err != nil {
7376
return err
7477
}
78+
includedCode := includedCodeJson{}
79+
if err := json.Unmarshal(run.ProblemVersion.IncludedFiles, &includedCode); err != nil {
80+
return err
81+
}
82+
logger.Infof("Lang: %v, included code:", run.Submission.Language, includedCode)
83+
extraFiles := includedCode.FilesByLanguage[run.Submission.Language]
84+
7585
logger.Infof("Files: %v", submissionFiles)
7686
for path, content := range submissionFiles.Files {
87+
if _, hasExtraFile := extraFiles[path]; hasExtraFile {
88+
continue
89+
}
7790
content, err := base64.StdEncoding.DecodeString(content)
7891
if err != nil {
7992
return err
@@ -83,6 +96,15 @@ func evaluate(runId int64) error {
8396
Contents: content,
8497
})
8598
}
99+
100+
logger.Infof("Extra files: %v", extraFiles)
101+
for path, content := range extraFiles {
102+
program.Sources = append(program.Sources, &apipb.SourceFile{
103+
Path: filepath.Base(path),
104+
Contents: []byte(content),
105+
})
106+
}
107+
86108
// In case we retry judging of the run, put it in a new folder instead to avoid collisions
87109
subRoot := fmt.Sprintf("/var/lib/omogen/submissions/%d-%d", runId, time.Now().Unix())
88110
compile, err := eval.Compile(program, filepath.Join(subRoot, "compile"))

omogenjudge/contests/active_contest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@ def process_view(self, request: OmogenRequest, view_func, view_args, view_kwargs
3434
request.contest_site = True
3535
except Contest.DoesNotExist:
3636
request.contest = None
37+
if request.contest:
38+
request.team = contest_team_for_user(request.contest, request.user)
3739

3840

3941
def contest_context(request: OmogenRequest) -> dict[str, typing.Any]:
4042
if request.contest:
4143
contest = request.contest
42-
team = contest_team_for_user(contest, request.user)
4344
ctx: dict[str, typing.Any] = {
4445
'contest': contest,
4546
'all_contest_problems': SimpleLazyObject(lambda: contest_problems(contest)),
46-
'contest_team': team,
47-
'contest_started': contest_has_started_for_team(contest, team),
48-
'contest_ended': contest_has_ended_for_team(contest, team),
47+
'contest_team': request.team,
48+
'contest_started': contest_has_started_for_team(contest, request.team),
49+
'contest_ended': contest_has_ended_for_team(contest, request.team),
4950
}
50-
if not team_can_view_problems(contest, team):
51+
if not team_can_view_problems(contest, request.team):
5152
ctx['contest_problems'] = []
5253
else:
5354
ctx['contest_problems'] = SimpleLazyObject(lambda: contest_problems(contest))

omogenjudge/contests/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
def team_can_view_problems(contest: Contest, team: Optional[Team]) -> bool:
88
if not contest.published:
99
return False
10-
return contest_has_started_for_team(contest, team)
10+
return contest_has_started_for_team(contest, team)

omogenjudge/contests/scoreboard.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ def _contest_submissions(self, team: Team, submissions: list[Submission]) -> lis
177177
contest_submissions.append(submission)
178178
return contest_submissions
179179

180+
@property
181+
def has_penalty(self):
182+
return NotImplementedError
183+
180184

181185
def _subtask_runs(group_runs: List[SubmissionGroupRun], subtasks: int):
182186
# First run is sample; assume all other subtasks have depth 1
@@ -228,6 +232,10 @@ def _process_problem(self, submissions: List[Submission], scoreboard_problem: Sc
228232
def _team_sort_key(self, team):
229233
return -team.total_score, team.tiebreak
230234

235+
@property
236+
def has_penalty(self):
237+
return False
238+
231239

232240
class BinaryWithPenalty(ScoreboardMaker):
233241

@@ -255,11 +263,15 @@ def _process_problem(self, submissions: List[Submission], scoreboard_problem: Sc
255263
problem_result.problem_score += 1
256264
if start_time:
257265
seconds = math.floor((sub.date_created - start_time).total_seconds())
258-
problem_result.tiebreak = -failures * 20 + seconds // 60
266+
problem_result.tiebreak = failures * 20 + seconds // 60
259267
else:
260268
failures += 1
261269
return problem_result
262270

271+
@property
272+
def has_penalty(self):
273+
return True
274+
263275

264276
_SCOREBOARDS: Dict[ScoringType, Type[ScoreboardMaker]] = {
265277
ScoringType.BINARY_WITH_PENALTY: BinaryWithPenalty,

omogenjudge/frontend/accounts/login.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,20 @@ def github_auth(request: OmogenRequest) -> HttpResponse:
149149
response = requests.post("https://github.com/login/oauth/access_token", data=request_params)
150150
response.raise_for_status()
151151
client.parse_request_body_response(response.text)
152-
uri, headers, body = client.add_token("https://api.github.com/user", "get", )
153152

153+
uri, headers, body = client.add_token("https://api.github.com/user", "get", )
154154
user_details = requests.get(uri, data=body, headers=headers).json()
155155
username = user_details["login"]
156-
email = user_details["email"]
157156
full_name = user_details.get("name")
158-
return oauth_login(request, username, email, full_name)
157+
158+
uri, headers, body = client.add_token("https://api.github.com/user/emails", "get", )
159+
emails = requests.get(uri, data=body, headers=headers).json()
160+
for email in emails:
161+
if email["primary"] and email["verified"]:
162+
return oauth_login(request, username, email["email"], full_name)
163+
messages.error(request, "You need to verify your primary email on your Github account to log in.")
164+
return redirect("login")
165+
159166
else:
160167
url, _, _ = client.prepare_authorization_request(
161168
"https://github.com/login/oauth/authorize",

omogenjudge/frontend/jinja2/accounts/register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{% if social_logins %}
1717
<hr>
1818
<div class="text-center">
19-
{{ social.signins(social_logins) }}
19+
{{ social.social_logins(social_logins) }}
2020
</div>
2121
{% endif %}
2222
</div>

omogenjudge/frontend/jinja2/problems/view_problem.html

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@
2222
onload="
2323
document.querySelectorAll('.tex2jax_process').forEach(
2424
el => renderMathInElement(el, { delimiters: [
25-
{left: '$', right: '$', display: false},
2625
{left: '$$', right: '$$', display: true},
26+
{left: '$', right: '$', display: false},
2727
{left: '\\(', right: '\\)', display: false},
2828
{left: '\\[', right: '\\]', display: true},
29+
{left: '\\begin{equation}', right: '\\end{equation}', display: true},
30+
{left: '\\begin{equation*}', right: '\\end{equation*}', display: true},
31+
{left: '\\begin{align}', right: '\\end{align}', display: true},
32+
{left: '\\begin{align*}', right: '\\end{align*}', display: true},
33+
{left: '\\begin{alignat}', right: '\\end{alignat}', display: true},
34+
{left: '\\begin{gather}', right: '\\end{gather}', display: true},
35+
{left: '\\begin{CD}', right: '\\end{CD}', display: true},
2936
],
3037
ignoredClasses: ['*']
3138
}));
@@ -57,9 +64,19 @@ <h6 class="card-subtitle text-muted">
5764
</div>
5865
{% endif %}
5966
</div>
60-
<div class="card-body problemstatement">
61-
{{ statement_html | safe }}
62-
</div>
67+
<ul class="list-group list-group-flush">
68+
{% if attachments %}
69+
<li class="list-group-item">
70+
<strong>Attachments:</strong>
71+
{% for name, url in attachments %}
72+
<a href="{{url}}" class="text-decoration-none">{{name}}</a>
73+
{% endfor %}
74+
</li>
75+
{% endif %}
76+
<li class="list-group-item problemstatement">
77+
{{ statement_html | safe }}
78+
</li>
79+
</ul>
6380
<div class="card-footer d-flex justify-content-between">
6481
{% if statement_authors %}
6582
<span>
@@ -74,7 +91,7 @@ <h6 class="card-subtitle text-muted">
7491
{% else %}
7592
License: {{ statement_license.display() }}
7693
{% endif %}
77-
</span>
94+
</span>
7895
</div>
7996
</div>
8097
</div>

omogenjudge/frontend/jinja2/scoreboard/view_scoreboard.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h1 class="text-center">{{ contest.title }}</h1>
5757
{% endif %}
5858
{% endfor %}
5959
<th class="text-center" style="width: 5em">Score</th>
60-
{% if contest.start_time %}
60+
{% if scoreboard.has_penalty %}
6161
<th class="text-center" style="width: 4em"
6262
{% if contest.scoring_type == 'scoring' %}
6363
data-bs-toggle="tooltip" data-bs-placement="right"
@@ -69,7 +69,13 @@ <h1 class="text-center">{{ contest.title }}</h1>
6969
{% endif %}
7070
</tr>
7171
</thead>
72+
{% set sc = namespace(upsolving_section = False, has_regular_team = False) %}
7273
{% for team in scoreboard.scoreboard_teams %}
74+
{% set sc.has_regular_team = sc.has_regular_team or team.rank %}
75+
{% if sc.has_regular_team and not sc.upsolving_section and not team.rank %}
76+
<tr class="bg-opacity-10 bg-dark"><td colspan="1000"></td></tr>
77+
{% endif %}
78+
{% set sc.upsolving_section = not team.rank %}
7379
<tr
7480
id="rank-{{ loop.index0 }}"
7581
{% if user.is_authenticated and loop.index0 == scoreboard.user_to_rank[user.account_id] %}
@@ -133,8 +139,12 @@ <h1 class="text-center">{{ contest.title }}</h1>
133139
</td>
134140
{% endfor %}
135141
<td class="text-center">{{ formatting.format_score(team.total_score) }}</td>
136-
{% if contest.start_time %}
137-
<td class="text-center">{{ scoreboard.format_tiebreak(team.tiebreak) }}</td>
142+
{% if scoreboard.has_penalty %}
143+
<td class="text-center">
144+
{% if team.virtual or (contest.start_time and not team.practice) %}
145+
{{ scoreboard.format_tiebreak(team.tiebreak) }}
146+
{% endif %}
147+
</td>
138148
{% endif %}
139149
{% endif %}
140150
</tr>

omogenjudge/frontend/js_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class JsContext:
2020
def js_context(request: OmogenRequest) -> Dict[str, str]:
2121
contest = request.contest
2222
if contest:
23-
team = contest_team_for_user(contest, request.user)
23+
team = request.team
2424
return {
2525
'js_context':
2626
json.dumps(dataclasses.asdict(JsContext(

0 commit comments

Comments
 (0)