1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- // Checkout commit de1fdc341b09addeabd719e7a058e3ad449398bc and run on old ranks.db backup
- import databases from '../database.js';
- const RANK_DIVISIONS = [
- 'Cardboard',
- 'Wood',
- 'Wood+',
- 'Wood++',
- 'Bronze',
- 'Bronze+',
- 'Bronze++',
- 'Silver',
- 'Silver+',
- 'Silver++',
- 'Gold',
- 'Gold+',
- 'Gold++',
- 'Platinum',
- 'Platinum+',
- 'Platinum++',
- 'Diamond',
- 'Diamond+',
- 'Diamond++',
- 'Legendary',
- ];
- function get_rank_text(rank_float) {
- if (rank_float == null || typeof rank_float === 'undefined') {
- return 'Unranked';
- }
- if (rank_float == 1.0) {
- return 'The One';
- }
- // Epic rank distribution algorithm
- for (let i = 0; i < RANK_DIVISIONS.length; i++) {
- // Turn current 'Cardboard' rank into a value between 0 and 1
- const rank_nb = (i + 1) / RANK_DIVISIONS.length;
- // To make climbing ranks more satisfying, we make lower ranks more common.
- // Visual representation: https://graphtoy.com/?f1(x,t)=1-((cos(x%5E0.8*%F0%9D%9C%8B)/2)+0.5)&v1=true&f2(x,t)=&v2=true&f3(x,t)=&v3=false&f4(x,t)=&v4=false&f5(x,t)=&v5=false&f6(x,t)=&v6=false&grid=true&coords=0.3918011117299855,0.3722110561434862,1.0068654346588846
- const cutoff = 1 - ((Math.cos(Math.pow(rank_nb, 0.8) * Math.PI) / 2) + 0.5);
- if (rank_float < cutoff) {
- return RANK_DIVISIONS[i];
- }
- }
- // Ok, floating point errors, who cares
- return RANK_DIVISIONS[RANK_DIVISIONS.length - 1];
- }
- async function export_ranks() {
- const ranked_users = databases.ranks.prepare(`SELECT user_id, games_played FROM user WHERE games_played > 9 ORDER BY elo DESC`).all();
- const unranked_users = databases.ranks.prepare(`SELECT user_id, games_played FROM user WHERE games_played <= 9 ORDER BY elo DESC`).all();
- console.log('BEGIN TRANSACTION;');
- for (let i = 0; i < ranked_users.length; i++) {
- const division = get_rank_text(1.0 - i / ranked_users.length);
- console.log(`UPDATE rating SET s1_division = '${division}', s1_scores = ${ranked_users[i].games_played} WHERE user_id = ${ranked_users[i].user_id} AND mode = 0;`);
- }
- for (let i = 0; i < unranked_users.length; i++) {
- console.log(`UPDATE rating SET s1_scores = ${unranked_users[i].games_played} WHERE user_id = ${unranked_users[i].user_id} AND mode = 0;`);
- }
- console.log('COMMIT;');
- }
- export_ranks();
|