Initialize base ratings for variants

This commit is contained in:
Maximilian Keßler 2023-11-23 01:18:26 +01:00
parent 1e7c6ebcf7
commit 78a43d7d24
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 28 additions and 5 deletions

View file

@ -2,6 +2,7 @@ import json
import psycopg2
import psycopg2.extensions
import psycopg2.extras
import psycopg2.errors
import requests
import unidecode
@ -98,6 +99,27 @@ def fetch_and_initialize_variants():
conn_manager.get_connection().commit()
def initialize_variant_base_ratings():
config = config_manager.get_config()
conn = conn_manager.get_connection()
cur = conn.cursor()
cur.execute("SELECT id, name from variants")
ratings = []
for variant_id, variant_name in cur.fetchall():
for num_players in range(config.min_player_count, config.max_player_count + 1):
rating = config.variant_base_rating(variant_name, num_players)
ratings.append((variant_id, num_players, rating))
psycopg2.extras.execute_values(
cur,
"INSERT INTO variant_base_ratings (variant_id, player_count, rating)"
"VALUES %s "
"ON CONFLICT (variant_id, player_count) "
"DO UPDATE SET rating = EXCLUDED.rating",
ratings
)
conn.commit()
def normalize_username(username: str) -> str:
decoded = unidecode.unidecode(username)
return decoded.lower()

View file

@ -4,19 +4,19 @@ variant_base_ratings:
No Variant:
3p: 1500
4p: 1500
5p: 1500
5p: 1600
6 Suits:
3p: 1500
4p: 1500
5p: 1500
Clue Starved:
5p: 1600
Clue Starved (5 Suits):
3p: 1500
4p: 1500
6p: 1700
5p: 1700
Clue Starved (6 Suits):
3p: 1500
4p: 1500
6p: 1700
5p: 1700
min_player_count: 3
max_player_count: 5
min_suits: 5

View file

@ -31,6 +31,7 @@ def subcommand_init(force: bool, fetch_variants: bool):
logger.info("Successfully initialized database tables")
if fetch_variants:
database.fetch_and_initialize_variants()
database.initialize_variant_base_ratings()
def subcommand_generate_config():