A person's number is read for the event's context (faces/numbers.ts): that season's squad, then what the shirts clearly read in their confirmed photos of the same season and competition (first when the game is not an official match), and the number typed on the person only in the current season and never for a national team. Used for face/number agreement, squad suggestions and the shirt-sample labels (which never take the model's own readings). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
23 lines
1.0 KiB
TypeScript
23 lines
1.0 KiB
TypeScript
/** Below this the shirt-number reading is not used for suggestions. */
|
|
export const JERSEY_MIN_SCORE = 0.7;
|
|
export interface NumberVote {
|
|
number: string;
|
|
score: number;
|
|
votes: number;
|
|
}
|
|
|
|
/** The number more than half of these readings agree on (clear readings only), with its mean score. */
|
|
export function majorityNumber(faces: { jerseyNumber: string | null; jerseyScore: number | null }[]): NumberVote | null {
|
|
const clear = faces.filter((f) => f.jerseyNumber !== null && (f.jerseyScore ?? 0) >= JERSEY_MIN_SCORE);
|
|
const tally = new Map<string, { votes: number; sum: number }>();
|
|
for (const f of clear) {
|
|
const t = tally.get(f.jerseyNumber!) ?? { votes: 0, sum: 0 };
|
|
t.votes++;
|
|
t.sum += f.jerseyScore!;
|
|
tally.set(f.jerseyNumber!, t);
|
|
}
|
|
const [best] = [...tally.entries()].sort((a, b) => b[1].votes - a[1].votes);
|
|
if (!best || best[1].votes * 2 <= clear.length) return null;
|
|
return { number: best[0], score: Math.round((best[1].sum / best[1].votes) * 1000) / 1000, votes: best[1].votes };
|
|
}
|