forked from Ruderverein-Donau-Linz/rowt
Merge pull request 'show amount of trips in stat' (#834) from show-amount-trips into main
Reviewed-on: Ruderverein-Donau-Linz/rowt#834
This commit is contained in:
commit
09d4c0abe4
@ -98,6 +98,7 @@ ORDER BY
|
|||||||
#[derive(FromRow, Serialize, Clone)]
|
#[derive(FromRow, Serialize, Clone)]
|
||||||
pub struct Stat {
|
pub struct Stat {
|
||||||
name: String,
|
name: String,
|
||||||
|
pub(crate) amount_trips: i32,
|
||||||
pub(crate) rowed_km: i32,
|
pub(crate) rowed_km: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,9 +109,11 @@ impl Stat {
|
|||||||
None => chrono::Local::now().year(),
|
None => chrono::Local::now().year(),
|
||||||
};
|
};
|
||||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||||
let rowed_km = sqlx::query(&format!(
|
// proper guests
|
||||||
|
let guests = sqlx::query(&format!(
|
||||||
"
|
"
|
||||||
SELECT SUM((b.amount_seats - COALESCE(m.member_count, 0)) * l.distance_in_km) as total_guest_km
|
SELECT SUM((b.amount_seats - COALESCE(m.member_count, 0)) * l.distance_in_km) as total_guest_km,
|
||||||
|
SUM(b.amount_seats - COALESCE(m.member_count, 0)) AS amount_trips
|
||||||
FROM logbook l
|
FROM logbook l
|
||||||
JOIN boat b ON l.boat_id = b.id
|
JOIN boat b ON l.boat_id = b.id
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
@ -123,12 +126,15 @@ WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' AND not b.exter
|
|||||||
))
|
))
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap();
|
||||||
.get::<i64, usize>(0) as i32;
|
|
||||||
|
|
||||||
let rowed_km_guests = sqlx::query(&format!(
|
let guest_km: i32 = guests.get(0);
|
||||||
|
let guest_amount_trips: i32 = guests.get(1);
|
||||||
|
|
||||||
|
// e.g. scheckbücher
|
||||||
|
let guest_user = sqlx::query(&format!(
|
||||||
"
|
"
|
||||||
SELECT CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
|
SELECT CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km, COUNT(*) AS amount_trips
|
||||||
FROM user u
|
FROM user u
|
||||||
INNER JOIN rower r ON u.id = r.rower_id
|
INNER JOIN rower r ON u.id = r.rower_id
|
||||||
INNER JOIN logbook l ON r.logbook_id = l.id
|
INNER JOIN logbook l ON r.logbook_id = l.id
|
||||||
@ -145,15 +151,27 @@ AND u.name != 'Externe Steuerperson';
|
|||||||
))
|
))
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap();
|
||||||
.get::<i64, usize>(0) as i32;
|
|
||||||
|
let guest_user_km: i32 = guest_user.get(0);
|
||||||
|
let guest_user_amount_trips: i32 = guest_user.get(1);
|
||||||
|
|
||||||
Stat {
|
Stat {
|
||||||
name: "Gäste".into(),
|
name: "Gäste".into(),
|
||||||
rowed_km: rowed_km + rowed_km_guests,
|
amount_trips: guest_amount_trips + guest_user_amount_trips,
|
||||||
|
rowed_km: guest_km + guest_user_km,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn trips_people(db: &SqlitePool, year: Option<i32>) -> i32 {
|
||||||
|
let stats = Self::people(db, year).await;
|
||||||
|
let mut sum = 0;
|
||||||
|
for stat in stats {
|
||||||
|
sum += stat.amount_trips;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum
|
||||||
|
}
|
||||||
pub async fn sum_people(db: &SqlitePool, year: Option<i32>) -> i32 {
|
pub async fn sum_people(db: &SqlitePool, year: Option<i32>) -> i32 {
|
||||||
let stats = Self::people(db, year).await;
|
let stats = Self::people(db, year).await;
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
@ -172,7 +190,7 @@ AND u.name != 'Externe Steuerperson';
|
|||||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||||
sqlx::query(&format!(
|
sqlx::query(&format!(
|
||||||
"
|
"
|
||||||
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
|
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km, COUNT(*) AS amount_trips
|
||||||
FROM (
|
FROM (
|
||||||
SELECT * FROM user
|
SELECT * FROM user
|
||||||
WHERE id IN (
|
WHERE id IN (
|
||||||
@ -194,6 +212,7 @@ ORDER BY rowed_km DESC, u.name;
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|row| Stat {
|
.map(|row| Stat {
|
||||||
name: row.get("name"),
|
name: row.get("name"),
|
||||||
|
amount_trips: row.get("amount_trips"),
|
||||||
rowed_km: row.get("rowed_km"),
|
rowed_km: row.get("rowed_km"),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@ -203,7 +222,7 @@ ORDER BY rowed_km DESC, u.name;
|
|||||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||||
let row = sqlx::query(&format!(
|
let row = sqlx::query(&format!(
|
||||||
"
|
"
|
||||||
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
|
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km, COUNT(*) AS amount_trips
|
||||||
FROM (
|
FROM (
|
||||||
SELECT * FROM user
|
SELECT * FROM user
|
||||||
WHERE id={}
|
WHERE id={}
|
||||||
@ -220,6 +239,7 @@ WHERE l.distance_in_km IS NOT NULL;
|
|||||||
|
|
||||||
Stat {
|
Stat {
|
||||||
name: row.get("name"),
|
name: row.get("name"),
|
||||||
|
amount_trips: row.get("amount_trips"),
|
||||||
rowed_km: row.get("rowed_km"),
|
rowed_km: row.get("rowed_km"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,7 +252,7 @@ WHERE l.distance_in_km IS NOT NULL;
|
|||||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||||
let row = sqlx::query(&format!(
|
let row = sqlx::query(&format!(
|
||||||
"
|
"
|
||||||
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
|
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km, COUNT(*) AS amount_trips
|
||||||
FROM (
|
FROM (
|
||||||
SELECT * FROM user
|
SELECT * FROM user
|
||||||
WHERE id={}
|
WHERE id={}
|
||||||
@ -249,6 +269,7 @@ WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%';
|
|||||||
|
|
||||||
Stat {
|
Stat {
|
||||||
name: row.get("name"),
|
name: row.get("name"),
|
||||||
|
amount_trips: row.get("amount_trips"),
|
||||||
rowed_km: row.get("rowed_km"),
|
rowed_km: row.get("rowed_km"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,14 @@ async fn index_boat_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Templa
|
|||||||
async fn index(db: &State<SqlitePool>, user: DonauLinzUser, year: Option<i32>) -> Template {
|
async fn index(db: &State<SqlitePool>, user: DonauLinzUser, year: Option<i32>) -> Template {
|
||||||
let stat = Stat::people(db, year).await;
|
let stat = Stat::people(db, year).await;
|
||||||
let club_km = Stat::sum_people(db, year).await;
|
let club_km = Stat::sum_people(db, year).await;
|
||||||
|
let club_trips = Stat::trips_people(db, year).await;
|
||||||
let guest_km = Stat::guest(db, year).await;
|
let guest_km = Stat::guest(db, year).await;
|
||||||
let personal = stat::get_personal(db, &user).await;
|
let personal = stat::get_personal(db, &user).await;
|
||||||
let kiosk = false;
|
let kiosk = false;
|
||||||
|
|
||||||
Template::render(
|
Template::render(
|
||||||
"stat.people",
|
"stat.people",
|
||||||
context!(loggedin_user: &UserWithDetails::from_user(user.into_inner(), db).await, stat, personal, kiosk, guest_km, club_km),
|
context!(loggedin_user: &UserWithDetails::from_user(user.into_inner(), db).await, stat, personal, kiosk, guest_km, club_km, club_trips),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="filter-result-js" class="search-result"></div>
|
<div id="filter-result-js" class="search-result"></div>
|
||||||
<div class="border-r border-l border-gray-200 dark:border-primary-600">
|
<div class="border-r border-l border-gray-200 dark:border-primary-600">
|
||||||
{% set_global km = 0 %} {% set_global index = 1 %}
|
{% set_global km = 0 %} {% set_global km = 0 %} {% set_global index = 1 %}
|
||||||
{% for s in stat %}
|
{% for s in stat %}
|
||||||
<div class="border-t border-gray-200 dark:border-primary-600 bg-white dark:bg-primary-900 text-black dark:text-white flex justify-between items-center px-3 py-1"
|
<div class="border-t border-gray-200 dark:border-primary-600 bg-white dark:bg-primary-900 text-black dark:text-white flex justify-between items-center px-3 py-1"
|
||||||
data-filterable="true"
|
data-filterable="true"
|
||||||
@ -35,6 +35,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<span class="grow">{{ s.name }}</span>
|
<span class="grow">{{ s.name }}</span>
|
||||||
<span>{{ s.rowed_km }} km</span>
|
<span>{{ s.rowed_km }} km</span>
|
||||||
|
<span class="pl-3">{{ s.amount_trips }} Fahrt{{ s.amount_trips | pluralize(plural="en") }}</span>
|
||||||
{% set_global km = s.rowed_km %}
|
{% set_global km = s.rowed_km %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -44,6 +45,7 @@
|
|||||||
<span class="text-sm text-gray-600 dark:text-gray-100 w-10"></span>
|
<span class="text-sm text-gray-600 dark:text-gray-100 w-10"></span>
|
||||||
<span class="grow"><b>Summe Vereinsmitglieder</b></span>
|
<span class="grow"><b>Summe Vereinsmitglieder</b></span>
|
||||||
<span><b>{{ club_km }} km</b></span>
|
<span><b>{{ club_km }} km</b></span>
|
||||||
|
<span class="pl-3"><b>{{ club_trips }} Fahrt{{ club_trips | pluralize(plural="en") }}</b></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="border-t border-gray-200 dark:border-primary-600 bg-white dark:bg-primary-900 text-black dark:text-white flex justify-between items-center px-3 py-1"
|
<div class="border-t border-gray-200 dark:border-primary-600 bg-white dark:bg-primary-900 text-black dark:text-white flex justify-between items-center px-3 py-1"
|
||||||
data-filterable="false"
|
data-filterable="false"
|
||||||
@ -51,6 +53,7 @@
|
|||||||
<span class="text-sm text-gray-600 dark:text-gray-100 w-10"></span>
|
<span class="text-sm text-gray-600 dark:text-gray-100 w-10"></span>
|
||||||
<span class="grow"><b>Summe {{ guest_km.name }}</b></span>
|
<span class="grow"><b>Summe {{ guest_km.name }}</b></span>
|
||||||
<span><b>{{ guest_km.rowed_km }} km</b></span>
|
<span><b>{{ guest_km.rowed_km }} km</b></span>
|
||||||
|
<span class="pl-3"><b>{{ guest_km.amount_trips }} Fahrt{{ guest_km.amount_trips | pluralize(plural="en") }}</b></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="border-t border-gray-200 dark:border-primary-600 border-b bg-white dark:bg-primary-900 text-black dark:text-white flex justify-between items-center px-3 py-1"
|
<div class="border-t border-gray-200 dark:border-primary-600 border-b bg-white dark:bg-primary-900 text-black dark:text-white flex justify-between items-center px-3 py-1"
|
||||||
data-filterable="false"
|
data-filterable="false"
|
||||||
@ -58,6 +61,7 @@
|
|||||||
<span class="text-sm text-gray-600 dark:text-gray-100 w-10"></span>
|
<span class="text-sm text-gray-600 dark:text-gray-100 w-10"></span>
|
||||||
<span class="grow"><b>Gesamtsumme</b></span>
|
<span class="grow"><b>Gesamtsumme</b></span>
|
||||||
<span><b>{{ club_km + guest_km.rowed_km }} km</b></span>
|
<span><b>{{ club_km + guest_km.rowed_km }} km</b></span>
|
||||||
|
<span class="pl-3"><b>{{ guest_km.amount_trips + club_trips }} Fahrt{{ guest_km.amount_trips + club_trips | pluralize(plural="en") }}</b></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="container" class="w-full"></div>
|
<div id="container" class="w-full"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user