Merge pull request 'be able to show total km of each rower' (#1173) from show-full-stats into main
Reviewed-on: #1173
This commit was merged in pull request #1173.
This commit is contained in:
@@ -104,9 +104,11 @@ pub struct Stat {
|
||||
|
||||
impl Stat {
|
||||
pub async fn guest(db: &SqlitePool, year: Option<i32>) -> Stat {
|
||||
let year = match year {
|
||||
Some(year) => year,
|
||||
None => chrono::Local::now().year(),
|
||||
let year = year.unwrap_or_else(|| chrono::Local::now().year());
|
||||
let year_filter = if year == 0 {
|
||||
String::new()
|
||||
} else {
|
||||
format!("AND l.arrival LIKE '{}-%'", year)
|
||||
};
|
||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||
// proper guests
|
||||
@@ -121,7 +123,7 @@ LEFT JOIN (
|
||||
FROM rower
|
||||
GROUP BY logbook_id
|
||||
) m ON l.id = m.logbook_id
|
||||
WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' AND not b.external;
|
||||
WHERE l.distance_in_km IS NOT NULL {year_filter} AND not b.external;
|
||||
"
|
||||
))
|
||||
.fetch_one(db)
|
||||
@@ -145,7 +147,7 @@ WHERE u.id NOT IN (
|
||||
WHERE ro.name = 'Donau Linz'
|
||||
)
|
||||
AND l.distance_in_km IS NOT NULL
|
||||
AND l.arrival LIKE '{year}-%'
|
||||
{year_filter}
|
||||
AND u.name != 'Externe Steuerperson';
|
||||
"
|
||||
))
|
||||
@@ -183,25 +185,27 @@ AND u.name != 'Externe Steuerperson';
|
||||
}
|
||||
|
||||
pub async fn people(db: &SqlitePool, year: Option<i32>) -> Vec<Stat> {
|
||||
let year = match year {
|
||||
Some(year) => year,
|
||||
None => chrono::Local::now().year(),
|
||||
let year = year.unwrap_or_else(|| chrono::Local::now().year());
|
||||
let year_filter = if year == 0 {
|
||||
String::new()
|
||||
} else {
|
||||
format!("AND l.arrival LIKE '{}-%'", year)
|
||||
};
|
||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||
sqlx::query(&format!(
|
||||
"
|
||||
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km, COUNT(*) AS amount_trips
|
||||
FROM (
|
||||
SELECT * FROM user
|
||||
SELECT * FROM user
|
||||
WHERE id IN (
|
||||
SELECT user_id FROM user_role
|
||||
JOIN role ON user_role.role_id = role.id
|
||||
SELECT user_id FROM user_role
|
||||
JOIN role ON user_role.role_id = role.id
|
||||
WHERE role.name = 'Donau Linz'
|
||||
)
|
||||
) u
|
||||
INNER JOIN rower r ON u.id = r.rower_id
|
||||
INNER JOIN logbook l ON r.logbook_id = l.id
|
||||
WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' AND u.name != 'Externe Steuerperson'
|
||||
WHERE l.distance_in_km IS NOT NULL {year_filter} AND u.name != 'Externe Steuerperson'
|
||||
GROUP BY u.name
|
||||
ORDER BY rowed_km DESC, u.name;
|
||||
"
|
||||
|
||||
@@ -78,11 +78,12 @@
|
||||
var queryParams = new URLSearchParams(window.location.search);
|
||||
return queryParams.get('year');
|
||||
}
|
||||
|
||||
|
||||
function populateYears() {
|
||||
var select = document.getElementById('yearSelect');
|
||||
var currentYear = new Date().getFullYear();
|
||||
var selectedYear = getYearFromURL() || currentYear;
|
||||
|
||||
for (var year = 1977; year <= currentYear; year++) {
|
||||
var option = document.createElement('option');
|
||||
option.value = option.textContent = year;
|
||||
@@ -91,13 +92,21 @@
|
||||
}
|
||||
select.appendChild(option);
|
||||
}
|
||||
|
||||
var gesamtOption = document.createElement('option');
|
||||
gesamtOption.value = 0;
|
||||
gesamtOption.textContent = 'GESAMT';
|
||||
if (selectedYear == 0) {
|
||||
gesamtOption.selected = true;
|
||||
}
|
||||
select.appendChild(gesamtOption);
|
||||
}
|
||||
|
||||
|
||||
function changeYear() {
|
||||
var selectedYear = document.getElementById('yearSelect').value;
|
||||
window.location.href = '?year=' + selectedYear;
|
||||
}
|
||||
|
||||
|
||||
populateYears();
|
||||
</script>
|
||||
{% endblock content %}
|
||||
|
||||
Reference in New Issue
Block a user