Calcoli di badge, obiettivi e percentuali spostati da route e componenti a src/lib
squadra: mediaPresenzeRosa, obiettiviCompletati, mediaProgressoObiettivi, quantiAlGrado; scout: percentualePiu; utils: percentuale (usata da profilo, RosaPresenze, CollezioneBadge). Test unitari per ciascuna. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06c91149e7
commit
99265f6a1e
13 files changed
+106
-30
No files matched your search
@@ -194,6 +194,14 @@ export function gradoRaggiunto(def: BadgeDef, valore: number): Grado | null {
|
||||
return grado;
|
||||
}
|
||||
|
||||
/** Quanti giocatori della rosa hanno raggiunto almeno `grado` per il badge `def`. */
|
||||
export function quantiAlGrado(def: BadgeDef, rosa: Giocatore[], grado: Grado): number {
|
||||
return rosa.filter((g) => {
|
||||
const raggiunto = gradoRaggiunto(def, def.valore(g));
|
||||
return raggiunto ? gradiOrdine.indexOf(raggiunto) >= gradiOrdine.indexOf(grado) : false;
|
||||
}).length;
|
||||
}
|
||||
|
||||
export function statoBadge(def: BadgeDef, g: Giocatore): BadgeStato {
|
||||
const valore = def.valore(g);
|
||||
const grado = gradoRaggiunto(def, valore);
|
||||
|
||||
@@ -415,6 +415,25 @@ export function progressoObiettivo(o: ObiettivoSquadra) {
|
||||
return Math.min(100, Math.round((o.valore / o.target) * 100));
|
||||
}
|
||||
|
||||
export function obiettiviCompletati(obiettivi: ObiettivoSquadra[]) {
|
||||
return obiettivi.filter((o) => progressoObiettivo(o) >= 100).length;
|
||||
}
|
||||
|
||||
export function mediaProgressoObiettivi(obiettivi: ObiettivoSquadra[]) {
|
||||
return obiettivi.length
|
||||
? Math.round(obiettivi.reduce((s, o) => s + progressoObiettivo(o), 0) / obiettivi.length)
|
||||
: 0;
|
||||
}
|
||||
|
||||
/** Media, in percentuale, della quota di eventi a cui ogni giocatore della rosa ha partecipato. */
|
||||
export function mediaPresenzeRosa(rosa: Giocatore[]) {
|
||||
return rosa.length
|
||||
? Math.round(
|
||||
(rosa.reduce((s, g) => s + g.presenze / (g.totaliEventi || 1), 0) / rosa.length) * 100,
|
||||
)
|
||||
: 0;
|
||||
}
|
||||
|
||||
export function obiettiviOrdinati(rosa?: Giocatore[], ctx?: ContestoObiettivi, oggi?: Date) {
|
||||
return obiettiviSquadra(rosa, ctx, oggi).sort((a, b) => {
|
||||
const pa = progressoObiettivo(a);
|
||||
|
||||
@@ -96,6 +96,11 @@ export function contaValutazioni(
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Percentuale di + sul totale (+ e −) di un fondamentale; `null` se non ci sono valutazioni. */
|
||||
export function percentualePiu(piu: number, meno: number): number | null {
|
||||
return piu + meno === 0 ? null : Math.round((piu / (piu + meno)) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Riepilogo delle valutazioni per la lettura nell'app: totali di squadra e per giocatore,
|
||||
* su tutta la partita o su un solo set. Chi non ha valutazioni nel periodo non compare.
|
||||
|
||||
@@ -4,3 +4,8 @@ import { twMerge } from "tailwind-merge";
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
/** Percentuale intera di `parte` su `totale`; 0 se il totale è 0. */
|
||||
export function percentuale(parte: number, totale: number): number {
|
||||
return totale ? Math.round((parte / totale) * 100) : 0;
|
||||
}
|
||||
Reference in new issue
Block a user