give proper results for stats
This commit is contained in:
parent
d838a1ca68
commit
826402cd41
@ -50,18 +50,36 @@ pub struct PersonalStat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_personal(db: &SqlitePool, user: &User) -> Vec<PersonalStat> {
|
pub async fn get_personal(db: &SqlitePool, user: &User) -> Vec<PersonalStat> {
|
||||||
vec![
|
sqlx::query(&format!(
|
||||||
PersonalStat {
|
"
|
||||||
date: String::from("2023-01-01"),
|
SELECT
|
||||||
km: 5,
|
departure_date as date,
|
||||||
},
|
SUM(total_distance) OVER (ORDER BY departure_date) as km
|
||||||
PersonalStat {
|
FROM (
|
||||||
date: String::from("2023-02-01"),
|
SELECT
|
||||||
km: 24,
|
date(l.departure) as departure_date,
|
||||||
},
|
COALESCE(SUM(l.distance_in_km),0) as total_distance
|
||||||
PersonalStat {
|
FROM
|
||||||
date: String::from("2023-08-30"),
|
logbook l
|
||||||
km: 1340,
|
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 stat = Stat::get_rowed_km(db).await;
|
||||||
let personal = stat::get_personal(db, &user).await;
|
let personal = stat::get_personal(db, &user).await;
|
||||||
|
|
||||||
|
println!("{personal:?}");
|
||||||
Template::render("stat", context!(loggedin_user: &user, stat, personal))
|
Template::render("stat", context!(loggedin_user: &user, stat, personal))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user