|
@@ -9,6 +9,7 @@ import {get_division_from_elo, get_rankup_progress, update_the_one} from './elo_
|
|
|
const get_rating_stmt = db.prepare(`SELECT * FROM rating WHERE user_id = ? AND mode = ?`);
|
|
|
const update_rating_stmt = db.prepare(`
|
|
|
UPDATE rating SET
|
|
|
+ s3_scores = ?,
|
|
|
total_scores = ?,
|
|
|
elo = ?
|
|
|
WHERE user_id = ? AND mode = ?`,
|
|
@@ -21,13 +22,13 @@ const insert_score_stmt = db.prepare(`INSERT INTO score (
|
|
|
);
|
|
|
const better_users_stmt = db.prepare(`
|
|
|
SELECT COUNT(*) AS nb FROM rating r1, rating r2
|
|
|
- WHERE r1.total_scores >= ? AND r1.mode = ?
|
|
|
- AND r2.total_scores >= ? AND r2.mode = ?
|
|
|
+ WHERE r1.s3_scores >= ? AND r1.mode = ?
|
|
|
+ AND r2.s3_scores >= ? AND r2.mode = ?
|
|
|
AND r1.elo > r2.elo AND r2.user_id = ?`,
|
|
|
);
|
|
|
|
|
|
|
|
|
-const nb_active_users_stmt = db.prepare(`SELECT COUNT(*) AS nb FROM rating WHERE total_scores >= ? AND mode = ?`);
|
|
|
+const nb_active_users_stmt = db.prepare(`SELECT COUNT(*) AS nb FROM rating WHERE s3_scores >= ? AND mode = ?`);
|
|
|
const nb_active_users = [
|
|
|
nb_active_users_stmt.get(Config.games_needed_for_rank, 0).nb,
|
|
|
nb_active_users_stmt.get(Config.games_needed_for_rank, 1).nb,
|
|
@@ -105,11 +106,10 @@ async function save_game_and_update_rating(lobby, game) {
|
|
|
player.expected += 1 / (1 + Math.pow(10, (opponent.rating.elo - player.rating.elo) / 480));
|
|
|
}
|
|
|
|
|
|
- let k_factor = 40;
|
|
|
- if (player.rating.total_scores >= Config.games_needed_for_rank) k_factor = 32;
|
|
|
- if (player.rating.elo > 2400) k_factor = 16;
|
|
|
- else if (player.rating.elo > 2100) k_factor = 24;
|
|
|
- if (is_weekend) k_factor *= 1.5;
|
|
|
+ let k_factor = 32;
|
|
|
+ if (is_weekend || player.rating.s3_scores < Config.games_needed_for_rank) k_factor *= 1.25;
|
|
|
+ if (player.rating.elo > 2100) k_factor *= 0.75;
|
|
|
+ if (player.rating.elo > 2400) k_factor *= 0.75;
|
|
|
|
|
|
player.new_elo = player.rating.elo + k_factor * (player.actual - player.expected);
|
|
|
if (player.new_elo < 100) player.new_elo = 100;
|
|
@@ -127,15 +127,17 @@ async function save_game_and_update_rating(lobby, game) {
|
|
|
);
|
|
|
|
|
|
// score.rating is cached, so updating it here
|
|
|
+ if (bancho.connected) score.rating.s3_scores++;
|
|
|
score.rating.total_scores++;
|
|
|
score.rating.elo = score.new_elo;
|
|
|
|
|
|
// We also cache the total number of active users for each ruleset :)
|
|
|
- if (score.rating.total_scores == 10) {
|
|
|
+ if (score.rating.s3_scores == 10) {
|
|
|
nb_active_users[score.rating.mode]++;
|
|
|
}
|
|
|
|
|
|
update_rating_stmt.run(
|
|
|
+ score.rating.s3_scores,
|
|
|
score.rating.total_scores,
|
|
|
score.rating.elo,
|
|
|
score.rating.user_id,
|
|
@@ -174,7 +176,7 @@ async function save_game_and_update_rating(lobby, game) {
|
|
|
const rank_changes = [];
|
|
|
for (const score of game.scores) {
|
|
|
const player = await get_user_by_id(score.user_id);
|
|
|
- if (player.ratings[game.mode_int].total_scores < Config.games_needed_for_rank) continue;
|
|
|
+ if (player.ratings[game.mode_int].s3_scores < Config.games_needed_for_rank) continue;
|
|
|
|
|
|
const old_rank_text = player.ratings[game.mode_int].division;
|
|
|
const new_rank_text = get_division_from_elo(score.rating.elo, game.mode_int);
|
|
@@ -222,12 +224,13 @@ function get_user_rank(user_id, ruleset) {
|
|
|
Config.games_needed_for_rank, ruleset,
|
|
|
user_id,
|
|
|
);
|
|
|
- const is_ranked = rating.total_scores >= Config.games_needed_for_rank;
|
|
|
+ const is_ranked = rating.s3_scores >= Config.games_needed_for_rank;
|
|
|
|
|
|
const info = {
|
|
|
elo: '???',
|
|
|
rank_nb: '???',
|
|
|
text: 'Unranked',
|
|
|
+ s3_scores: rating.s3_scores,
|
|
|
total_scores: rating.total_scores,
|
|
|
is_ranked: is_ranked,
|
|
|
};
|