Commit 7a41e250 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Sort students by grades in contest results

parent 1a731d9a
Pipeline #539 canceled with stage
......@@ -57,6 +57,21 @@ fn fill_user_data(session: &SessionUser, data: &mut json_val::Map<String, serde_
data.insert("parent".to_string(), to_json(&"base"));
}
fn grade_to_string(grade: i32) -> String {
match grade {
0 => "Noch kein Schüler".to_string(),
n @ 1..=10 => format!("{}", n),
11 => "11 (G8)".to_string(),
12 => "12 (G8)".to_string(),
111 => "11 (G9)".to_string(),
112 => "12 (G9)".to_string(),
113 => "13 (G9)".to_string(),
114 => "Berufsschule".to_string(),
255 => "Kein Schüler mehr".to_string(),
_ => "?".to_string(),
}
}
pub fn index<T: MedalConnection>(conn: &T, session_token: Option<String>,
(self_url, oauth_providers): (Option<String>, Option<Vec<OauthProvider>>))
-> (String, json_val::Map<String, json_val::Value>)
......@@ -361,10 +376,10 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
let (tasknames, resultdata) = conn.get_contest_groups_grades(session.id, contest_id);
let mut results: Vec<(String, i32, Vec<(String, String, i32, Vec<String>)>)> = Vec::new();
let mut results: Vec<(String, i32, Vec<(String, String, i32, String, Vec<String>)>)> = Vec::new();
for (group, groupdata) in resultdata {
let mut groupresults: Vec<(String, String, i32, Vec<String>)> = Vec::new();
let mut groupresults: Vec<(String, String, i32, String, Vec<String>)> = Vec::new();
//TODO: use user
for (user, userdata) in groupdata {
......@@ -387,6 +402,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
groupresults.push((user.firstname.unwrap_or_else(|| "–".to_string()),
user.lastname.unwrap_or_else(|| "–".to_string()),
user.id,
grade_to_string(user.grade),
userresults))
}
......@@ -673,18 +689,7 @@ pub fn show_group<T: MedalConnection>(conn: &T, group_id: i32, session_token: &s
.map(|m| MemberInfo { id: m.id,
firstname: m.firstname.clone().unwrap_or_else(|| "".to_string()),
lastname: m.lastname.clone().unwrap_or_else(|| "".to_string()),
grade: match m.grade {
0 => "Noch kein Schüler".to_string(),
n @ 1..=10 => format!("{}", n),
11 => "11 (G8)".to_string(),
12 => "12 (G8)".to_string(),
111 => "11 (G9)".to_string(),
112 => "12 (G9)".to_string(),
113 => "13 (G9)".to_string(),
114 => "Berufsschule".to_string(),
255 => "Kein Schüler mehr".to_string(),
_ => "?".to_string(),
},
grade: grade_to_string(m.grade),
logincode: m.logincode.clone().unwrap_or_else(|| "".to_string()) })
.collect();
......
......@@ -629,7 +629,7 @@ impl MedalConnection for Connection {
let query = "SELECT grade.taskgroup, grade.session, grade.grade, grade.validated, usergroup.id, usergroup.name,
usergroup.groupcode, usergroup.tag, student.id, student.username, student.logincode,
student.firstname, student.lastname
student.firstname, student.lastname, student.grade AS sgrade
FROM grade
JOIN taskgroup ON grade.taskgroup = taskgroup.id
JOIN session AS student ON grade.session = student.id
......@@ -637,7 +637,7 @@ impl MedalConnection for Connection {
WHERE usergroup.admin = $1
AND taskgroup.contest = $2
AND taskgroup.active = $3
ORDER BY usergroup.id, student.id, taskgroup.positionalnumber";
ORDER BY usergroup.id, sgrade, student.lastname, taskgroup.positionalnumber";
let gradeinfo =
self.query_map_many(query, &[&session_id, &contest_id, &true], |row| {
(Grade { taskgroup: row.get(0), user: row.get(1), grade: row.get(2), validated: row.get(3) },
......@@ -651,7 +651,8 @@ impl MedalConnection for Connection {
username: row.get(9),
logincode: row.get(10),
firstname: row.get(11),
lastname: row.get(12) })
lastname: row.get(12),
grade: row.get(13)})
})
.unwrap();
let mut gradeinfo_iter = gradeinfo.iter();
......
......@@ -725,7 +725,7 @@ impl MedalConnection for Connection {
let query = "SELECT grade.taskgroup, grade.session, grade.grade, grade.validated, usergroup.id, usergroup.name,
usergroup.groupcode, usergroup.tag, student.id, student.username, student.logincode,
student.firstname, student.lastname
student.firstname, student.lastname, student.grade AS sgrade
FROM grade
JOIN taskgroup ON grade.taskgroup = taskgroup.id
JOIN session AS student ON grade.session = student.id
......@@ -733,7 +733,7 @@ impl MedalConnection for Connection {
WHERE usergroup.admin = $1
AND taskgroup.contest = $2
AND taskgroup.active = $3
ORDER BY usergroup.id, student.id, taskgroup.positionalnumber";
ORDER BY usergroup.id, sgrade, student.lastname, taskgroup.positionalnumber";
let gradeinfo =
self.query_map_many(query, &[&session_id, &contest_id, &true], |row| {
(Grade { taskgroup: row.get(0), user: row.get(1), grade: row.get(2), validated: row.get(3) },
......@@ -747,7 +747,8 @@ impl MedalConnection for Connection {
username: row.get(9),
logincode: row.get(10),
firstname: row.get(11),
lastname: row.get(12) })
lastname: row.get(12),
grade: row.get(13)})
})
.unwrap();
let mut gradeinfo_iter = gradeinfo.iter();
......@@ -813,9 +814,9 @@ impl MedalConnection for Connection {
ORDER BY taskgroup.positionalnumber";
let gradeinfo =
self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0),
user: row.get(1),
grade: row.get(2),
validated: row.get(3) })
user: row.get(1),
grade: row.get(2),
validated: row.get(3) })
.unwrap();
let gradeinfo_iter = gradeinfo.iter();
......
......@@ -725,7 +725,7 @@ impl MedalConnection for Connection {
let query = "SELECT grade.taskgroup, grade.session, grade.grade, grade.validated, usergroup.id, usergroup.name,
usergroup.groupcode, usergroup.tag, student.id, student.username, student.logincode,
student.firstname, student.lastname
student.firstname, student.lastname, student.grade AS sgrade
FROM grade
JOIN taskgroup ON grade.taskgroup = taskgroup.id
JOIN session AS student ON grade.session = student.id
......@@ -733,7 +733,7 @@ impl MedalConnection for Connection {
WHERE usergroup.admin = ?1
AND taskgroup.contest = ?2
AND taskgroup.active = ?3
ORDER BY usergroup.id, student.id, taskgroup.positionalnumber";
ORDER BY usergroup.id, sgrade, student.lastname, taskgroup.positionalnumber";
let gradeinfo =
self.query_map_many(query, &[&session_id, &contest_id, &true], |row| {
(Grade { taskgroup: row.get(0), user: row.get(1), grade: row.get(2), validated: row.get(3) },
......@@ -747,7 +747,8 @@ impl MedalConnection for Connection {
username: row.get(9),
logincode: row.get(10),
firstname: row.get(11),
lastname: row.get(12) })
lastname: row.get(12),
grade: row.get(13)})
})
.unwrap();
let mut gradeinfo_iter = gradeinfo.iter();
......@@ -813,9 +814,9 @@ impl MedalConnection for Connection {
ORDER BY taskgroup.positionalnumber";
let gradeinfo =
self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0),
user: row.get(1),
grade: row.get(2),
validated: row.get(3) })
user: row.get(1),
grade: row.get(2),
validated: row.get(3) })
.unwrap();
let gradeinfo_iter = gradeinfo.iter();
......
......@@ -47,6 +47,7 @@ pub struct UserInfo {
pub logincode: Option<String>,
pub firstname: Option<String>,
pub lastname: Option<String>,
pub grade: i32,
}
#[derive(Clone)]
......
......@@ -28,7 +28,7 @@
{{#each this.2}}
<tr><td></td>
<td><a href="/user/{{this.1}}">{{this.0}}</a></td>
{{#each this.2}}
{{#each this.4}}
<td>{{this}}</td>
{{/each}}
{{/each}}
......
Gruppe,Vorname,Nachname,Gesamtpunkte{{#each taskname}},{{this}}{{/each}}
{{#each result}}{{#each this.2}}{{../0}},{{this.0}},{{this.1}}{{#each this.3}},{{this}}{{/each}}
{{/each}}{{/each}}
\ No newline at end of file
Gruppe,Vorname,Nachname,Jahrgangsstufe,Gesamtpunkte{{#each taskname}},{{this}}{{/each}}
{{#each result}}{{#each this.2}}{{../0}},{{this.0}},{{this.1}},{{this.3}}{{#each this.4}},{{this}}{{/each}}
{{/each}}{{/each}}
......@@ -44,8 +44,8 @@
<tr style="background-color:#e5fae5;"><td style="max-width:200px;"><a href="/group/{{this.1}}">{{this.0}}</a></td><td colspan="12"></td></tr>
{{#each this.2}}
<tr><td></td>
<td><a href="/user/{{this.2}}">{{this.0}} {{this.1}}</a></td>
{{#each this.3}}
<td><a href="/user/{{this.2}}">{{this.0}} {{this.1}} ({{this.3}})</a></td>
{{#each this.4}}
<td>{{this}}</td>
{{/each}}
{{/each}}
......
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