use rank 10 million for unranked players

This commit is contained in:
2026-03-09 22:36:20 +01:00
parent 2b2de11c73
commit de1e5a7f21
3 changed files with 27 additions and 10 deletions

View File

@@ -14,8 +14,9 @@ import { proxyImage } from './storage/r2';
let pendingOsuProfile: { rank: number | null } | null = null;
function eloFromRank(rank: number | null): { elo: number; osuRank: number | null } {
if (!rank || rank <= 0) return { elo: 1000, osuRank: null };
const rawElo = 3500 - Math.log10(rank) * 500;
// Unranked → treat as rank 10,000,000 (yields 0 ELO)
const effectiveRank = rank && rank > 0 ? rank : 10_000_000;
const rawElo = 3500 - Math.log10(effectiveRank) * 500;
return { elo: Math.round(Math.max(0, Math.min(3500, rawElo))), osuRank: rank };
}

View File

@@ -148,15 +148,31 @@ export const actions: Actions = {
// API failure — treat as unranked
}
// Unranked → rank 100,000 (~1000 ELO)
const effectiveRank = rank && rank > 0 ? rank : 100_000;
// Unranked → rank 10,000,000 (yields 0 ELO)
const effectiveRank = rank && rank > 0 ? rank : 10_000_000;
const rawElo = 3500 - Math.log10(effectiveRank) * 500;
const elo = Math.round(Math.max(0, Math.min(3500, rawElo)));
await db
.update(playerRating)
.set({ elo, initialElo: elo, osuRankAtSeed: rank, wins: 0, losses: 0, updatedAt: new Date() })
.where(eq(playerRating.userId, u.id));
// Upsert: insert if no rating row exists, update if it does
const existing = await db.query.playerRating.findFirst({
where: eq(playerRating.userId, u.id)
});
if (existing) {
await db
.update(playerRating)
.set({ elo, initialElo: elo, osuRankAtSeed: rank, wins: 0, losses: 0, updatedAt: new Date() })
.where(eq(playerRating.userId, u.id));
} else {
await db.insert(playerRating).values({
userId: u.id,
elo,
initialElo: elo,
osuRankAtSeed: rank,
wins: 0,
losses: 0
});
}
console.log(`[Admin] Reset ${u.name}: rank #${rank ?? 'unranked'} → ${elo} ELO`);
updated++;