Separate player presence from scout stats
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+29
-11
@@ -1,15 +1,18 @@
|
||||
import { useMemo } from "react";
|
||||
import { giocatori, type Giocatore } from "./crapp-data";
|
||||
import { giocatoriConScout, useScoutMatches } from "./scout-store";
|
||||
import { useVotiMvp, vincitoriMvp } from "./mvp-voti";
|
||||
import { mvpVintiPerGiocatore, useVotiMvp } from "./mvp-voti";
|
||||
import { mediePagelle, usePagelle } from "./pagelle";
|
||||
import { statisticheCacche, useCacche } from "./cacche";
|
||||
import { conteggioTurni } from "./palloni-core";
|
||||
import { useTurniPalloni } from "./palloni";
|
||||
import { useInfortuniERitardi } from "./infortuni";
|
||||
import { useGiocatoreBase } from "./user-store";
|
||||
import { useGiocatoreId } from "./user-store";
|
||||
import { useEventi } from "./eventi";
|
||||
import { useRispostePresenze } from "./presenze";
|
||||
import {
|
||||
contaPresenzeGiocatore,
|
||||
totaliEventiGiocatore,
|
||||
useRispostePresenze,
|
||||
} from "./presenze";
|
||||
import { obiettiviOrdinati } from "./obiettivi";
|
||||
import { useCsi } from "./csi";
|
||||
import { partiteGiocate } from "./csi-core";
|
||||
@@ -20,12 +23,13 @@ import { partiteGiocate } from "./csi-core";
|
||||
* nessuna query aggiuntiva rispetto a quelle che l'app fa comunque.
|
||||
*/
|
||||
export function useRosa(): Giocatore[] {
|
||||
const scoutMatches = useScoutMatches();
|
||||
const voti = useVotiMvp();
|
||||
const { voti: pagelle } = usePagelle();
|
||||
const { righe: cacche } = useCacche();
|
||||
const { turni } = useTurniPalloni();
|
||||
const { infortuni, ritardi } = useInfortuniERitardi();
|
||||
const { eventi } = useEventi();
|
||||
const { presenze: mappaPresenze } = useRispostePresenze();
|
||||
|
||||
const votiMvp = voti.data ?? [];
|
||||
|
||||
@@ -33,24 +37,38 @@ export function useRosa(): Giocatore[] {
|
||||
const medie = mediePagelle(pagelle);
|
||||
const statCacche = statisticheCacche(cacche);
|
||||
const palloni = conteggioTurni(turni);
|
||||
return giocatoriConScout(scoutMatches, vincitoriMvp(votiMvp)).map((g) => ({
|
||||
const mvpVinti = mvpVintiPerGiocatore(votiMvp);
|
||||
|
||||
return giocatori.map((g) => ({
|
||||
...g,
|
||||
mediaVoto: medie[g.id]?.media ?? g.mediaVoto,
|
||||
presenze: contaPresenzeGiocatore(g.id, eventi, mappaPresenze),
|
||||
totaliEventi: totaliEventiGiocatore(g.id, eventi),
|
||||
mvp: mvpVinti[g.id] ?? 0,
|
||||
mediaVoto: medie[g.id]?.media ?? 0,
|
||||
palloni: palloni[g.id] ?? 0,
|
||||
cacche: statCacche[g.id]?.giornateTop ?? 0,
|
||||
cacchePartita: statCacche[g.id]?.media ?? 0,
|
||||
infortuni: infortuni[g.id] ?? 0,
|
||||
ritardi: ritardi[g.id] ?? 0,
|
||||
}));
|
||||
}, [scoutMatches, votiMvp, pagelle, cacche, turni, infortuni, ritardi]);
|
||||
}, [
|
||||
votiMvp,
|
||||
pagelle,
|
||||
cacche,
|
||||
turni,
|
||||
infortuni,
|
||||
ritardi,
|
||||
eventi,
|
||||
mappaPresenze,
|
||||
]);
|
||||
}
|
||||
|
||||
/** Il giocatore selezionato sul dispositivo, con le statistiche complete. */
|
||||
export function useIo(): Giocatore | null {
|
||||
const base = useGiocatoreBase();
|
||||
const id = useGiocatoreId();
|
||||
const rosa = useRosa();
|
||||
if (!base) return null;
|
||||
return rosa.find((g) => g.id === base.id) ?? base;
|
||||
if (!id) return null;
|
||||
return rosa.find((g) => g.id === id) ?? null;
|
||||
}
|
||||
|
||||
/** Obiettivi collaborativi calcolati sui dati reali già in cache. */
|
||||
|
||||
@@ -186,24 +186,22 @@ export function totaliSquadra(matches: ScoutMatch[]) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Presenze e MVP ricavati dalle partite scoutate: nessuna statistica individuale offensiva.
|
||||
* `mvpPerMatch` mappa idPartita -> nome dell'MVP eletto dalla squadra. */
|
||||
/**
|
||||
* MVP ricavati dalle partite scoutate (mappa matchId → nome vincitore).
|
||||
* Le presenze personali restano su `risposte_presenze`, non sullo scout.
|
||||
*/
|
||||
export function giocatoriConScout(
|
||||
matches: ScoutMatch[],
|
||||
mvpPerMatch: Record<string, string> = {},
|
||||
): Giocatore[] {
|
||||
return giocatori.map((g) => {
|
||||
let presenze = 0;
|
||||
let mvp = 0;
|
||||
for (const m of matches) {
|
||||
if (totaliPerGiocatore(m.azioni).has(g.id)) presenze += 1;
|
||||
if (mvpPerMatch[m.id] === g.nome) mvp += 1;
|
||||
}
|
||||
return {
|
||||
...g,
|
||||
mvp: g.mvp + mvp,
|
||||
presenze: g.presenze + presenze,
|
||||
totaliEventi: g.totaliEventi + matches.length,
|
||||
mvp,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user