diff --git a/src/api/FantasyFootballApiv2.js b/src/api/FantasyFootballApiv2.js index 8c92e6c..372d386 100644 --- a/src/api/FantasyFootballApiv2.js +++ b/src/api/FantasyFootballApiv2.js @@ -52,6 +52,17 @@ export const getPowerRankings = async (leagueId, seasonId) => { return week.scores.sort((a, b) => a.score - b.score); }); + //Function to keep track of simulated week wins total + const getSimWeekWins = (totalSimWeekWins, weekWins) => { + const weekLosses = data.teams.length - weekWins - 1; + + if (weekWins > weekLosses) { + return totalSimWeekWins + 1; + } else { + return totalSimWeekWins; + } + }; + //Map wins and scores onto team data const teams = data.teams.map(team => { const wins = sortedWeeklyScores.map(week => { @@ -74,7 +85,9 @@ export const getPowerRankings = async (leagueId, seasonId) => { totalWins: wins.reduce((acc, x) => acc + x, 0), totalLosses: Object.keys(weeklyResults).length * (data.teams.length - 1) - - wins.reduce((acc, x) => acc + x, 0) + wins.reduce((acc, x) => acc + x, 0), + totalSimWeekWins: wins.reduce(getSimWeekWins, 0), + totalSimWeekLosses: Object.keys(weeklyResults).length - wins.reduce(getSimWeekWins, 0) }; }); diff --git a/src/api/FantasyFootballApiv2.test.js b/src/api/FantasyFootballApiv2.test.js index 4d5a7a2..c6b65bd 100644 --- a/src/api/FantasyFootballApiv2.test.js +++ b/src/api/FantasyFootballApiv2.test.js @@ -15,7 +15,11 @@ describe('API', () => { const rankings = await getPowerRankings(); expect(rankings[0].totalWins).toEqual(88); expect(rankings[0].totalLosses).toEqual(44); + expect(rankings[0].totalSimWeekWins).toEqual(8); + expect(rankings[0].totalSimWeekLosses).toEqual(4); expect(rankings[11].totalWins).toEqual(40); expect(rankings[11].totalLosses).toEqual(92); + expect(rankings[11].totalSimWeekWins).toEqual(3); + expect(rankings[11].totalSimWeekLosses).toEqual(9); }); }); diff --git a/src/pages/rankings/TrueRankingsTable.js b/src/pages/rankings/TrueRankingsTable.js index 9f3327a..fa159d1 100644 --- a/src/pages/rankings/TrueRankingsTable.js +++ b/src/pages/rankings/TrueRankingsTable.js @@ -83,7 +83,7 @@ const StyledTableCell = styled(TableCell)({ padding: '14px' }); -export default function TrueRankinsTable(props) { +export default function TrueRankingsTable(props) { const classes = useStyles(); const isLargeScreen = useMediaQuery('(min-width:960px)'); @@ -140,6 +140,12 @@ export default function TrueRankinsTable(props) { > Simulated Record + + Simulated Record by Week + + + + {row.totalSimWeekWins} - {row.totalSimWeekLosses} + + {row.actualRecord.wins} - {row.actualRecord.losses}