Skip to content

Commit

Permalink
Better identification of position for processPlayersHallOfFame
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Aug 11, 2024
1 parent 36fce5f commit 69a6380
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 27 deletions.
4 changes: 1 addition & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
26 changes: 13 additions & 13 deletions src/ui/views/Colleges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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",
Expand Down Expand Up @@ -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),
])}
>
Expand Down Expand Up @@ -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}` : "",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/HallOfFame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : "",
Expand Down
4 changes: 3 additions & 1 deletion src/ui/views/Player/TopStuff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ const StatsSummary = ({
};

const TopStuff = ({
bestPos,
currentSeason,
freeAgent,
gender,
Expand All @@ -259,6 +260,7 @@ const TopStuff = ({
willingToSign,
}: Pick<
View<"player">,
| "bestPos"
| "currentSeason"
| "freeAgent"
| "gender"
Expand Down Expand Up @@ -459,7 +461,7 @@ const TopStuff = ({
</div>
<div>
<strong>
{player.ratings.at(-1)!.pos},{" "}
{bestPos},{" "}
{teamURL ? <a href={teamURL}>{teamName}</a> : teamName}
{player.jerseyNumber ? (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/ui/views/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ const MaybeBold = ({
};

const Player2 = ({
bestPos,
currentSeason,
customMenu,
events,
Expand Down Expand Up @@ -370,6 +371,7 @@ const Player2 = ({
return (
<>
<TopStuff
bestPos={bestPos}
currentSeason={currentSeason}
freeAgent={freeAgent}
gender={gender}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/views/PlayerGameLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NoGamesMessage } from "./GameLog";
import type { DataTableRow } from "../components/DataTable";

const PlayerGameLog = ({
bestPos,
currentSeason,
customMenu,
freeAgent,
Expand Down Expand Up @@ -185,6 +186,7 @@ const PlayerGameLog = ({
return (
<>
<TopStuff
bestPos={bestPos}
currentSeason={currentSeason}
freeAgent={freeAgent}
gender={gender}
Expand Down
28 changes: 28 additions & 0 deletions src/worker/util/processPlayersHallOfFame.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bySport } from "../../common";
import { maxBy } from "../../common/utils";

// Would be better as part of idb.getCopies.playersPlus
const processPlayersHallOfFame = <
Expand All @@ -18,6 +19,7 @@ const processPlayersHallOfFame = <
players: T[],
): (T & {
bestStats: any;
bestPos: string;
legacyTid: number;
peakOvr: number;
})[] => {
Expand All @@ -34,8 +36,17 @@ const processPlayersHallOfFame = <

const hasSeasonWithGamesPlayed = p.stats.some(ps => ps.gp > 0);

const posBySeason: Record<number, string | undefined> = {};
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<string, number> = {};
const teamSums: Record<number, number> = {};
for (const ps of p.stats) {
const tid = ps.tid;
Expand All @@ -48,6 +59,7 @@ const processPlayersHallOfFame = <
if (bestSeasonOverride !== undefined) {
if (ps.season === bestSeasonOverride) {
bestStats = ps;
bestPos = posBySeason[ps.season];
}
} else {
if (ewa > bestEWA) {
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -77,6 +104,7 @@ const processPlayersHallOfFame = <

return {
...p,
bestPos: bestPos ?? "",
bestStats,
peakOvr,
legacyTid,
Expand Down
2 changes: 1 addition & 1 deletion src/worker/views/colleges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const genView = (
"hof",
"jerseyNumber",
],
ratings: ["ovr", "pos"],
ratings: ["season", "ovr", "pos"],
stats: ["season", "abbrev", "tid", ...stats],
fuzz: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/worker/views/frivolitiesDraftClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const updateFrivolitiesDraftClasses = async (
"diedYear",
"jerseyNumber",
],
ratings: ["ovr", "pos"],
ratings: ["season", "ovr", "pos"],
stats: ["season", "abbrev", "tid", ...stats],
fuzz: true,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/worker/views/hallOfFame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion src/worker/views/most.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/worker/views/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/worker/views/relatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const getRelationText = (
return directLine
? "Self"
: brother
? helpers.getRelativeType(gender, "brother")
: "Cousin";
? helpers.getRelativeType(gender, "brother")
: "Cousin";
}

if (generation === 1) {
Expand Down Expand Up @@ -229,7 +229,7 @@ const updatePlayers = async (
"college",
"jerseyNumber",
],
ratings: ["ovr", "pos"],
ratings: ["season", "ovr", "pos"],
stats: ["season", "abbrev", "tid", ...stats],
fuzz: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/worker/views/tragicDeaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 69a6380

Please sign in to comment.