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
32 changes: 21 additions & 11 deletions frontend/src/app/modules/matches/matches-computations.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,37 @@ export const plotRatingHistory = (userMatches, userId, initialRating) => {
))
}

export const computeLongestWinStreak = (userId, userMatches) => {
export const computeStreaks = (userId, userMatches) => {
const initialState = {
longest: 0,
current: 0,
longestWinStreak: 0,
currentWinStreak: 0,
highestEloGainStreak: 0,
currentEloGainStreak: 0,
}

return userMatches.reduce((state, match) => {
const reversedMatches = [...userMatches].reverse()

return reversedMatches.reduce((state, match) => {
if (didUserWin(userId, match)) {
const current = state.current + 1
const longest = Math.max(current, state.longest)
const currentWinStreak = state.currentWinStreak + 1
const longestWinStreak = Math.max(currentWinStreak, state.longestWinStreak)
const currentEloGainStreak = state.currentEloGainStreak + match.winningTeamRatingChange
const highestEloGainStreak = Math.max(currentEloGainStreak, state.highestEloGainStreak)
return {
current,
longest,
currentWinStreak,
longestWinStreak,
currentEloGainStreak,
highestEloGainStreak,
}
} else {
return {
longest: state.longest,
current: 0,
longestWinStreak: state.longestWinStreak,
currentWinStreak: 0,
highestEloGainStreak: state.highestEloGainStreak,
currentEloGainStreak: 0,
}
}
}, initialState).longest
}, initialState)
}

export const computeWinRatio = (userId, userMatches) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/modules/matches/matches-selectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSelector } from 'reselect'
import {
computeLongestWinStreak,
computeStreaks,
computeWinRatio,
generateMatchRatingChanges,
plotRatingHistory,
Expand Down Expand Up @@ -39,7 +39,7 @@ const getLastMatchesForUser = createSelector(

const generateStatisticsForUser = (userId, userMatches) => ({
matchChanges: generateMatchRatingChanges(userId, userMatches),
longestStreak: computeLongestWinStreak(userId, userMatches),
streaks: computeStreaks(userId, userMatches),
winRatio: computeWinRatio(userId, userMatches),
totalMatches: userMatches.length,
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/modules/root/root-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const initialState = {

const usersLoaded = (state, { users }) => ({
...state,
users
users,
})

const updateUsersStatus = (state, { status }) => ({
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/app/pages/Profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ class ProfileComponent extends Component {

const {
user: { name, rating, id },
statistics: { totalMatches, winRatio, longestStreak, matchChanges },
statistics: {
totalMatches,
winRatio,
matchChanges,
streaks: {
currentWinStreak,
longestWinStreak,
currentEloGainStreak,
highestEloGainStreak,
},
},
} = this.props

return (
Expand All @@ -28,7 +38,10 @@ class ProfileComponent extends Component {
<ProfileDetail>
<Subtitle>Matches: {totalMatches}</Subtitle>
<Subtitle>Win Rate: {(winRatio * 100).toFixed(2)}%</Subtitle>
<Subtitle>Win Streak: {longestStreak}</Subtitle>
<Subtitle>Longest Win Streak: {longestWinStreak}</Subtitle>
<Subtitle>Current Win Streak: {currentWinStreak}</Subtitle>
<Subtitle>Highest Elo Gain Streak: {highestEloGainStreak}</Subtitle>
<Subtitle>Current Elo Gain Streak: {currentEloGainStreak}</Subtitle>
</ProfileDetail>
<ProfileRatingGraph userId={id} />
<ProfileBattleHistory matches={matchChanges} />
Expand Down