Skip to content

Commit df4518e

Browse files
committed
updated the stats file to not have the calcuated fields
1 parent 01522ed commit df4518e

4 files changed

Lines changed: 2308 additions & 2123 deletions

File tree

src/Players.md

Lines changed: 200 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,37 @@ function getStatsForPeriod(selectedPeriod) {
6969
const latestPeriod = Math.max(...availablePeriods);
7070
const latestPeriodData = statsData[latestPeriod];
7171

72-
return latestPeriodData.map(stat => ({
73-
hockeyRef: stat.hockeyRef,
74-
team: stat.team,
75-
pos: stat.pos,
76-
goals: stat["stats/goals"] || 0,
77-
assists: stat["stats/assists"] || 0,
78-
toughness: stat["stats/toughness"] || 0,
79-
dstat: stat["stats/dstat"] || 0,
80-
gstat: stat["stats/gstat"] || 0,
81-
games_played: stat["stats/gp"] || stat["stats/games_played"] || 0
82-
}));
72+
return latestPeriodData.map(stat => {
73+
// Calculate dstat based on position
74+
let dstat = 0;
75+
if (stat.pos === "G") {
76+
dstat = 0;
77+
} else if (stat.pos === "D") {
78+
dstat = (stat["stats/toi"] || 0) / 20 + (stat["stats/blocks"] || 0) + (stat["stats/take"] || 0) - (stat["stats/give"] || 0);
79+
} else { // Forward positions (F, C, LW, RW, etc.)
80+
dstat = (stat["stats/toi"] || 0) / 30 + (stat["stats/blocks"] || 0) + (stat["stats/take"] || 0) - (stat["stats/give"] || 0);
81+
}
82+
83+
// Calculate gstat based on position
84+
let gstat = 0;
85+
if (stat.pos === "G") {
86+
gstat = 2 * (stat["stats/wins"] || 0) + (stat["stats/ties"] || 0) + 2 * (stat["stats/so"] || 0) + 0.15 * (stat["stats/sa"] || 0) - (stat["stats/ga"] || 0);
87+
} else {
88+
gstat = 0;
89+
}
90+
91+
return {
92+
hockeyRef: stat.hockeyRef,
93+
team: stat.team,
94+
pos: stat.pos,
95+
goals: stat["stats/goals"] || 0,
96+
assists: stat["stats/assists"] || 0,
97+
toughness: (stat.pos === "G") ? 0 : ((stat["stats/pim"] || 0) + (stat["stats/hits"] || 0)),
98+
dstat: dstat,
99+
gstat: gstat,
100+
games_played: stat["stats/gp"] || 0
101+
};
102+
});
83103
} else {
84104
// For specific periods, calculate differences
85105
const selectedPeriodNum = parseInt(selectedPeriod.replace('Period ', ''));
@@ -91,16 +111,56 @@ function getStatsForPeriod(selectedPeriod) {
91111
return currentPeriodData.map(stat => {
92112
const prevStat = previousPeriodData?.find(p => p.hockeyRef === stat.hockeyRef);
93113

114+
// Calculate current period dstat
115+
let currentDstat = 0;
116+
if (stat.pos === "G") {
117+
currentDstat = 0;
118+
} else if (stat.pos === "D") {
119+
currentDstat = (stat["stats/toi"] || 0) / 20 + (stat["stats/blocks"] || 0) + (stat["stats/take"] || 0) - (stat["stats/give"] || 0);
120+
} else { // Forward positions
121+
currentDstat = (stat["stats/toi"] || 0) / 30 + (stat["stats/blocks"] || 0) + (stat["stats/take"] || 0) - (stat["stats/give"] || 0);
122+
}
123+
124+
// Calculate previous period dstat
125+
let prevDstat = 0;
126+
if (prevStat) {
127+
if (prevStat.pos === "G") {
128+
prevDstat = 0;
129+
} else if (prevStat.pos === "D") {
130+
prevDstat = (prevStat["stats/toi"] || 0) / 20 + (prevStat["stats/blocks"] || 0) + (prevStat["stats/take"] || 0) - (prevStat["stats/give"] || 0);
131+
} else { // Forward positions
132+
prevDstat = (prevStat["stats/toi"] || 0) / 30 + (prevStat["stats/blocks"] || 0) + (prevStat["stats/take"] || 0) - (prevStat["stats/give"] || 0);
133+
}
134+
}
135+
136+
// Calculate current period gstat
137+
let currentGstat = 0;
138+
if (stat.pos === "G") {
139+
currentGstat = 2 * (stat["stats/wins"] || 0) + (stat["stats/ties"] || 0) + 2 * (stat["stats/so"] || 0) + 0.15 * (stat["stats/sa"] || 0) - (stat["stats/ga"] || 0);
140+
} else {
141+
currentGstat = 0;
142+
}
143+
144+
// Calculate previous period gstat
145+
let prevGstat = 0;
146+
if (prevStat) {
147+
if (prevStat.pos === "G") {
148+
prevGstat = 2 * (prevStat["stats/wins"] || 0) + (prevStat["stats/ties"] || 0) + 2 * (prevStat["stats/so"] || 0) + 0.15 * (prevStat["stats/sa"] || 0) - (prevStat["stats/ga"] || 0);
149+
} else {
150+
prevGstat = 0;
151+
}
152+
}
153+
94154
return {
95155
hockeyRef: stat.hockeyRef,
96156
team: stat.team,
97157
pos: stat.pos,
98158
goals: (stat["stats/goals"] || 0) - (prevStat?.["stats/goals"] || 0),
99159
assists: (stat["stats/assists"] || 0) - (prevStat?.["stats/assists"] || 0),
100-
toughness: (stat["stats/toughness"] || 0) - (prevStat?.["stats/toughness"] || 0),
101-
dstat: (stat["stats/dstat"] || 0) - (prevStat?.["stats/dstat"] || 0),
102-
gstat: (stat["stats/gstat"] || 0) - (prevStat?.["stats/gstat"] || 0),
103-
games_played: (stat["stats/gp"] || stat["stats/games_played"] || 0) - (prevStat?.["stats/gp"] || prevStat?.["stats/games_played"] || 0)
160+
toughness: (stat.pos === "G") ? 0 : (((stat["stats/pim"] || 0) + (stat["stats/hits"] || 0)) - ((prevStat?.["stats/pim"] || 0) + (prevStat?.["stats/hits"] || 0))),
161+
dstat: currentDstat - prevDstat,
162+
gstat: currentGstat - prevGstat,
163+
games_played: (stat["stats/gp"] || 0) - (prevStat?.["stats/gp"] || 0)
104164
};
105165
});
106166
}
@@ -268,6 +328,29 @@ const filteredStatsData = playerStatsData
268328
});
269329
```
270330
331+
```js
332+
// Calculate totals for active and reserve players
333+
const activeTotals = filteredStatsData
334+
.filter(player => player.Reserve !== "R" && player.Reserve !== "N/A")
335+
.reduce((totals, player) => ({
336+
goals: totals.goals + (player.Goals || 0),
337+
assists: totals.assists + (player.Assists || 0),
338+
toughness: totals.toughness + (player.Toughness || 0),
339+
dstat: totals.dstat + (player.DStat || 0),
340+
gstat: totals.gstat + (player.GStat || 0)
341+
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
342+
343+
const reserveTotals = filteredStatsData
344+
.filter(player => player.Reserve === "R")
345+
.reduce((totals, player) => ({
346+
goals: totals.goals + (player.Goals || 0),
347+
assists: totals.assists + (player.Assists || 0),
348+
toughness: totals.toughness + (player.Toughness || 0),
349+
dstat: totals.dstat + (player.DStat || 0),
350+
gstat: totals.gstat + (player.GStat || 0)
351+
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
352+
```
353+
271354
<div class="tabs">
272355
<div class="tab-buttons">
273356
<button class="tab-button active" onclick="showTab('contract-tab', this)">Player Contracts</button>
@@ -331,6 +414,24 @@ const filteredStatsData = playerStatsData
331414
332415
<div id="stats-tab" class="tab-content">
333416
<h3>Player Statistics</h3>
417+
<div class="stats-totals">
418+
<div class="totals-row active-totals">
419+
<strong>Active Totals:</strong>
420+
<span>Goals: ${activeTotals.goals}</span>
421+
<span>Assists: ${activeTotals.assists}</span>
422+
<span>Toughness: ${activeTotals.toughness}</span>
423+
<span>D-Stat: ${activeTotals.dstat.toFixed(2)}</span>
424+
<span>G-Stat: ${activeTotals.gstat.toFixed(2)}</span>
425+
</div>
426+
<div class="totals-row reserve-totals">
427+
<strong>Reserve Totals:</strong>
428+
<span>Goals: ${reserveTotals.goals}</span>
429+
<span>Assists: ${reserveTotals.assists}</span>
430+
<span>Toughness: ${reserveTotals.toughness}</span>
431+
<span>D-Stat: ${reserveTotals.dstat.toFixed(2)}</span>
432+
<span>G-Stat: ${reserveTotals.gstat.toFixed(2)}</span>
433+
</div>
434+
</div>
334435
${Inputs.table(filteredStatsData, {
335436
columns: ["Name", "Team", "Position", "Reserve", "Goals", "Assists", "Toughness", "DStat", "GStat", "GamesPlayed", "NHLTeam"],
336437
header: {
@@ -571,6 +672,27 @@ function updateTables() {
571672
const filteredRosterData = filterPlayers(window.playerData.playerRosterData);
572673
const filteredStatsData = filterPlayers(window.playerData.playerStatsData);
573674
675+
// Calculate totals for active and reserve players
676+
const activeTotals = filteredStatsData
677+
.filter(player => player.Reserve !== "R" && player.Reserve !== "N/A")
678+
.reduce((totals, player) => ({
679+
goals: totals.goals + (player.Goals || 0),
680+
assists: totals.assists + (player.Assists || 0),
681+
toughness: totals.toughness + (player.Toughness || 0),
682+
dstat: totals.dstat + (player.DStat || 0),
683+
gstat: totals.gstat + (player.GStat || 0)
684+
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
685+
686+
const reserveTotals = filteredStatsData
687+
.filter(player => player.Reserve === "R")
688+
.reduce((totals, player) => ({
689+
goals: totals.goals + (player.Goals || 0),
690+
assists: totals.assists + (player.Assists || 0),
691+
toughness: totals.toughness + (player.Toughness || 0),
692+
dstat: totals.dstat + (player.DStat || 0),
693+
gstat: totals.gstat + (player.GStat || 0)
694+
}), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
695+
574696
console.log('Filtered data lengths:', {
575697
contract: filteredContractData.length,
576698
roster: filteredRosterData.length,
@@ -646,6 +768,29 @@ function updateTables() {
646768
// Update stats table
647769
const statsContainer = document.getElementById('stats-table');
648770
if (statsContainer && typeof Inputs !== 'undefined') {
771+
// Update totals display
772+
const statsTotalsContainer = statsContainer.parentElement.querySelector('.stats-totals');
773+
if (statsTotalsContainer) {
774+
statsTotalsContainer.innerHTML = `
775+
<div class="totals-row active-totals">
776+
<strong>Active Totals:</strong>
777+
<span>Goals: ${activeTotals.goals}</span>
778+
<span>Assists: ${activeTotals.assists}</span>
779+
<span>Toughness: ${activeTotals.toughness}</span>
780+
<span>D-Stat: ${activeTotals.dstat.toFixed(2)}</span>
781+
<span>G-Stat: ${activeTotals.gstat.toFixed(2)}</span>
782+
</div>
783+
<div class="totals-row reserve-totals">
784+
<strong>Reserve Totals:</strong>
785+
<span>Goals: ${reserveTotals.goals}</span>
786+
<span>Assists: ${reserveTotals.assists}</span>
787+
<span>Toughness: ${reserveTotals.toughness}</span>
788+
<span>D-Stat: ${reserveTotals.dstat.toFixed(2)}</span>
789+
<span>G-Stat: ${reserveTotals.gstat.toFixed(2)}</span>
790+
</div>
791+
`;
792+
}
793+
649794
statsContainer.innerHTML = filteredStatsData.length > 0 ? '' : '<p>No players found for this team.</p>';
650795
if (filteredStatsData.length > 0) {
651796
try {
@@ -785,4 +930,44 @@ window.showTab = function(tabId, buttonElement) {
785930
border-bottom: 1px solid #e0e0e0;
786931
padding-bottom: 8px;
787932
}
933+
934+
.stats-totals {
935+
margin: 15px 0;
936+
padding: 15px;
937+
background-color: #f8f9fa;
938+
border-radius: 6px;
939+
border: 1px solid #e0e0e0;
940+
}
941+
942+
.totals-row {
943+
display: flex;
944+
gap: 20px;
945+
align-items: center;
946+
margin-bottom: 8px;
947+
padding: 8px 0;
948+
}
949+
950+
.totals-row:last-child {
951+
margin-bottom: 0;
952+
}
953+
954+
.active-totals {
955+
border-bottom: 1px solid #ddd;
956+
padding-bottom: 12px;
957+
}
958+
959+
.totals-row strong {
960+
min-width: 120px;
961+
color: #333;
962+
}
963+
964+
.totals-row span {
965+
font-weight: 500;
966+
color: #555;
967+
background-color: white;
968+
padding: 4px 8px;
969+
border-radius: 4px;
970+
border: 1px solid #ddd;
971+
font-size: 14px;
972+
}
788973
</style>

0 commit comments

Comments
 (0)