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 ...@@ -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 c = conn.get_contest_by_id_complete(contest_id);
let grades = conn.get_contest_user_grades(&session_token, 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(); let mut tasks = Vec::new();
for (task, grade) in c.taskgroups.into_iter().zip(grades) { for (taskgroup, grade) in c.taskgroups.into_iter().zip(grades) {
let mut subtaskstars = generate_subtaskstars(&task, &grade, None); let mut subtaskstars = generate_subtaskstars(&taskgroup, &grade, None);
let ti = TaskInfo { name: task.name, subtasks: subtaskstars }; let ti = TaskInfo { name: taskgroup.name, subtasks: subtaskstars };
tasks.push(ti); 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(), let ci = ContestInfo { id: c.id.unwrap(),
...@@ -221,12 +225,16 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token ...@@ -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("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; let left_secs = i64::from(ci.duration) * 60 - passed_secs;
if left_secs < 0 { if left_secs < 0 {
// Contest over // Contest over
data.insert("is_time_left".to_string(), to_json(&false));
} else { } else {
data.insert("is_time_left".to_string(), to_json(&true));
let left_min = left_secs / 60; let left_min = left_secs / 60;
let left_sec = left_secs % 60; let left_sec = left_secs % 60;
if left_sec < 10 { if left_sec < 10 {
......
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
</p> </p>
{{/each}} {{/each}}
<hr>
<p>
Punktestand: {{ total_points }} ★ / {{ max_total_points }}&nbsp; ({{ relative_points }} %)
</p>
{{else}} {{else}}
{{#if can_start}} {{#if can_start}}
......
...@@ -69,37 +69,42 @@ ...@@ -69,37 +69,42 @@
{{#if contest.duration}}<h4 class="subtitle is-5">Dauer: {{contest.duration}} Minuten</h4>{{/if}} {{#if contest.duration}}<h4 class="subtitle is-5">Dauer: {{contest.duration}} Minuten</h4>{{/if}}
{{#if participation_start_date}} {{#if participation_start_date}}
<p> <p>
{{#if time_left}} {{#if time_left}}
Verbleibenden Zeit: {{time_left}} Verbleibenden Zeit: {{time_left}}
{{/if}} {{/if}}
</p> </p>
{{#each contest.tasks}} {{#each contest.tasks}}
<div style="margin: 10px;"> <div style="margin: 10px;">
{{name}}: {{name}}
<ul> <ul>
{{#each subtasks}} {{#each subtasks}}
<li><a href="/task/{{id}}">{{linktext}}</a></li> <li><a href="/task/{{id}}">{{linktext}}</a></li>
{{/each}} {{/each}}
</ul> </ul>
</div> </div>
{{/each}} {{/each}}
{{else}} <hr>
<p>
Punktestand: {{ total_points }} ★ / {{ max_total_points }}&nbsp; ({{ relative_points }} %)
</p>
{{else}}
{{#if can_start}} {{#if can_start}}
<p> <p>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="csrftoken" value="{{csrftoken}}"> <input type="hidden" name="csrftoken" value="{{csrftoken}}">
<input class="button is-warning" type="submit" value="⏱ &nbsp; Jetzt starten!"> <input class="button is-warning" type="submit" value="⏱ &nbsp; Jetzt starten!">
</form> </form>
</p> </p>
<p>Der Wettbewerb kann nach dem Starten nicht mehr pausiert werden.</p> <p>Der Wettbewerb kann nach dem Starten nicht mehr pausiert werden.</p>
{{/if}}
{{/if}} {{/if}}
{{/if}}
</div> </div>
</div> </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