-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from AlecM33/score-on-embed
Add current score to embed, display due up on 3rd out, indicate barrels
- Loading branch information
Showing
9 changed files
with
170 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const liveFeed = require('./livefeed'); | ||
const globalCache = require('./global-cache'); | ||
const globals = require('../config/globals'); | ||
const ColorContrastChecker = require('color-contrast-checker'); | ||
|
||
module.exports = { | ||
deriveHalfInning: (halfInningFull) => { | ||
return halfInningFull === 'top' ? 'TOP' : 'BOT'; | ||
}, | ||
|
||
didGameEnd: (homeScore, awayScore) => { | ||
const feed = liveFeed.init(globalCache.values.game.currentLiveFeed); | ||
return feed.inning() >= 9 | ||
&& ( | ||
(homeScore > awayScore && feed.halfInning() === 'top') | ||
|| (awayScore > homeScore && feed.halfInning() === 'bottom') | ||
); | ||
}, | ||
|
||
getConstrastingEmbedColors: () => { | ||
const feed = liveFeed.init(globalCache.values.game.currentLiveFeed); | ||
globalCache.values.game.homeTeamColor = globals.TEAMS.find( | ||
team => team.id === feed.homeTeamId() | ||
).primaryColor; | ||
const awayTeam = globals.TEAMS.find( | ||
team => team.id === feed.awayTeamId() | ||
); | ||
const colorContrastChecker = new ColorContrastChecker(); | ||
if (colorContrastChecker.isLevelCustom(globalCache.values.game.homeTeamColor, awayTeam.primaryColor, globals.TEAM_COLOR_CONTRAST_RATIO)) { | ||
globalCache.values.game.awayTeamColor = awayTeam.primaryColor; | ||
} else { | ||
globalCache.values.game.awayTeamColor = awayTeam.secondaryColor; | ||
} | ||
}, | ||
|
||
getDueUp: () => { | ||
const feed = liveFeed.init(globalCache.values.game.currentLiveFeed); | ||
const linescore = feed.linescore(); | ||
|
||
return '\n\n**Due up**: ' + linescore.offense?.batter?.fullName + ', ' + linescore.offense?.onDeck?.fullName + ', ' + linescore.offense?.inHole?.fullName; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = { | ||
init: (liveFeed) => { | ||
return { | ||
timestamp: () => { | ||
return liveFeed.metaData.timeStamp; | ||
}, | ||
inning: () => { | ||
return liveFeed.liveData.plays.currentPlay.about.inning; | ||
}, | ||
halfInning: () => { | ||
return liveFeed.liveData.plays.currentPlay.about.halfInning; | ||
}, | ||
awayAbbreviation: () => { | ||
return liveFeed.gameData.teams.away.abbreviation; | ||
}, | ||
homeAbbreviation: () => { | ||
return liveFeed.gameData.teams.home.abbreviation; | ||
}, | ||
homeTeamId: () => { | ||
return liveFeed.gameData.teams.home.id; | ||
}, | ||
awayTeamId: () => { | ||
return liveFeed.gameData.teams.away.id; | ||
}, | ||
currentPlay: () => { | ||
return liveFeed.liveData.plays.currentPlay; | ||
}, | ||
allPlays: () => { | ||
return liveFeed.liveData.plays.allPlays; | ||
}, | ||
linescore: () => { | ||
return liveFeed.liveData.linescore; | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const gamedayUtil = require('../modules/gameday-util'); | ||
const liveFeed = require('../modules/livefeed'); | ||
|
||
describe('gameday-util', () => { | ||
beforeAll(() => {}); | ||
|
||
describe('#didGameEnd', () => { | ||
it('should say the game ended when the top of the 9th ended with the home team leading', async () => { | ||
spyOn(liveFeed, 'init').and.returnValue({ | ||
inning: () => { return 9; }, | ||
halfInning: () => { return 'top'; } | ||
}); | ||
expect(gamedayUtil.didGameEnd(3, 2)).toBeTrue(); | ||
}); | ||
|
||
it('should say the game ended when the bottom of the 9th ended with the away team leading', async () => { | ||
spyOn(liveFeed, 'init').and.returnValue({ | ||
inning: () => { return 9; }, | ||
halfInning: () => { return 'bottom'; } | ||
}); | ||
expect(gamedayUtil.didGameEnd(2, 3)).toBeTrue(); | ||
}); | ||
|
||
it('should say the game is still going if the game is tied', async () => { | ||
spyOn(liveFeed, 'init').and.returnValue({ | ||
inning: () => { return 9; }, | ||
halfInning: () => { return 'bottom'; } | ||
}); | ||
expect(gamedayUtil.didGameEnd(3, 3)).toBeFalse(); | ||
}); | ||
|
||
it('should say the game is still going the top of the 9th has ended with the away team leading', async () => { | ||
spyOn(liveFeed, 'init').and.returnValue({ | ||
inning: () => { return 9; }, | ||
halfInning: () => { return 'top'; } | ||
}); | ||
expect(gamedayUtil.didGameEnd(3, 10)).toBeFalse(); | ||
}); | ||
|
||
it('should say the game ended when the top of an extra inning ended with the home team leading', async () => { | ||
spyOn(liveFeed, 'init').and.returnValue({ | ||
inning: () => { return 15; }, | ||
halfInning: () => { return 'top'; } | ||
}); | ||
expect(gamedayUtil.didGameEnd(3, 2)).toBeTrue(); | ||
}); | ||
}); | ||
}); |