From 69a6380d54e14a2540235c936d2a4e99e4988bec Mon Sep 17 00:00:00 2001 From: Jeremy Scheff Date: Sat, 10 Aug 2024 22:45:01 -0400 Subject: [PATCH] Better identification of position for processPlayersHallOfFame --- TODO | 4 +-- src/ui/views/Colleges.tsx | 26 +++++++++---------- src/ui/views/HallOfFame.tsx | 2 +- src/ui/views/Player/TopStuff.tsx | 4 ++- src/ui/views/Player/index.tsx | 2 ++ src/ui/views/PlayerGameLog.tsx | 2 ++ src/worker/util/processPlayersHallOfFame.ts | 28 +++++++++++++++++++++ src/worker/views/colleges.ts | 2 +- src/worker/views/frivolitiesDraftClasses.ts | 2 +- src/worker/views/hallOfFame.ts | 2 +- src/worker/views/most.ts | 2 +- src/worker/views/player.ts | 8 +++++- src/worker/views/relatives.ts | 6 ++--- src/worker/views/tragicDeaths.ts | 2 +- 14 files changed, 65 insertions(+), 27 deletions(-) diff --git a/TODO b/TODO index 21a00ccccf..eb10efbea8 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,3 @@ -some indication of jersey number collisions when editing a player -- https://old.reddit.com/r/BasketballGM/comments/1dsfbps/monthly_suggestions_thread/ldelue2/ - On the frivolities page for jersey numbers add a column for number of teams that have retired the number https://discord.com/channels/290013534023057409/331882115119448065/1236793003587272845 rounding @@ -187,6 +184,7 @@ more options to set real rookie ratings https://old.reddit.com/r/BasketballGM/co support sorting mobile trade tables (like saved trades, trading block) new achievements +- moneyball 4 - win 3 championships with hardest constraint https://old.reddit.com/r/BasketballGM/comments/1bgxksp/auto_played_almost_9000_seasons_to_get_longevity/lhgnwm1/?context=3 - force challenge mode to remain on - win title X years after sisyphus mode diff --git a/src/ui/views/Colleges.tsx b/src/ui/views/Colleges.tsx index 4777096624..7a15641b7a 100644 --- a/src/ui/views/Colleges.tsx +++ b/src/ui/views/Colleges.tsx @@ -20,10 +20,10 @@ export const genView = ( type === "college" ? "Colleges" : type === "country" - ? "Countries" - : type === "draftPosition" - ? "Best Player at Every Pick" - : "Jersey Numbers", + ? "Countries" + : type === "draftPosition" + ? "Best Player at Every Pick" + : "Jersey Numbers", customMenu: frivolitiesMenu, }); @@ -44,10 +44,10 @@ export const genView = ( type === "college" ? "College" : type === "country" - ? "Country" - : type === "draftPosition" - ? "Pick" - : "stat:jerseyNumber", + ? "Country" + : type === "draftPosition" + ? "Pick" + : "stat:jerseyNumber", "# Players", "Active", "HoF", @@ -82,10 +82,10 @@ export const genView = ( type === "college" ? "college" : type === "country" - ? "country" - : type === "draftPosition" - ? "at_pick" - : "jersey_number", + ? "country" + : type === "draftPosition" + ? "at_pick" + : "jersey_number", window.encodeURIComponent(c.name), ])} > @@ -114,7 +114,7 @@ export const genView = ( "table-info": p.statsTids.includes(userTid), }, }, - p.ratings.at(-1).pos, + p.bestPos, p.draft.year, p.retiredYear === Infinity ? null : p.retiredYear, p.draft.round > 0 ? `${p.draft.round}-${p.draft.pick}` : "", diff --git a/src/ui/views/HallOfFame.tsx b/src/ui/views/HallOfFame.tsx index 4a6d841ae0..f9e111e1c8 100644 --- a/src/ui/views/HallOfFame.tsx +++ b/src/ui/views/HallOfFame.tsx @@ -45,7 +45,7 @@ const HallOfFame = ({ players, stats, userTid }: View<"hallOfFame">) => { firstNameShort: p.firstNameShort, lastName: p.lastName, }), - p.ratings.at(-1).pos, + p.bestPos, p.draft.year, p.retiredYear, p.draft.round > 0 ? `${p.draft.round}-${p.draft.pick}` : "", diff --git a/src/ui/views/Player/TopStuff.tsx b/src/ui/views/Player/TopStuff.tsx index 217a5830be..23779cf58d 100644 --- a/src/ui/views/Player/TopStuff.tsx +++ b/src/ui/views/Player/TopStuff.tsx @@ -235,6 +235,7 @@ const StatsSummary = ({ }; const TopStuff = ({ + bestPos, currentSeason, freeAgent, gender, @@ -259,6 +260,7 @@ const TopStuff = ({ willingToSign, }: Pick< View<"player">, + | "bestPos" | "currentSeason" | "freeAgent" | "gender" @@ -459,7 +461,7 @@ const TopStuff = ({
- {player.ratings.at(-1)!.pos},{" "} + {bestPos},{" "} {teamURL ? {teamName} : teamName} {player.jerseyNumber ? ( <> diff --git a/src/ui/views/Player/index.tsx b/src/ui/views/Player/index.tsx index 4d7ea7d078..e9b197f305 100644 --- a/src/ui/views/Player/index.tsx +++ b/src/ui/views/Player/index.tsx @@ -300,6 +300,7 @@ const MaybeBold = ({ }; const Player2 = ({ + bestPos, currentSeason, customMenu, events, @@ -370,6 +371,7 @@ const Player2 = ({ return ( <> { @@ -34,8 +36,17 @@ const processPlayersHallOfFame = < const hasSeasonWithGamesPlayed = p.stats.some(ps => ps.gp > 0); + const posBySeason: Record = {}; + for (const row of p.ratings) { + if (row.pos !== undefined && row.season !== undefined) { + posBySeason[row.season] = row.pos; + } + } + let bestEWA = -Infinity; let bestStats; + let bestPos: string | undefined; + const posByEWA: Record = {}; const teamSums: Record = {}; for (const ps of p.stats) { const tid = ps.tid; @@ -48,6 +59,7 @@ const processPlayersHallOfFame = < if (bestSeasonOverride !== undefined) { if (ps.season === bestSeasonOverride) { bestStats = ps; + bestPos = posBySeason[ps.season]; } } else { if (ewa > bestEWA) { @@ -56,6 +68,16 @@ const processPlayersHallOfFame = < bestEWA = ewa; } } + + const pos = posBySeason[ps.season]; + if (pos !== undefined) { + //console.log(ps.pos, ps) + if (posByEWA[pos] === undefined) { + posByEWA[pos] = ewa; + } else { + posByEWA[pos] += ewa; + } + } } if (Object.hasOwn(teamSums, tid)) { teamSums[tid] += ewa; @@ -66,6 +88,11 @@ const processPlayersHallOfFame = < if (bestStats === undefined) { bestStats = p.careerStats; } + if (bestPos === undefined) { + bestPos = + maxBy(Object.entries(posByEWA), ([, ewa]) => ewa)?.[0] ?? + p.ratings.at(-1)?.pos; + } const legacyTid = parseInt( Object.keys(teamSums).reduce( @@ -77,6 +104,7 @@ const processPlayersHallOfFame = < return { ...p, + bestPos: bestPos ?? "", bestStats, peakOvr, legacyTid, diff --git a/src/worker/views/colleges.ts b/src/worker/views/colleges.ts index d499cee6b1..d103e92c9b 100644 --- a/src/worker/views/colleges.ts +++ b/src/worker/views/colleges.ts @@ -147,7 +147,7 @@ export const genView = ( "hof", "jerseyNumber", ], - ratings: ["ovr", "pos"], + ratings: ["season", "ovr", "pos"], stats: ["season", "abbrev", "tid", ...stats], fuzz: true, }); diff --git a/src/worker/views/frivolitiesDraftClasses.ts b/src/worker/views/frivolitiesDraftClasses.ts index 7f5895906d..ae1b4725e6 100644 --- a/src/worker/views/frivolitiesDraftClasses.ts +++ b/src/worker/views/frivolitiesDraftClasses.ts @@ -129,7 +129,7 @@ const updateFrivolitiesDraftClasses = async ( "diedYear", "jerseyNumber", ], - ratings: ["ovr", "pos"], + ratings: ["season", "ovr", "pos"], stats: ["season", "abbrev", "tid", ...stats], fuzz: true, }), diff --git a/src/worker/views/hallOfFame.ts b/src/worker/views/hallOfFame.ts index 341e31bcad..6ea5537813 100644 --- a/src/worker/views/hallOfFame.ts +++ b/src/worker/views/hallOfFame.ts @@ -41,7 +41,7 @@ const updatePlayers = async (inputs: unknown, updateEvents: UpdateEvents) => { "retiredYear", "statsTids", ], - ratings: ["ovr", "pos"], + ratings: ["season", "ovr", "pos"], stats: ["season", "abbrev", "tid", ...stats], fuzz: true, }); diff --git a/src/worker/views/most.ts b/src/worker/views/most.ts index a10cb8a79b..e9951e7134 100644 --- a/src/worker/views/most.ts +++ b/src/worker/views/most.ts @@ -87,7 +87,7 @@ const getMostXPlayers = async ({ "jerseyNumber", "awards", ], - ratings: ["ovr", "pos"], + ratings: ["season", "ovr", "pos"], stats: ["season", "abbrev", "tid", ...stats], fuzz: true, mergeStats: "totOnly", diff --git a/src/worker/views/player.ts b/src/worker/views/player.ts index 75f3835776..7d66ff33ba 100644 --- a/src/worker/views/player.ts +++ b/src/worker/views/player.ts @@ -329,8 +329,11 @@ export const getCommon = async (pid?: number, season?: number) => { let teamColors; let teamJersey; + let bestPos; if (p.tid === PLAYER.RETIRED) { - const { legacyTid } = processPlayersHallOfFame([p])[0]; + const info = processPlayersHallOfFame([p])[0]; + const legacyTid = info.legacyTid; + bestPos = info.bestPos; // Randomly pick a season that he played on this team, and use that for colors const teamJerseyNumberInfos = jerseyNumberInfos.filter( @@ -343,6 +346,8 @@ export const getCommon = async (pid?: number, season?: number) => { teamJersey = info.t.jersey; } } + } else { + bestPos = p.ratings.at(-1)!.pos; } if (teamColors === undefined) { teamColors = await getTeamColors(p.tid); @@ -467,6 +472,7 @@ export const getCommon = async (pid?: number, season?: number) => { return { type: "normal" as const, + bestPos, currentSeason: g.get("season"), customMenu, freeAgent: p.tid === PLAYER.FREE_AGENT, diff --git a/src/worker/views/relatives.ts b/src/worker/views/relatives.ts index 1b237904b0..6f3f48745e 100644 --- a/src/worker/views/relatives.ts +++ b/src/worker/views/relatives.ts @@ -19,8 +19,8 @@ const getRelationText = ( return directLine ? "Self" : brother - ? helpers.getRelativeType(gender, "brother") - : "Cousin"; + ? helpers.getRelativeType(gender, "brother") + : "Cousin"; } if (generation === 1) { @@ -229,7 +229,7 @@ const updatePlayers = async ( "college", "jerseyNumber", ], - ratings: ["ovr", "pos"], + ratings: ["season", "ovr", "pos"], stats: ["season", "abbrev", "tid", ...stats], fuzz: true, }); diff --git a/src/worker/views/tragicDeaths.ts b/src/worker/views/tragicDeaths.ts index 18ca6e9701..253fe1622e 100644 --- a/src/worker/views/tragicDeaths.ts +++ b/src/worker/views/tragicDeaths.ts @@ -58,7 +58,7 @@ const tragicDeaths = async (inputs: unknown, updateEvents: UpdateEvents) => { "statsTids", "hof", ], - ratings: ["ovr", "pos"], + ratings: ["season", "ovr", "pos"], stats: ["season", "abbrev", "tid", ...stats], fuzz: true, });