give proper results for stats
This commit is contained in:
parent
78bb6cfa75
commit
a2dfd26841
@ -50,18 +50,36 @@ pub struct PersonalStat {
|
||||
}
|
||||
|
||||
pub async fn get_personal(db: &SqlitePool, user: &User) -> Vec<PersonalStat> {
|
||||
vec![
|
||||
PersonalStat {
|
||||
date: String::from("2023-01-01"),
|
||||
km: 5,
|
||||
},
|
||||
PersonalStat {
|
||||
date: String::from("2023-02-01"),
|
||||
km: 24,
|
||||
},
|
||||
PersonalStat {
|
||||
date: String::from("2023-08-30"),
|
||||
km: 1340,
|
||||
},
|
||||
]
|
||||
sqlx::query(&format!(
|
||||
"
|
||||
SELECT
|
||||
departure_date as date,
|
||||
SUM(total_distance) OVER (ORDER BY departure_date) as km
|
||||
FROM (
|
||||
SELECT
|
||||
date(l.departure) as departure_date,
|
||||
COALESCE(SUM(l.distance_in_km),0) as total_distance
|
||||
FROM
|
||||
logbook l
|
||||
LEFT JOIN
|
||||
rower r ON l.id = r.logbook_id
|
||||
WHERE
|
||||
l.shipmaster = {0} OR r.rower_id = {0}
|
||||
GROUP BY
|
||||
departure_date
|
||||
) as subquery
|
||||
ORDER BY
|
||||
departure_date;
|
||||
",
|
||||
user.id
|
||||
))
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|row| PersonalStat {
|
||||
date: row.get("date"),
|
||||
km: row.get("km"),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ async fn index(db: &State<SqlitePool>, user: User) -> Template {
|
||||
let stat = Stat::get_rowed_km(db).await;
|
||||
let personal = stat::get_personal(db, &user).await;
|
||||
|
||||
println!("{personal:?}");
|
||||
Template::render("stat", context!(loggedin_user: &user, stat, personal))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user