total-score-calculation #15
@ -1,3 +1,4 @@
|
|||||||
|
#![feature(diagnostic_namespace)]
|
||||||
use crate::error_template::{AppError, ErrorTemplate};
|
use crate::error_template::{AppError, ErrorTemplate};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![feature(diagnostic_namespace)]
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::components;
|
use crate::components::{self, participant};
|
||||||
use crate::util::surrealdb::schemas;
|
use crate::util::surrealdb::schemas;
|
||||||
|
use futures::stream::ForEach;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
/// Renders the home page of your application.
|
/// Renders the home page of your application.
|
||||||
@ -23,6 +24,37 @@ pub fn Groups() -> impl IntoView {
|
|||||||
let (participants_lifesaver, participants_hindernis, participants_popduiken) =
|
let (participants_lifesaver, participants_hindernis, participants_popduiken) =
|
||||||
sort_by_events(participants_filtered);
|
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! {
|
view! {
|
||||||
<h2>"Groups"</h2>
|
<h2>"Groups"</h2>
|
||||||
<div class="groups-select-container">
|
<div class="groups-select-container">
|
||||||
@ -43,7 +75,7 @@ pub fn Groups() -> impl IntoView {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h3>"Algemene score"</h3>
|
<h3>"Algemene score"</h3>
|
||||||
<components::participants::Participants participants=participants_filtered.into() show_group=false />
|
<components::participants::Participants participants=total_score_participants.into() show_group=false />
|
||||||
<div class="events-container">
|
<div class="events-container">
|
||||||
<div>
|
<div>
|
||||||
<h3>"Lifesaver"</h3>
|
<h3>"Lifesaver"</h3>
|
||||||
@ -61,6 +93,52 @@ pub fn Groups() -> impl IntoView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sort_by_total_score(
|
||||||
|
participants_filtered: Memo<Vec<schemas::ParticipantSignal>>,
|
||||||
|
lifesaver_best: Memo<u32>,
|
||||||
|
popduiken_best: Memo<u32>,
|
||||||
|
hindernis_best: Memo<u32>,
|
||||||
|
) -> Memo<Vec<schemas::ParticipantSignal>> {
|
||||||
|
let total_score_participants: Memo<Vec<schemas::ParticipantSignal>> = 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(
|
fn sort_by_events(
|
||||||
participants_filtered: Memo<Vec<schemas::ParticipantSignal>>,
|
participants_filtered: Memo<Vec<schemas::ParticipantSignal>>,
|
||||||
) -> (
|
) -> (
|
||||||
|
@ -34,10 +34,10 @@
|
|||||||
zlib.out
|
zlib.out
|
||||||
dart-sass
|
dart-sass
|
||||||
llvmPackages_17.lld
|
llvmPackages_17.lld
|
||||||
(rust-bin.stable.latest.default.override {
|
(rust-bin.selectLatestNightlyWith ( toolchain: toolchain.default.override {
|
||||||
extensions= [ "rust-src" "rust-analyzer" ];
|
extensions= [ "rust-src" "rust-analyzer" ];
|
||||||
targets = [ "wasm32-unknown-unknown" ];
|
targets = [ "wasm32-unknown-unknown" ];
|
||||||
})
|
}))
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
Loading…
Reference in New Issue
Block a user