Skip to content

Commit

Permalink
#11 - Rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fezzzi committed Jul 9, 2020
1 parent 3e4dd84 commit 344c641
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions frontend/src/app/modules/matches/matches-computations.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ export const computeWinRatio = (playerId, playerMatches) => {
return (playerMatches.length > 0) ? (wonMatchesCount / playerMatches.length) : 0
}

export const computeKingStreakDuration = (matchesLast, usersLast) => {
if (usersLast.length < 1) {
export const computeKingStreakDuration = (matchesLast, playersLast) => {
if (playersLast.length < 1) {
return null
}

const usersMap = usersLast.reduce((map, user) => {
map[user.id] = user.rating
const playersMap = playersLast.reduce((map, player) => {
map[player.id] = player.rating
return map
}, new Map())

const kingId = usersLast[0].id
const kingId = playersLast[0].id
let matchFound = false
for (const match of matchesLast) {
const players = [...match.team1, ...match.team2]
Expand All @@ -88,20 +88,20 @@ export const computeKingStreakDuration = (matchesLast, usersLast) => {
const kingPlayer = players.find(player => player.id === kingId)
let kingWon = false
if (kingPlayer) {
kingWon = usersMap[kingId] > kingPlayer.matchRating
usersMap[kingId] = kingPlayer.matchRating
kingWon = playersMap[kingId] > kingPlayer.matchRating
playersMap[kingId] = kingPlayer.matchRating
}

// #2 check whether none of the other players beat the king
for (const player of players) {
usersMap[player.id] = player.matchRating
matchFound |= (player.id !== kingId && player.matchRating > usersMap[kingId])
playersMap[player.id] = player.matchRating
matchFound |= (player.id !== kingId && player.matchRating > playersMap[kingId])
}

// #3 check if king was first before winning
if (kingPlayer && kingWon && !matchFound) {
for (const key in usersMap) {
matchFound |= (usersMap[key] > usersMap[kingId])
for (const key in playersMap) {
matchFound |= (playersMap[key] > playersMap[kingId])
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/modules/matches/matches-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const generateStatisticsForPlayer = (playerId, playerMatches) => ({
export const getKing = createSelector(
getLastMatches,
getTopRatedPlayers,
(userMatches, users) => computeKingStreakDuration(userMatches, users)
(playerMatches, players) => computeKingStreakDuration(playerMatches, players),
)

export const getStatisticsForPlayer = createSelector(
Expand Down

0 comments on commit 344c641

Please sign in to comment.