Commit 00c4059f authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Show contest result summary on contest page

parent 319f061c
Pipeline #144 passed with stages
in 17 minutes and 14 seconds
......@@ -177,13 +177,17 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
let c = conn.get_contest_by_id_complete(contest_id);
let grades = conn.get_contest_user_grades(&session_token, contest_id);
// TODO: Clean up star generation
let mut totalgrade = 0;
let mut max_totalgrade = 0;
let mut tasks = Vec::new();
for (task, grade) in c.taskgroups.into_iter().zip(grades) {
let mut subtaskstars = generate_subtaskstars(&task, &grade, None);
let ti = TaskInfo { name: task.name, subtasks: subtaskstars };
for (taskgroup, grade) in c.taskgroups.into_iter().zip(grades) {
let mut subtaskstars = generate_subtaskstars(&taskgroup, &grade, None);
let ti = TaskInfo { name: taskgroup.name, subtasks: subtaskstars };
tasks.push(ti);
totalgrade += i32::from(grade.grade.unwrap_or(0));
max_totalgrade += i32::from(taskgroup.tasks.iter().map(|x| x.stars).max().unwrap_or(0));
}
let ci = ContestInfo { id: c.id.unwrap(),
......@@ -221,12 +225,16 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
}
data.insert("participation_start_date".to_string(), to_json(&format!("{}", passed_secs)));
data.insert("total_points".to_string(), to_json(&totalgrade));
data.insert("max_total_points".to_string(), to_json(&max_totalgrade));
data.insert("relative_points".to_string(), to_json(&((totalgrade * 100) / max_totalgrade)));
let left_secs = i64::from(ci.duration) * 60 - passed_secs;
if left_secs < 0 {
// Contest over
data.insert("is_time_left".to_string(), to_json(&false));
} else {
data.insert("is_time_left".to_string(), to_json(&true));
let left_min = left_secs / 60;
let left_sec = left_secs % 60;
if left_sec < 10 {
......
......@@ -29,6 +29,11 @@
</p>
{{/each}}
<hr>
<p>
Punktestand: {{ total_points }} ★ / {{ max_total_points }}&nbsp; ({{ relative_points }} %)
</p>
{{else}}
{{#if can_start}}
......
......@@ -69,37 +69,42 @@
{{#if contest.duration}}<h4 class="subtitle is-5">Dauer: {{contest.duration}} Minuten</h4>{{/if}}
{{#if participation_start_date}}
<p>
{{#if time_left}}
Verbleibenden Zeit: {{time_left}}
{{/if}}
</p>
<p>
{{#if time_left}}
Verbleibenden Zeit: {{time_left}}
{{/if}}
</p>
{{#each contest.tasks}}
<div style="margin: 10px;">
{{name}}:
{{#each contest.tasks}}
<div style="margin: 10px;">
{{name}}
<ul>
{{#each subtasks}}
<li><a href="/task/{{id}}">{{linktext}}</a></li>
{{/each}}
</ul>
</div>
{{/each}}
<ul>
{{#each subtasks}}
<li><a href="/task/{{id}}">{{linktext}}</a></li>
{{/each}}
</ul>
</div>
{{/each}}
{{else}}
<hr>
<p>
Punktestand: {{ total_points }} ★ / {{ max_total_points }}&nbsp; ({{ relative_points }} %)
</p>
{{else}}
{{#if can_start}}
<p>
<form action="" method="post">
<input type="hidden" name="csrftoken" value="{{csrftoken}}">
<input class="button is-warning" type="submit" value="⏱ &nbsp; Jetzt starten!">
</form>
</p>
{{#if can_start}}
<p>
<form action="" method="post">
<input type="hidden" name="csrftoken" value="{{csrftoken}}">
<input class="button is-warning" type="submit" value="⏱ &nbsp; Jetzt starten!">
</form>
</p>
<p>Der Wettbewerb kann nach dem Starten nicht mehr pausiert werden.</p>
{{/if}}
<p>Der Wettbewerb kann nach dem Starten nicht mehr pausiert werden.</p>
{{/if}}
{{/if}}
</div>
</div>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment