forked from Hanabi/hanabi-league
Initialize base ratings for variants
This commit is contained in:
parent
1e7c6ebcf7
commit
78a43d7d24
3 changed files with 28 additions and 5 deletions
22
database.py
22
database.py
|
@ -2,6 +2,7 @@ import json
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
|
import psycopg2.extras
|
||||||
import psycopg2.errors
|
import psycopg2.errors
|
||||||
import requests
|
import requests
|
||||||
import unidecode
|
import unidecode
|
||||||
|
@ -98,6 +99,27 @@ def fetch_and_initialize_variants():
|
||||||
conn_manager.get_connection().commit()
|
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:
|
def normalize_username(username: str) -> str:
|
||||||
decoded = unidecode.unidecode(username)
|
decoded = unidecode.unidecode(username)
|
||||||
return decoded.lower()
|
return decoded.lower()
|
||||||
|
|
|
@ -4,19 +4,19 @@ variant_base_ratings:
|
||||||
No Variant:
|
No Variant:
|
||||||
3p: 1500
|
3p: 1500
|
||||||
4p: 1500
|
4p: 1500
|
||||||
5p: 1500
|
5p: 1600
|
||||||
6 Suits:
|
6 Suits:
|
||||||
3p: 1500
|
3p: 1500
|
||||||
4p: 1500
|
4p: 1500
|
||||||
5p: 1500
|
5p: 1600
|
||||||
Clue Starved:
|
Clue Starved (5 Suits):
|
||||||
3p: 1500
|
3p: 1500
|
||||||
4p: 1500
|
4p: 1500
|
||||||
6p: 1700
|
5p: 1700
|
||||||
Clue Starved (6 Suits):
|
Clue Starved (6 Suits):
|
||||||
3p: 1500
|
3p: 1500
|
||||||
4p: 1500
|
4p: 1500
|
||||||
6p: 1700
|
5p: 1700
|
||||||
min_player_count: 3
|
min_player_count: 3
|
||||||
max_player_count: 5
|
max_player_count: 5
|
||||||
min_suits: 5
|
min_suits: 5
|
||||||
|
|
1
main.py
1
main.py
|
@ -31,6 +31,7 @@ def subcommand_init(force: bool, fetch_variants: bool):
|
||||||
logger.info("Successfully initialized database tables")
|
logger.info("Successfully initialized database tables")
|
||||||
if fetch_variants:
|
if fetch_variants:
|
||||||
database.fetch_and_initialize_variants()
|
database.fetch_and_initialize_variants()
|
||||||
|
database.initialize_variant_base_ratings()
|
||||||
|
|
||||||
|
|
||||||
def subcommand_generate_config():
|
def subcommand_generate_config():
|
||||||
|
|
Loading…
Reference in a new issue