Changed comparison between participants

This commit is contained in:
xeovalyte 2024-06-18 12:33:21 +02:00
parent a55db6941e
commit 2fd49b7795
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:kSQDrQDmKzljJzfGYcd3m9RqHi4h8rSwkZ3sQ9kBURo
2 changed files with 45 additions and 34 deletions

View File

@ -23,7 +23,37 @@ pub fn Groups() -> impl IntoView {
let (participants_lifesaver, participants_hindernis, participants_popduiken) =
sort_by_events(participants_filtered);
let total_score_participants = sort_by_total_score(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! {
<h2>"Groups"</h2>
@ -65,6 +95,9 @@ 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
@ -73,48 +106,26 @@ fn sort_by_total_score(
.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;
}
}
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.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
+ ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best)
}
None => 36_000_000,
None => 1000,
};
let part_b = match b.value.get().events {
Some(events) => {
(((events.lifesaver.unwrap_or(6_000_000) * 100) / lifesaver_best)
((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
+ ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best)
}
None => 36_000_000,
None => 1000,
};
part_a.cmp(&part_b)

View File

@ -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 = ''