Skip to content

Commit 078a415

Browse files
committed
Graph fixes
- Adds first "point" (MMR starting point) to graph - Potential fix for 0 MMR issues but idk if it'll really work
1 parent 462d584 commit 078a415

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/utils/queryDB.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,27 @@ export async function getStatsCanvasUserData(
15131513
date: r.date as Date,
15141514
}))
15151515

1516+
// Get queue default_elo for initial data point
1517+
const queueSettings = await getQueueSettings(queueId)
1518+
const defaultElo = queueSettings.default_elo
1519+
15161520
const totalChange = eloChanges.reduce((sum, r) => sum + r.change, 0)
15171521
let running = (p.elo ?? 0) - totalChange
1518-
const elo_graph_data = eloChanges.map((r) => {
1522+
1523+
const elo_graph_data: { date: Date; rating: number }[] = []
1524+
1525+
// Add initial starting point if there are any matches
1526+
if (eloChanges.length > 0) {
1527+
const firstMatchDate = new Date(eloChanges[0].date)
1528+
const startDate = new Date(firstMatchDate.getTime() - 1000) // 1 second before
1529+
elo_graph_data.push({ date: startDate, rating: defaultElo })
1530+
}
1531+
1532+
// Add all match data points
1533+
eloChanges.forEach((r) => {
15191534
running += r.change
1520-
return { date: r.date, rating: running }
1535+
const clampedRating = Math.max(0, running) // Makes sure it stays within the range of 0-9999
1536+
elo_graph_data.push({ date: r.date, rating: clampedRating })
15211537
})
15221538

15231539
// Calculate percentiles for each stat using CTEs

0 commit comments

Comments
 (0)