first commit for total score calculation
This commit is contained in:
parent
25e02dfed5
commit
a55db6941e
@ -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.
|
||||||
@ -22,6 +23,7 @@ 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 total_score_participants = sort_by_total_score(participants_filtered);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<h2>"Groups"</h2>
|
<h2>"Groups"</h2>
|
||||||
@ -43,7 +45,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 +63,71 @@ pub fn Groups() -> impl IntoView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sort_by_total_score(
|
||||||
|
participants_filtered: Memo<Vec<schemas::ParticipantSignal>>,
|
||||||
|
) -> 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 mut lifesaver_best = 6_000_000;
|
||||||
|
let mut popduiken_best = 6_000_000;
|
||||||
|
let mut hindernis_best = 6_000_000;
|
||||||
|
|
||||||
|
for val in all_participants.clone().into_iter() {
|
||||||
|
if val.1.value.get().events == None {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let person = val.1.value.get().events.unwrap();
|
||||||
|
let person_lifesaver = person.lifesaver.unwrap_or(6_000_000);
|
||||||
|
let person_popduiken = person.popduiken.unwrap_or(6_000_000);
|
||||||
|
let person_hindernis = person.hindernis.unwrap_or(6_000_000);
|
||||||
|
|
||||||
|
if person_lifesaver < lifesaver_best {
|
||||||
|
lifesaver_best = person_lifesaver;
|
||||||
|
}
|
||||||
|
if person_popduiken < popduiken_best {
|
||||||
|
popduiken_best = person_popduiken;
|
||||||
|
}
|
||||||
|
if person_hindernis < hindernis_best {
|
||||||
|
hindernis_best = person_hindernis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
/ 3
|
||||||
|
}
|
||||||
|
None => 36_000_000,
|
||||||
|
};
|
||||||
|
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))
|
||||||
|
/ 3
|
||||||
|
}
|
||||||
|
None => 36_000_000,
|
||||||
|
};
|
||||||
|
|
||||||
|
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>>,
|
||||||
) -> (
|
) -> (
|
||||||
|
Loading…
Reference in New Issue
Block a user