diff --git a/application/src/app.rs b/application/src/app.rs index 63831ad..71677c9 100644 --- a/application/src/app.rs +++ b/application/src/app.rs @@ -1,3 +1,4 @@ +#![feature(diagnostic_namespace)] use crate::error_template::{AppError, ErrorTemplate}; use leptos::*; use leptos_meta::*; diff --git a/application/src/main.rs b/application/src/main.rs index abad6ce..07254b9 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -1,3 +1,4 @@ +#![feature(diagnostic_namespace)] #[cfg(feature = "ssr")] #[tokio::main] async fn main() { diff --git a/application/src/pages/groups.rs b/application/src/pages/groups.rs index 58d33b3..767ac3e 100644 --- a/application/src/pages/groups.rs +++ b/application/src/pages/groups.rs @@ -1,5 +1,6 @@ -use crate::components; +use crate::components::{self, participant}; use crate::util::surrealdb::schemas; +use futures::stream::ForEach; use leptos::*; /// Renders the home page of your application. @@ -23,6 +24,37 @@ pub fn Groups() -> impl IntoView { let (participants_lifesaver, participants_hindernis, participants_popduiken) = sort_by_events(participants_filtered); + let lifesaver_best = create_memo(move |_| match participants_lifesaver.get().get(0) { + Some(p) => match p.value.get().events { + Some(e) => e.lifesaver.unwrap_or(0), + None => 6_000_000, + }, + None => 6_000_000, + }); + + let hindernis_best = create_memo(move |_| match participants_hindernis.get().get(0) { + Some(p) => match p.value.get().events { + Some(e) => e.hindernis.unwrap_or(0), + None => 6_000_000, + }, + None => 6_000_000, + }); + + let popduiken_best = create_memo(move |_| match participants_popduiken.get().get(0) { + Some(p) => match p.value.get().events { + Some(e) => e.popduiken.unwrap_or(0), + None => 6_000_000, + }, + None => 6_000_000, + }); + + let total_score_participants = sort_by_total_score( + participants_filtered, + lifesaver_best, + hindernis_best, + popduiken_best, + ); + view! {

"Groups"

@@ -43,7 +75,7 @@ pub fn Groups() -> impl IntoView {

"Algemene score"

- +

"Lifesaver"

@@ -61,6 +93,52 @@ pub fn Groups() -> impl IntoView { } } +fn sort_by_total_score( + participants_filtered: Memo>, + lifesaver_best: Memo, + popduiken_best: Memo, + hindernis_best: Memo, +) -> Memo> { + let total_score_participants: Memo> = create_memo(move |_| { + let mut all_participants: Vec<(usize, schemas::ParticipantSignal)> = participants_filtered + .get() + .into_iter() + .enumerate() + .collect(); + + let lifesaver_best = lifesaver_best.get(); + let popduiken_best = popduiken_best.get(); + let hindernis_best = hindernis_best.get(); + + all_participants.sort_by(|(_, a), (_, b)| { + let part_a = match a.value.get().events { + Some(events) => { + ((events.lifesaver.unwrap_or(6_000_000) * 100) / lifesaver_best) + + ((events.hindernis.unwrap_or(6_000_000) * 100) / hindernis_best) + + ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best) + } + None => 1000, + }; + let part_b = match b.value.get().events { + Some(events) => { + ((events.lifesaver.unwrap_or(6_000_000) * 100) / lifesaver_best) + + ((events.hindernis.unwrap_or(6_000_000) * 100) / hindernis_best) + + ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best) + } + None => 1000, + }; + + part_a.cmp(&part_b) + }); + + all_participants + .into_iter() + .map(|(_, value)| value) + .collect() + }); + total_score_participants +} + fn sort_by_events( participants_filtered: Memo>, ) -> ( diff --git a/flake.nix b/flake.nix index 461b215..aa331ad 100644 --- a/flake.nix +++ b/flake.nix @@ -34,10 +34,10 @@ zlib.out dart-sass llvmPackages_17.lld - (rust-bin.stable.latest.default.override { + (rust-bin.selectLatestNightlyWith ( toolchain: toolchain.default.override { extensions= [ "rust-src" "rust-analyzer" ]; targets = [ "wasm32-unknown-unknown" ]; - }) + })) ]; shellHook = ''