Skip to content

Commit 2b0eb03

Browse files
committed
fix: mmr calc being wrong on recalculating win
Just makes sure to accont for already finished matches properly
1 parent e84913a commit 2b0eb03

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/utils/algorithms/calculateMMR.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,22 @@ export async function calculateNewMMR(
159159
const mmrChange = isWinner ? ratingChange : -ratingChange / loserCount
160160

161161
for (const player of ts.team.players) {
162-
const oldMMR = player.elo ?? queueSettings.default_elo
162+
// If this match was already processed, revert the previous MMR change
163+
// to get the pre-match MMR before applying the new change
164+
let currentMMR = player.elo ?? queueSettings.default_elo
165+
const previousEloChange = player.elo_change ?? 0
166+
const isRecalculation = previousEloChange !== 0
167+
168+
// Revert previous MMR change if it exists
169+
const oldMMR = currentMMR - previousEloChange
170+
163171
const oldRank = await getLeaderboardPosition(queueId, player.user_id)
164-
const oldVolatility = player.volatility ?? 0
172+
const currentVolatility = player.volatility ?? 0
173+
174+
// Only increment volatility if this is the first time processing this match
175+
const oldVolatility = isRecalculation
176+
? currentVolatility - 1
177+
: currentVolatility
165178

166179
const newMMR = parseFloat((oldMMR + mmrChange).toFixed(1))
167180
const newVolatility = Math.min(oldVolatility + 1, 10)

0 commit comments

Comments
 (0)