total-score-calculation #15
@ -23,7 +23,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 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! {
|
view! {
|
||||||
<h2>"Groups"</h2>
|
<h2>"Groups"</h2>
|
||||||
@ -65,6 +95,9 @@ pub fn Groups() -> impl IntoView {
|
|||||||
|
|
||||||
fn sort_by_total_score(
|
fn sort_by_total_score(
|
||||||
participants_filtered: Memo<Vec<schemas::ParticipantSignal>>,
|
participants_filtered: Memo<Vec<schemas::ParticipantSignal>>,
|
||||||
|
lifesaver_best: Memo<u32>,
|
||||||
|
popduiken_best: Memo<u32>,
|
||||||
|
hindernis_best: Memo<u32>,
|
||||||
) -> Memo<Vec<schemas::ParticipantSignal>> {
|
) -> Memo<Vec<schemas::ParticipantSignal>> {
|
||||||
let total_score_participants: Memo<Vec<schemas::ParticipantSignal>> = create_memo(move |_| {
|
let total_score_participants: Memo<Vec<schemas::ParticipantSignal>> = create_memo(move |_| {
|
||||||
let mut all_participants: Vec<(usize, schemas::ParticipantSignal)> = participants_filtered
|
let mut all_participants: Vec<(usize, schemas::ParticipantSignal)> = participants_filtered
|
||||||
@ -73,48 +106,26 @@ fn sort_by_total_score(
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut lifesaver_best = 6_000_000;
|
let lifesaver_best = lifesaver_best.get();
|
||||||
let mut popduiken_best = 6_000_000;
|
let popduiken_best = popduiken_best.get();
|
||||||
let mut hindernis_best = 6_000_000;
|
let hindernis_best = hindernis_best.get();
|
||||||
|
|
||||||
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)| {
|
all_participants.sort_by(|(_, a), (_, b)| {
|
||||||
let part_a = match a.value.get().events {
|
let part_a = match a.value.get().events {
|
||||||
Some(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.hindernis.unwrap_or(6_000_000) * 100) / hindernis_best)
|
||||||
+ ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best))
|
+ ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best)
|
||||||
/ 3
|
|
||||||
}
|
}
|
||||||
None => 36_000_000,
|
None => 1000,
|
||||||
};
|
};
|
||||||
let part_b = match b.value.get().events {
|
let part_b = match b.value.get().events {
|
||||||
Some(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.hindernis.unwrap_or(6_000_000) * 100) / hindernis_best)
|
||||||
+ ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best))
|
+ ((events.popduiken.unwrap_or(6_000_000) * 100) / popduiken_best)
|
||||||
/ 3
|
|
||||||
}
|
}
|
||||||
None => 36_000_000,
|
None => 1000,
|
||||||
};
|
};
|
||||||
|
|
||||||
part_a.cmp(&part_b)
|
part_a.cmp(&part_b)
|
||||||
|
@ -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