@@ -223,27 +223,7 @@ module.exports = {
223
223
} ,
224
224
225
225
buildStandingsTable : async ( standings , divisionName ) => {
226
- const centralMap = standings . teamRecords . map ( teamRecord => {
227
- return {
228
- name : teamRecord . team . name ,
229
- wins : teamRecord . leagueRecord . wins ,
230
- losses : teamRecord . leagueRecord . losses ,
231
- pct : teamRecord . leagueRecord . pct ,
232
- gamesBack : teamRecord . gamesBack ,
233
- homeRecord : ( ( ) => {
234
- const home = teamRecord . records . splitRecords . find ( record => record . type === 'home' ) ;
235
- return home . wins + '-' + home . losses ;
236
- } ) ( ) ,
237
- awayRecord : ( ( ) => {
238
- const away = teamRecord . records . splitRecords . find ( record => record . type === 'away' ) ;
239
- return away . wins + '-' + away . losses ;
240
- } ) ( ) ,
241
- lastTen : ( ( ) => {
242
- const l10 = teamRecord . records . splitRecords . find ( record => record . type === 'lastTen' ) ;
243
- return l10 . wins + '-' + l10 . losses ;
244
- } ) ( )
245
- } ;
246
- } ) ;
226
+ const centralMap = mapStandings ( standings ) ;
247
227
const table = new AsciiTable ( divisionName + '\n' ) ;
248
228
table . setHeading ( 'Team' , 'W-L' , 'GB' , 'L10' ) ;
249
229
centralMap . forEach ( ( entry ) => table . addRow (
@@ -256,6 +236,37 @@ module.exports = {
256
236
return ( await getScreenshotOfHTMLTables ( [ table ] ) ) ;
257
237
} ,
258
238
239
+ buildWildcardTable : async ( divisionLeaders , wildcard , leagueName ) => {
240
+ const divisionLeadersMap = mapStandings ( divisionLeaders ) ;
241
+ const wildcardMap = mapStandings ( wildcard , true ) ;
242
+ const table = new AsciiTable ( leagueName + ' Wild Card \n' ) ;
243
+ table . setHeading ( 'Team' , 'W-L' , 'WCGB' , 'L10' , 'STRK' ) ;
244
+ divisionLeadersMap . forEach ( ( entry ) => table . addRow (
245
+ entry . name ,
246
+ entry . wins + '-' + entry . losses ,
247
+ '-' ,
248
+ entry . lastTen ,
249
+ entry . streak
250
+ ) ) ;
251
+ let wildCardDivided = false ;
252
+ table . addRow ( '' , '' , '' , '' , '' ) ;
253
+ wildcardMap . forEach ( ( entry ) => {
254
+ if ( ! wildCardDivided && entry . gamesBack !== '-' && ! entry . gamesBack . includes ( '+' ) ) {
255
+ wildCardDivided = true ;
256
+ table . addRow ( '' , '' , '' , '' , '' ) ;
257
+ }
258
+ table . addRow (
259
+ entry . name ,
260
+ entry . wins + '-' + entry . losses ,
261
+ entry . gamesBack ,
262
+ entry . lastTen ,
263
+ entry . streak
264
+ ) ;
265
+ } ) ;
266
+ table . removeBorder ( ) ;
267
+ return ( await getScreenshotOfHTMLTables ( [ table ] ) ) ;
268
+ } ,
269
+
259
270
getStatcastData : ( savantText ) => {
260
271
const statcast = / s t a t c a s t : \[ (?< statcast > .+ ) ] ,/ . exec ( savantText ) ?. groups . statcast ;
261
272
const metricSummaries = / m e t r i c S u m m a r y S t a t s : { (?< metricSummaries > .+ ) } , / . exec ( savantText ) ?. groups . metricSummaries ;
@@ -858,6 +869,37 @@ module.exports = {
858
869
}
859
870
} ;
860
871
872
+ function mapStandings ( standings , wildcard = false ) {
873
+ return standings . teamRecords . map ( teamRecord => {
874
+ return {
875
+ name : teamRecord . team . name + ( standings . standingsType === 'divisionLeaders' ? ' - ' + getDivisionAbbreviation ( teamRecord . team . division . name ) : '' ) ,
876
+ wins : ( teamRecord . leagueRecord ?. wins === undefined ? teamRecord . wins : teamRecord . leagueRecord . wins ) ,
877
+ losses : ( teamRecord . leagueRecord ?. losses === undefined ? teamRecord . losses : teamRecord . leagueRecord . losses ) ,
878
+ pct : ( teamRecord . leagueRecord ?. pct === undefined ? teamRecord . pct : teamRecord . leagueRecord . pct ) ,
879
+ gamesBack : ( wildcard ? teamRecord . wildCardGamesBack : teamRecord . gamesBack ) ,
880
+ homeRecord : ( teamRecord . record_home
881
+ ? teamRecord . record_home
882
+ : ( ( ) => {
883
+ const home = teamRecord . records . splitRecords . find ( record => record . type === 'home' ) ;
884
+ return home . wins + '-' + home . losses ;
885
+ } ) ( ) ) ,
886
+ awayRecord : ( teamRecord . record_away
887
+ ? teamRecord . record_away
888
+ : ( ( ) => {
889
+ const away = teamRecord . records . splitRecords . find ( record => record . type === 'away' ) ;
890
+ return away . wins + '-' + away . losses ;
891
+ } ) ( ) ) ,
892
+ lastTen : ( teamRecord . record_lastTen
893
+ ? teamRecord . record_lastTen
894
+ : ( ( ) => {
895
+ const l10 = teamRecord . records . splitRecords . find ( record => record . type === 'lastTen' ) ;
896
+ return l10 . wins + '-' + l10 . losses ;
897
+ } ) ( ) ) ,
898
+ streak : teamRecord . streak
899
+ } ;
900
+ } ) ;
901
+ }
902
+
861
903
function getPitchCollections ( dom ) {
862
904
const pitches = [ ] ;
863
905
const percentages = [ ] ;
@@ -1119,3 +1161,13 @@ function calculateRoundedPercentileFromNormalDistribution (metric, value, mean,
1119
1161
( shouldInvert ? ( 1.00 - ztable ( ( value - mean ) / standardDeviation ) ) : ztable ( ( value - mean ) / standardDeviation ) ) * 100
1120
1162
) ;
1121
1163
}
1164
+
1165
+ function getDivisionAbbreviation ( division ) {
1166
+ if ( division . toLowerCase ( ) . includes ( 'east' ) ) {
1167
+ return 'E' ;
1168
+ } else if ( division . toLowerCase ( ) . includes ( 'west' ) ) {
1169
+ return 'W' ;
1170
+ } else {
1171
+ return 'C' ;
1172
+ }
1173
+ }
0 commit comments