Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/api/FantasyFootballApiv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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)
};
});

Expand Down
4 changes: 4 additions & 0 deletions src/api/FantasyFootballApiv2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
13 changes: 12 additions & 1 deletion src/pages/rankings/TrueRankingsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand Down Expand Up @@ -140,6 +140,12 @@ export default function TrueRankinsTable(props) {
>
Simulated Record
</StyledTableCell>
<StyledTableCell
align="center"
css={{ minWidth: isLargeScreen ? '100px' : undefined }}
>
Simulated Record by Week
</StyledTableCell>
<StyledTableCell
align="center"
css={{ minWidth: isLargeScreen ? '100px' : undefined }}
Expand All @@ -163,6 +169,11 @@ export default function TrueRankinsTable(props) {
{row.totalWins} - {row.totalLosses}
</Typography>
</StyledTableCell>
<StyledTableCell align="center" className="simulated-record-cell">
<Typography variant="body1">
{row.totalSimWeekWins} - {row.totalSimWeekLosses}
</Typography>
</StyledTableCell>
<StyledTableCell align="center" className="actual-record-cell">
<Typography variant="body1">
{row.actualRecord.wins} - {row.actualRecord.losses}
Expand Down