Skip to content

Commit 63f5d54

Browse files
committed
Add overall playoff statistics
1 parent 5df26eb commit 63f5d54

2 files changed

Lines changed: 91 additions & 6 deletions

File tree

src/PlayoffStats.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ const teamSelector = teamInfo.availablePeriods.length > 0 ?
2727
const selectedTeam = teamSelector ? Generators.input(teamSelector) : null;
2828

2929
const periodSelector = teamInfo.availablePeriods.length > 0 ?
30-
Inputs.select(teamInfo.availablePeriods, {label: "Select Round:", value: teamInfo.availablePeriods[teamInfo.availablePeriods.length-1]}) : null;
30+
Inputs.select(teamInfo.availablePeriods, {
31+
label: "Select Round:",
32+
value: teamInfo.availablePeriods[teamInfo.availablePeriods.length-1],
33+
format: p => teamInfo.roundNames[p] || p
34+
}) : null;
3135
const selectedPeriod = periodSelector ? Generators.input(periodSelector) : null;
3236
```
3337

src/data/playoffRosters.json.js

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,99 @@ const teamData = teamInfo.map(team => {
9696
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
9797
});
9898

99+
// Add OVERALL stats using the latest round's stats without differential subtraction
100+
if (availablePlayoffRounds.length > 0) {
101+
const latestRound = availablePlayoffRounds[availablePlayoffRounds.length - 1];
102+
const latestStats = latestRound.statsFile;
103+
const latestRoster = latestRound.rosterFile;
104+
105+
team['OVERALL'] = {};
106+
const overallRoster = latestRoster.filter(player => player.ABBR === team.ABBR);
107+
108+
team['OVERALL']['ROSTER'] = overallRoster.map(player => {
109+
const info = playerInfo.find(p => p.ID === player.ID);
110+
const contract = contracts.find(c => c.ID === player.ID);
111+
const position = mapPosition(info.Pos);
112+
113+
const currentPlayerStats = latestStats.find(s => s.hockeyRef === player.ID) || {};
114+
const playerStats = getOverallStats(position, currentPlayerStats);
115+
116+
return {
117+
PLAYER_ID: player.ID,
118+
Name: info.Name,
119+
BirthDate: info.BirthDate,
120+
Age: calculateAge(info.BirthDate),
121+
Position: position,
122+
NHLTeam: info.NHL,
123+
Salary: contract?.Salary || 0,
124+
Contract: contract?.Contract || '---',
125+
Reserve: player.RESERVE || "",
126+
Goals: position === "G" ? null : playerStats.goals,
127+
Assists: position === "G" ? null : playerStats.assists,
128+
PIM: position === "G" ? null : playerStats.pim,
129+
Hits: position === "G" ? null : playerStats.hits,
130+
Blocks: position === "G" ? null : playerStats.blocks,
131+
Take: position === "G" ? null : playerStats.take,
132+
Give: position === "G" ? null : playerStats.give,
133+
TOI: position === "G" ? null : playerStats.toi,
134+
Record: position === "G" ? `${playerStats.wins}-${playerStats.losses}-${playerStats.ties}` : null,
135+
SO: position === "G" ? (playerStats.so || 0) : null,
136+
SA: position === "G" ? (playerStats.sa || 0) : null,
137+
GA: position === "G" ? (playerStats.ga || 0) : null,
138+
Toughness: position === "G" ? null : playerStats.toughness,
139+
DStat: position === "G" ? (playerStats.gstat || 0) : playerStats.dstat,
140+
GamesPlayed: playerStats.games_played,
141+
};
142+
});
143+
144+
team['OVERALL']['ROSTER'].sort((a, b) => {
145+
const posOrder = { 'D': 1, 'F': 2, 'G': 3 };
146+
if (posOrder[a.Position] !== posOrder[b.Position]) {
147+
return posOrder[a.Position] - posOrder[b.Position];
148+
}
149+
if (a.Reserve !== b.Reserve) {
150+
return (a.Reserve === "R" ? 1 : 0) - (b.Reserve === "R" ? 1 : 0);
151+
}
152+
return a.Name.localeCompare(b.Name);
153+
});
154+
155+
team['OVERALL']['ACTIVE_TOTALS'] = team['OVERALL']['ROSTER']
156+
.filter(player => player.Reserve !== "R" && player.Reserve !== "N/A")
157+
.reduce((totals, player) => ({
158+
goals: totals.goals + (player.Position !== "G" ? (player.Goals || 0) : 0),
159+
assists: totals.assists + (player.Position !== "G" ? (player.Assists || 0) : 0),
160+
toughness: totals.toughness + (player.Position !== "G" ? (player.Toughness || 0) : 0),
161+
dstat: totals.dstat + (player.Position !== "G" ? (player.DStat || 0) : 0),
162+
gstat: totals.gstat + (player.Position === "G" ? (player.DStat || 0) : 0)
163+
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
164+
165+
team['OVERALL']['RESERVE_TOTALS'] = team['OVERALL']['ROSTER']
166+
.filter(player => player.Reserve === "R")
167+
.reduce((totals, player) => ({
168+
goals: totals.goals + (player.Position !== "G" ? (player.Goals || 0) : 0),
169+
assists: totals.assists + (player.Position !== "G" ? (player.Assists || 0) : 0),
170+
toughness: totals.toughness + (player.Position !== "G" ? (player.Toughness || 0) : 0),
171+
dstat: totals.dstat + (player.Position !== "G" ? (player.DStat || 0) : 0),
172+
gstat: totals.gstat + (player.Position === "G" ? (player.DStat || 0) : 0)
173+
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
174+
}
175+
99176
return team;
100177
});
101178

102179
// Create available periods list (playoff rounds)
103-
const availablePeriods = availablePlayoffRounds.map(round => `R${round.round.toString().padStart(2, '0')}`);
180+
const roundKeys = availablePlayoffRounds.map(round => `R${round.round.toString().padStart(2, '0')}`);
181+
const availablePeriods = availablePlayoffRounds.length > 0 ? [...roundKeys, 'OVERALL'] : [];
182+
183+
const roundNames = availablePlayoffRounds.reduce((acc, round) => {
184+
acc[`R${round.round.toString().padStart(2, '0')}`] = round.name;
185+
return acc;
186+
}, {});
187+
if (availablePlayoffRounds.length > 0) roundNames['OVERALL'] = 'Overall';
104188

105189
process.stdout.write(JSON.stringify({
106190
teams,
107191
teamData,
108192
availablePeriods,
109-
roundNames: availablePlayoffRounds.reduce((acc, round) => {
110-
acc[`R${round.round.toString().padStart(2, '0')}`] = round.name;
111-
return acc;
112-
}, {})
193+
roundNames
113194
}));

0 commit comments

Comments
 (0)