-
Notifications
You must be signed in to change notification settings - Fork 3
Detailed logs for LOSS 0.0 MMR #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9973a31
225f160
904c720
34d6605
7e36961
f17dbde
61f4639
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,18 +644,18 @@ export async function endMatch( | |
| teamResults = await calculateNewMMR(queueId, matchId, teamResultsData) | ||
|
|
||
| // Save elo_change and winstreak to database | ||
| // IMPORTANT: Always update elo_change to prevent race conditions | ||
| const updatePromises = teamResults.teams.flatMap((team) => | ||
| team.players.map(async (player) => { | ||
| // Update win streak | ||
| await updatePlayerWinStreak(player.user_id, queueId, team.score == 1) | ||
|
|
||
| // Update elo change if it exists | ||
| if (player.elo_change !== undefined && player.elo_change !== null) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Im being honest I don't see why exactly this would've caused issues to begin with. Maybe add some logging first to try and trace back the issue? ,flatMap is usually a bit confusing to work with, I have a suspicion something might be off because of it. Maybe rewrite it to use simpler methods instead? I also don't see how this change would fix the issue tbh |
||
| await pool.query( | ||
| `UPDATE match_users SET elo_change = $1 WHERE match_id = $2 AND user_id = $3`, | ||
| [player.elo_change, matchId, player.user_id], | ||
| ) | ||
| } | ||
| // Always update elo_change - use 0 as fallback if calculation failed | ||
| const eloChange = player.elo_change ?? 0 | ||
| await pool.query( | ||
| `UPDATE match_users SET elo_change = $1 WHERE match_id = $2 AND user_id = $3`, | ||
| [eloChange, matchId, player.user_id], | ||
| ) | ||
| }), | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -523,6 +523,7 @@ export async function createMatch( | |
| ) | ||
|
|
||
| // Insert match_users (queue_join_time is already NULL from matchUpGames) | ||
| // First, insert all users to create the match_users records | ||
| for (const userId of userIds) { | ||
| await pool.query( | ||
| `INSERT INTO match_users (user_id, match_id, team) | ||
|
|
@@ -543,6 +544,31 @@ export async function createMatch( | |
| } catch (err) {} | ||
| } | ||
|
|
||
| // Calculate and store initial ELO changes for all players | ||
| // This prevents the race condition where elo_change is 0 | ||
| try { | ||
| const { getTeamsInMatch } = await import('./matchHelpers') | ||
| const { calculatePredictedMMR } = await import('./algorithms/calculateMMR') | ||
|
|
||
| const teamData = await getTeamsInMatch(matchId) | ||
| if (teamData.teams.length > 0) { | ||
| // Calculate ELO changes assuming team 1 wins (as a baseline) | ||
| const winningTeamId = teamData.teams[0]?.id ?? 1 | ||
| const eloChanges = await calculatePredictedMMR(queueId, teamData, winningTeamId) | ||
|
|
||
| // Store the calculated ELO changes in match_users table | ||
| for (const [userId, eloChange] of eloChanges.entries()) { | ||
|
||
| await pool.query( | ||
| `UPDATE match_users SET elo_change = $1 WHERE match_id = $2 AND user_id = $3`, | ||
| [eloChange, matchId, userId], | ||
| ) | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error('Error calculating initial ELO changes:', err) | ||
|
||
| // Continue even if ELO calculation fails - it will be recalculated at match end | ||
| } | ||
|
|
||
| await updateQueueMessage() | ||
|
|
||
| // Wait 2 seconds for channel to fully propagate in Discord's API | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes my favorite kind of change