@@ -71,30 +71,28 @@ function getStatsForPeriod(selectedPeriod) {
7171
7272 return latestPeriodData .map (stat => {
7373 // Calculate dstat based on position
74- let dstat = 0 ;
74+ let dstat = null ;
7575 if (stat .pos === " G" ) {
76- dstat = 0 ;
76+ dstat = null ;
7777 } else if (stat .pos === " D" ) {
7878 dstat = (stat[" stats/toi" ] || 0 ) / 20 + (stat[" stats/blocks" ] || 0 ) + (stat[" stats/take" ] || 0 ) - (stat[" stats/give" ] || 0 );
7979 } else { // Forward positions (F, C, LW, RW, etc.)
8080 dstat = (stat[" stats/toi" ] || 0 ) / 30 + (stat[" stats/blocks" ] || 0 ) + (stat[" stats/take" ] || 0 ) - (stat[" stats/give" ] || 0 );
8181 }
8282
8383 // Calculate gstat based on position
84- let gstat = 0 ;
84+ let gstat = null ;
8585 if (stat .pos === " G" ) {
8686 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 ;
8987 }
9088
9189 return {
9290 hockeyRef: stat .hockeyRef ,
9391 team: stat .team ,
9492 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 )),
93+ goals: ( stat . pos === " G " ) ? null : (stat [" stats/goals" ] || 0 ) ,
94+ assists: ( stat . pos === " G " ) ? null : (stat [" stats/assists" ] || 0 ) ,
95+ toughness: (stat .pos === " G" ) ? null : ((stat[" stats/pim" ] || 0 ) + (stat[" stats/hits" ] || 0 )),
9896 dstat: dstat,
9997 gstat: gstat,
10098 games_played: stat[" stats/gp" ] || 0
@@ -134,32 +132,41 @@ function getStatsForPeriod(selectedPeriod) {
134132 }
135133
136134 // Calculate current period gstat
137- let currentGstat = 0 ;
135+ let currentGstat = null ;
138136 if (stat .pos === " G" ) {
139137 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 ;
142138 }
143139
144140 // 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- }
141+ let prevGstat = null ;
142+ if (prevStat && prevStat .pos === " G" ) {
143+ 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 );
144+ }
145+
146+ // Calculate gstat difference (only for goalies)
147+ let gstatDiff = null ;
148+ if (stat .pos === " G" ) {
149+ gstatDiff = (currentGstat || 0 ) - (prevGstat || 0 );
150+ }
151+
152+ // Calculate current period toughness
153+ let currentToughness = (stat .pos === " G" ) ? 0 : ((stat[" stats/pim" ] || 0 ) + (stat[" stats/hits" ] || 0 ));
154+
155+ // Calculate previous period toughness
156+ let prevToughness = 0 ;
157+ if (prevStat && prevStat .pos !== " G" ) {
158+ prevToughness = (prevStat[" stats/pim" ] || 0 ) + (prevStat[" stats/hits" ] || 0 );
152159 }
153160
154161 return {
155162 hockeyRef: stat .hockeyRef ,
156163 team: stat .team ,
157164 pos: stat .pos ,
158- goals: (stat[" stats/goals" ] || 0 ) - (prevStat? .[" stats/goals" ] || 0 ),
159- assists: (stat[" stats/assists" ] || 0 ) - (prevStat? .[" stats/assists" ] || 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 ,
165+ goals: (stat . pos === " G " ) ? null : ((stat [" stats/goals" ] || 0 ) - (prevStat? .[" stats/goals" ] || 0 ) ),
166+ assists: (stat . pos === " G " ) ? null : ((stat [" stats/assists" ] || 0 ) - (prevStat? .[" stats/assists" ] || 0 ) ),
167+ toughness: (stat .pos === " G" ) ? null : (currentToughness - prevToughness ),
168+ dstat: ( stat . pos === " G " ) ? null : ( currentDstat - prevDstat) ,
169+ gstat: gstatDiff ,
163170 games_played: (stat[" stats/gp" ] || 0 ) - (prevStat? .[" stats/gp" ] || 0 )
164171 };
165172 });
@@ -280,11 +287,11 @@ function createPlayerStatsData(selectedPeriod) {
280287 Team: roster ? roster .ABBR : " N/A" ,
281288 Position : mapPosition (player .Pos ),
282289 Reserve: roster ? roster .RESERVE : " N/A" ,
283- Goals: stats ? stats .goals : 0 ,
284- Assists: stats ? stats .assists : 0 ,
285- Toughness: stats ? stats .toughness : 0 ,
286- DStat: stats ? stats .dstat : 0 ,
287- GStat: stats ? stats .gstat : 0 ,
290+ Goals: stats ? stats .goals : ( mapPosition ( player . Pos ) === " G " ? null : 0 ) ,
291+ Assists: stats ? stats .assists : ( mapPosition ( player . Pos ) === " G " ? null : 0 ) ,
292+ Toughness: stats ? stats .toughness : ( mapPosition ( player . Pos ) === " G " ? null : 0 ) ,
293+ DStat: stats ? stats .dstat : ( mapPosition ( player . Pos ) === " G " ? null : 0 ) ,
294+ GStat: stats ? ( stats .gstat !== null ? stats . gstat : ( mapPosition ( player . Pos ) === " G " ? 0 : null )) : ( mapPosition ( player . Pos ) === " G " ? 0 : null ) ,
288295 GamesPlayed: stats ? stats .games_played : 0 ,
289296 NHLTeam: player[" NHL Team" ]
290297 };
@@ -333,21 +340,21 @@ const filteredStatsData = playerStatsData
333340const activeTotals = filteredStatsData
334341 .filter (player => player .Reserve !== " R" && player .Reserve !== " N/A" )
335342 .reduce ((totals , player ) => ({
336- goals: totals .goals + (player .Goals || 0 ),
337- assists: totals .assists + (player .Assists || 0 ),
338- toughness: totals .toughness + (player .Toughness || 0 ),
343+ goals: totals .goals + (player .Position !== " G " ? ( player . Goals || 0 ) : 0 ),
344+ assists: totals .assists + (player .Position !== " G " ? ( player . Assists || 0 ) : 0 ),
345+ toughness: totals .toughness + (player .Position !== " G " ? ( player . Toughness || 0 ) : 0 ),
339346 dstat: totals .dstat + (player .DStat || 0 ),
340- gstat: totals .gstat + (player .GStat || 0 )
347+ gstat: totals .gstat + (player .GStat !== null ? player . GStat : 0 )
341348 }), { goals: 0 , assists: 0 , toughness: 0 , dstat: 0 , gstat: 0 });
342349
343350const reserveTotals = filteredStatsData
344351 .filter (player => player .Reserve === " R" )
345352 .reduce ((totals , player ) => ({
346- goals: totals .goals + (player .Goals || 0 ),
347- assists: totals .assists + (player .Assists || 0 ),
348- toughness: totals .toughness + (player .Toughness || 0 ),
353+ goals: totals .goals + (player .Position !== " G " ? ( player . Goals || 0 ) : 0 ),
354+ assists: totals .assists + (player .Position !== " G " ? ( player . Assists || 0 ) : 0 ),
355+ toughness: totals .toughness + (player .Position !== " G " ? ( player . Toughness || 0 ) : 0 ),
349356 dstat: totals .dstat + (player .DStat || 0 ),
350- gstat: totals .gstat + (player .GStat || 0 )
357+ gstat: totals .gstat + (player .GStat !== null ? player . GStat : 0 )
351358 }), { goals: 0 , assists: 0 , toughness: 0 , dstat: 0 , gstat: 0 });
352359` ` `
353360
@@ -449,8 +456,11 @@ const reserveTotals = filteredStatsData
449456 },
450457 format: {
451458 Reserve : x => x === " R" ? " ✓" : " " ,
452- DStat : x => x ? x .toFixed (2 ) : " 0.00" ,
453- GStat : x => x ? x .toFixed (2 ) : " 0.00"
459+ Goals : x => x !== null ? x : " " ,
460+ Assists : x => x !== null ? x : " " ,
461+ Toughness : x => x !== null ? x : " " ,
462+ DStat : x => x !== null ? x .toFixed (2 ) : " " ,
463+ GStat : x => x !== null ? x .toFixed (2 ) : " "
454464 },
455465 sort: null ,
456466 rows: Math .min (filteredStatsData .length , 50 ),
@@ -573,11 +583,11 @@ window.createPlayerStatsData = function(selectedPeriod) {
573583 Team: roster ? roster.ABBR : "N/A",
574584 Position: window.mapPosition(player.Pos),
575585 Reserve: roster ? roster.RESERVE : "N/A",
576- Goals: stats ? stats.goals : 0 ,
577- Assists: stats ? stats.assists : 0 ,
578- Toughness: stats ? stats.toughness : 0 ,
579- DStat: stats ? stats.dstat : 0 ,
580- GStat: stats ? stats.gstat : 0 ,
586+ Goals: stats ? stats.goals : (window.mapPosition(player.Pos) === "G" ? null : 0) ,
587+ Assists: stats ? stats.assists : (window.mapPosition(player.Pos) === "G" ? null : 0) ,
588+ Toughness: stats ? stats.toughness : (window.mapPosition(player.Pos) === "G" ? null : 0) ,
589+ DStat: stats ? stats.dstat : (window.mapPosition(player.Pos) === "G" ? null : 0) ,
590+ GStat: stats ? ( stats.gstat !== null ? stats.gstat : (window.mapPosition(player.Pos) === "G" ? 0 : null)) : (window.mapPosition(player.Pos) === "G" ? 0 : null) ,
581591 GamesPlayed: stats ? stats.games_played : 0,
582592 NHLTeam: player["NHL Team"]
583593 };
@@ -676,21 +686,21 @@ function updateTables() {
676686 const activeTotals = filteredStatsData
677687 .filter(player => player.Reserve !== "R" && player.Reserve !== "N/A")
678688 .reduce((totals, player) => ({
679- goals: totals.goals + (player.Goals || 0),
680- assists: totals.assists + (player.Assists || 0),
681- toughness: totals.toughness + (player.Toughness || 0),
689+ goals: totals.goals + (player.Position !== "G" ? (player. Goals || 0) : 0),
690+ assists: totals.assists + (player.Position !== "G" ? (player. Assists || 0) : 0),
691+ toughness: totals.toughness + (player.Position !== "G" ? (player. Toughness || 0) : 0),
682692 dstat: totals.dstat + (player.DStat || 0),
683- gstat: totals.gstat + (player.GStat || 0)
693+ gstat: totals.gstat + (player.GStat !== null ? player.GStat : 0)
684694 }), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
685695
686696 const reserveTotals = filteredStatsData
687697 .filter(player => player.Reserve === "R")
688698 .reduce((totals, player) => ({
689- goals: totals.goals + (player.Goals || 0),
690- assists: totals.assists + (player.Assists || 0),
691- toughness: totals.toughness + (player.Toughness || 0),
699+ goals: totals.goals + (player.Position !== "G" ? (player. Goals || 0) : 0),
700+ assists: totals.assists + (player.Position !== "G" ? (player. Assists || 0) : 0),
701+ toughness: totals.toughness + (player.Position !== "G" ? (player. Toughness || 0) : 0),
692702 dstat: totals.dstat + (player.DStat || 0),
693- gstat: totals.gstat + (player.GStat || 0)
703+ gstat: totals.gstat + (player.GStat !== null ? player.GStat : 0)
694704 }), { goals: 0, assists: 0, toughness: 0, dstat: 0, gstat: 0 });
695705
696706 console.log('Filtered data lengths:', {
0 commit comments