Commit 27ac8c89 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Fix formatting

parent 7e788cad
Pipeline #564 canceled with stages
...@@ -181,16 +181,19 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str, ...@@ -181,16 +181,19 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str,
data.insert("self_url".to_string(), to_json(&self_url)); data.insert("self_url".to_string(), to_json(&self_url));
data.insert("oauth_links".to_string(), to_json(&oauth_links)); data.insert("oauth_links".to_string(), to_json(&oauth_links));
let v: Vec<ContestInfo> = let v: Vec<ContestInfo> = conn.get_contest_list()
conn.get_contest_list() .iter()
.iter() .map(|c| ContestInfo { id: c.id.unwrap(),
.map(|c| ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public, login_required: c.requires_login.unwrap_or(false) }) name: c.name.clone(),
.filter(|ci| ci.public || visibility == ContestVisibility::All) duration: c.duration,
.filter(|ci| ci.duration == 0 || visibility != ContestVisibility::Open) public: c.public,
.filter(|ci| ci.duration != 0 || visibility != ContestVisibility::Current) login_required: c.requires_login.unwrap_or(false) })
.filter(|ci| ci.login_required || visibility != ContestVisibility::LoginRequired) .filter(|ci| ci.public || visibility == ContestVisibility::All)
.filter(|ci| !ci.login_required || visibility == ContestVisibility::LoginRequired) .filter(|ci| ci.duration == 0 || visibility != ContestVisibility::Open)
.collect(); .filter(|ci| ci.duration != 0 || visibility != ContestVisibility::Current)
.filter(|ci| ci.login_required || visibility != ContestVisibility::LoginRequired)
.filter(|ci| !ci.login_required || visibility == ContestVisibility::LoginRequired)
.collect();
data.insert("contest".to_string(), to_json(&v)); data.insert("contest".to_string(), to_json(&v));
data.insert("contestlist_header".to_string(), data.insert("contestlist_header".to_string(),
to_json(&match visibility { to_json(&match visibility {
...@@ -280,7 +283,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token ...@@ -280,7 +283,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
name: contest.name.clone(), name: contest.name.clone(),
duration: contest.duration, duration: contest.duration,
public: contest.public, public: contest.public,
login_required: contest.requires_login.unwrap_or(false)}; login_required: contest.requires_login.unwrap_or(false) };
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
data.insert("contest".to_string(), to_json(&ci)); data.insert("contest".to_string(), to_json(&ci));
...@@ -419,7 +422,11 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi ...@@ -419,7 +422,11 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
data.insert("result".to_string(), to_json(&results)); data.insert("result".to_string(), to_json(&results));
let c = conn.get_contest_by_id(contest_id); let c = conn.get_contest_by_id(contest_id);
let ci = ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public, login_required: c.requires_login.unwrap_or(false)}; let ci = ContestInfo { id: c.id.unwrap(),
name: c.name.clone(),
duration: c.duration,
public: c.public,
login_required: c.requires_login.unwrap_or(false) };
data.insert("contest".to_string(), to_json(&ci)); data.insert("contest".to_string(), to_json(&ci));
data.insert("contestname".to_string(), to_json(&c.name)); data.insert("contestname".to_string(), to_json(&c.name));
......
...@@ -657,7 +657,7 @@ impl MedalConnection for Connection { ...@@ -657,7 +657,7 @@ impl MedalConnection for Connection {
logincode: row.get(10), logincode: row.get(10),
firstname: row.get(11), firstname: row.get(11),
lastname: row.get(12), lastname: row.get(12),
grade: row.get(13)}) grade: row.get(13) })
}) })
.unwrap(); .unwrap();
let mut gradeinfo_iter = gradeinfo.iter(); let mut gradeinfo_iter = gradeinfo.iter();
...@@ -723,9 +723,9 @@ impl MedalConnection for Connection { ...@@ -723,9 +723,9 @@ impl MedalConnection for Connection {
ORDER BY taskgroup.positionalnumber"; ORDER BY taskgroup.positionalnumber";
let gradeinfo = let gradeinfo =
self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0), self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0),
user: row.get(1), user: row.get(1),
grade: row.get(2), grade: row.get(2),
validated: row.get(3) }) validated: row.get(3) })
.unwrap(); .unwrap();
let gradeinfo_iter = gradeinfo.iter(); let gradeinfo_iter = gradeinfo.iter();
...@@ -1128,7 +1128,8 @@ impl MedalConnection for Connection { ...@@ -1128,7 +1128,8 @@ impl MedalConnection for Connection {
FROM participation FROM participation
GROUP BY contest GROUP BY contest
ORDER BY contest DESC;"; ORDER BY contest DESC;";
let n_participations_by_id: Vec<(i64, i64)> = self.query_map_many(query, &[], |row| (row.get(0), row.get(1))).unwrap(); let n_participations_by_id: Vec<(i64, i64)> =
self.query_map_many(query, &[], |row| (row.get(0), row.get(1))).unwrap();
format!( format!(
"{{ "{{
...@@ -1146,8 +1147,19 @@ impl MedalConnection for Connection { ...@@ -1146,8 +1147,19 @@ impl MedalConnection for Connection {
}} }}
}} }}
", ",
now.sec, n_asession, n_apart, n_session, n_user, n_pmsuser, n_teacher, n_part, n_sub, now.sec,
n_participations_by_id.iter().map(|(x,y)| -> String {format!("\"{}\": {}", x, y)}).collect::<Vec<String>>().join(",\n ") n_asession,
n_apart,
n_session,
n_user,
n_pmsuser,
n_teacher,
n_part,
n_sub,
n_participations_by_id.iter()
.map(|(x, y)| -> String { format!("\"{}\": {}", x, y) })
.collect::<Vec<String>>()
.join(",\n ")
) )
} }
......
...@@ -753,7 +753,7 @@ impl MedalConnection for Connection { ...@@ -753,7 +753,7 @@ impl MedalConnection for Connection {
logincode: row.get(10), logincode: row.get(10),
firstname: row.get(11), firstname: row.get(11),
lastname: row.get(12), lastname: row.get(12),
grade: row.get(13)}) grade: row.get(13) })
}) })
.unwrap(); .unwrap();
let mut gradeinfo_iter = gradeinfo.iter(); let mut gradeinfo_iter = gradeinfo.iter();
...@@ -819,9 +819,9 @@ impl MedalConnection for Connection { ...@@ -819,9 +819,9 @@ impl MedalConnection for Connection {
ORDER BY taskgroup.positionalnumber"; ORDER BY taskgroup.positionalnumber";
let gradeinfo = let gradeinfo =
self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0), self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0),
user: row.get(1), user: row.get(1),
grade: row.get(2), grade: row.get(2),
validated: row.get(3) }) validated: row.get(3) })
.unwrap(); .unwrap();
let gradeinfo_iter = gradeinfo.iter(); let gradeinfo_iter = gradeinfo.iter();
...@@ -1224,7 +1224,8 @@ impl MedalConnection for Connection { ...@@ -1224,7 +1224,8 @@ impl MedalConnection for Connection {
FROM participation FROM participation
GROUP BY contest GROUP BY contest
ORDER BY contest DESC;"; ORDER BY contest DESC;";
let n_participations_by_id: Vec<(i64, i64)> = self.query_map_many(query, &[], |row| (row.get(0), row.get(1))).unwrap(); let n_participations_by_id: Vec<(i64, i64)> =
self.query_map_many(query, &[], |row| (row.get(0), row.get(1))).unwrap();
format!( format!(
"{{ "{{
...@@ -1242,8 +1243,19 @@ impl MedalConnection for Connection { ...@@ -1242,8 +1243,19 @@ impl MedalConnection for Connection {
}} }}
}} }}
", ",
now.sec, n_asession, n_apart, n_session, n_user, n_pmsuser, n_teacher, n_part, n_sub, now.sec,
n_participations_by_id.iter().map(|(x,y)| -> String {format!("\"{}\": {}", x, y)}).collect::<Vec<String>>().join(",\n ") n_asession,
n_apart,
n_session,
n_user,
n_pmsuser,
n_teacher,
n_part,
n_sub,
n_participations_by_id.iter()
.map(|(x, y)| -> String { format!("\"{}\": {}", x, y) })
.collect::<Vec<String>>()
.join(",\n ")
) )
} }
......
...@@ -753,7 +753,7 @@ impl MedalConnection for Connection { ...@@ -753,7 +753,7 @@ impl MedalConnection for Connection {
logincode: row.get(10), logincode: row.get(10),
firstname: row.get(11), firstname: row.get(11),
lastname: row.get(12), lastname: row.get(12),
grade: row.get(13)}) grade: row.get(13) })
}) })
.unwrap(); .unwrap();
let mut gradeinfo_iter = gradeinfo.iter(); let mut gradeinfo_iter = gradeinfo.iter();
...@@ -819,9 +819,9 @@ impl MedalConnection for Connection { ...@@ -819,9 +819,9 @@ impl MedalConnection for Connection {
ORDER BY taskgroup.positionalnumber"; ORDER BY taskgroup.positionalnumber";
let gradeinfo = let gradeinfo =
self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0), self.query_map_many(query, &[&session_token, &contest_id, &true], |row| Grade { taskgroup: row.get(0),
user: row.get(1), user: row.get(1),
grade: row.get(2), grade: row.get(2),
validated: row.get(3) }) validated: row.get(3) })
.unwrap(); .unwrap();
let gradeinfo_iter = gradeinfo.iter(); let gradeinfo_iter = gradeinfo.iter();
...@@ -1224,7 +1224,8 @@ impl MedalConnection for Connection { ...@@ -1224,7 +1224,8 @@ impl MedalConnection for Connection {
FROM participation FROM participation
GROUP BY contest GROUP BY contest
ORDER BY contest DESC;"; ORDER BY contest DESC;";
let n_participations_by_id: Vec<(i64, i64)> = self.query_map_many(query, &[], |row| (row.get(0), row.get(1))).unwrap(); let n_participations_by_id: Vec<(i64, i64)> =
self.query_map_many(query, &[], |row| (row.get(0), row.get(1))).unwrap();
format!( format!(
"{{ "{{
...@@ -1242,8 +1243,19 @@ impl MedalConnection for Connection { ...@@ -1242,8 +1243,19 @@ impl MedalConnection for Connection {
}} }}
}} }}
", ",
now.sec, n_asession, n_apart, n_session, n_user, n_pmsuser, n_teacher, n_part, n_sub, now.sec,
n_participations_by_id.iter().map(|(x,y)| -> String {format!("\"{}\": {}", x, y)}).collect::<Vec<String>>().join(",\n ") n_asession,
n_apart,
n_session,
n_user,
n_pmsuser,
n_teacher,
n_part,
n_sub,
n_participations_by_id.iter()
.map(|(x, y)| -> String { format!("\"{}\": {}", x, y) })
.collect::<Vec<String>>()
.join(",\n ")
) )
} }
......
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