Skip to content
Merged
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: 32 additions & 0 deletions src/apps/profiles/src/hooks/useFetchActiveTracks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,38 @@ describe('getSubTrackSummaryStats', () => {
wins: 2,
})
})

it('keeps aggregate Marathon Match wins when legacy placement history is partial', () => {
const summaryStats = getSubTrackSummaryStats({
challenges: 225,
name: 'MARATHON_MATCH',
submissions: {
submissions: 7,
},
wins: 76,
} as MemberStats, [
{
challengeId: 'legacy-mm-1',
challengeName: 'Legacy Marathon Match 1',
newRating: 1210,
placement: 122,
ratingDate: 1301961600000,
},
{
challengeId: 'legacy-mm-2',
challengeName: 'Legacy Marathon Match 2',
newRating: 1218,
placement: 145,
ratingDate: 1302652800000,
},
])

expect(summaryStats)
.toEqual({
submissions: 7,
wins: 76,
})
})
})

describe('getTrackSummaryStats', () => {
Expand Down
12 changes: 9 additions & 3 deletions src/apps/profiles/src/hooks/useFetchActiveTracks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export const getSubTrackDisplaySubmissionCount = (subTrack?: MemberStats): numbe
* Some unified stats rows currently include challenge/rating history while the
* aggregate win or submission counters are stale, omitted, or left at zero. In
* that case, placement-bearing history is used for wins and history/challenge
* count is used as the minimum visible submission count.
* count is used as the minimum visible submission count. Legacy Marathon Match
* history is partial, so its explicit aggregate win counter remains authoritative.
*
* @param {MemberStats | undefined} subTrack - The subtrack to summarize.
* @param {StatsHistory[]} trackHistory - Optional history rows for the same subtrack.
Expand All @@ -130,16 +131,21 @@ export const getSubTrackSummaryStats = (
subTrack?: MemberStats,
trackHistory: StatsHistory[] = [],
): SubTrackSummaryStats => {
const statWins = getFiniteNumber(subTrack?.wins) ?? 0
const aggregateWins = getFiniteNumber(subTrack?.wins)
const statWins = aggregateWins ?? 0
const historyWithPlacements = trackHistory
.filter(history => getFiniteNumber(history.placement) !== undefined)
const historyWins = historyWithPlacements.filter(history => history.placement === 1).length
const displaySubmissions = getSubTrackDisplaySubmissionCount(subTrack) ?? 0
const historySubmissions = trackHistory.length
const hasAuthoritativeAggregateWins = subTrack?.name === 'MARATHON_MATCH'
&& aggregateWins !== undefined

return {
submissions: Math.max(displaySubmissions, historySubmissions),
wins: historyWithPlacements.length > 0 ? historyWins : statWins,
wins: historyWithPlacements.length > 0 && !hasAuthoritativeAggregateWins
? historyWins
: statWins,
}
}

Expand Down
Loading