Revert "Add time stamps to games in tables"
This reverts commit 41e8fb9c85
.
This commit is contained in:
parent
66a08496d8
commit
181dd35ea6
5 changed files with 27 additions and 55 deletions
|
@ -133,8 +133,6 @@ CREATE TABLE games (
|
||||||
seed TEXT NOT NULL,
|
seed TEXT NOT NULL,
|
||||||
score SMALLINT NOT NULL,
|
score SMALLINT NOT NULL,
|
||||||
num_turns SMALLINT NOT NULL,
|
num_turns SMALLINT NOT NULL,
|
||||||
datetime_started TIMESTAMPTZ NOT NULL,
|
|
||||||
datetime_finished TIMESTAMPTZ NOT NULL,
|
|
||||||
/**
|
/**
|
||||||
* This is the league id mentioned above that will represent the ordering of games regarding being processed by ELO.
|
* This is the league id mentioned above that will represent the ordering of games regarding being processed by ELO.
|
||||||
* Note that this means when fetching new data from hanab.live, we have to fetch *all* of it and insert the games sorted
|
* Note that this means when fetching new data from hanab.live, we have to fetch *all* of it and insert the games sorted
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import json
|
import json
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
import platformdirs
|
import platformdirs
|
||||||
|
@ -29,18 +28,17 @@ session = requests_cache.CachedSession(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class GameInfo:
|
class GameInfo:
|
||||||
game_id: int
|
def __init__(self, game_id: int, num_players: int, variant_id: int, seed: str, score: int, num_turns: int,
|
||||||
num_players: int
|
user_ids: List[int], normalized_usernames: List[str]):
|
||||||
variant_id: int
|
self.game_id = game_id
|
||||||
seed: str
|
self.num_players = num_players
|
||||||
score: int
|
self.variant_id = variant_id
|
||||||
num_turns: int
|
self.seed = seed
|
||||||
user_ids: List[int]
|
self.score = score
|
||||||
normalized_usernames: List[str]
|
self.num_turns = num_turns
|
||||||
datetime_started: str
|
self.user_ids = user_ids
|
||||||
datetime_ended: str
|
self.normalized_usernames = normalized_usernames
|
||||||
|
|
||||||
|
|
||||||
def fetch_games_for_player(username: str, latest_game_id: int):
|
def fetch_games_for_player(username: str, latest_game_id: int):
|
||||||
|
@ -66,7 +64,6 @@ def process_game_entry(game_json: Dict, username_dict: Dict, variant_ids: List[i
|
||||||
score = game_json["score"]
|
score = game_json["score"]
|
||||||
num_turns = game_json["numTurns"]
|
num_turns = game_json["numTurns"]
|
||||||
start_time = game_json["datetimeStarted"]
|
start_time = game_json["datetimeStarted"]
|
||||||
end_time = game_json["datetimeFinished"]
|
|
||||||
|
|
||||||
game_options = game_json["options"]
|
game_options = game_json["options"]
|
||||||
var_id = game_options["variantID"]
|
var_id = game_options["variantID"]
|
||||||
|
@ -96,7 +93,7 @@ def process_game_entry(game_json: Dict, username_dict: Dict, variant_ids: List[i
|
||||||
return
|
return
|
||||||
user_ids.append(user_id)
|
user_ids.append(user_id)
|
||||||
|
|
||||||
return GameInfo(game_id, num_players, var_id, seed, score, num_turns, user_ids, normalized_usernames, start_time, end_time)
|
return GameInfo(game_id, num_players, var_id, seed, score, num_turns, user_ids, normalized_usernames)
|
||||||
|
|
||||||
|
|
||||||
def fetch_games_for_all_players():
|
def fetch_games_for_all_players():
|
||||||
|
@ -148,7 +145,7 @@ def store_new_games(games: Dict[int, GameInfo]):
|
||||||
|
|
||||||
# Now, iterate over all games and convert to tuples for insertion
|
# Now, iterate over all games and convert to tuples for insertion
|
||||||
for game in sorted(games.values(), key=lambda game_info: game_info.game_id):
|
for game in sorted(games.values(), key=lambda game_info: game_info.game_id):
|
||||||
tup = (game.game_id, game.num_players, game.variant_id, game.seed, game.score, game.num_turns, game.datetime_started, game.datetime_ended)
|
tup = (game.game_id, game.num_players, game.variant_id, game.seed, game.score, game.num_turns)
|
||||||
games_vals.append(tup)
|
games_vals.append(tup)
|
||||||
for player_id in game.user_ids:
|
for player_id in game.user_ids:
|
||||||
tup = (game.game_id, player_id)
|
tup = (game.game_id, player_id)
|
||||||
|
@ -163,7 +160,7 @@ def store_new_games(games: Dict[int, GameInfo]):
|
||||||
# (for example, because we forced a download refresh)
|
# (for example, because we forced a download refresh)
|
||||||
psycopg2.extras.execute_values(
|
psycopg2.extras.execute_values(
|
||||||
cur,
|
cur,
|
||||||
"INSERT INTO games (id, num_players, variant_id, seed, score, num_turns, datetime_started, datetime_finished) "
|
"INSERT INTO games (id, num_players, variant_id, seed, score, num_turns) "
|
||||||
"VALUES %s "
|
"VALUES %s "
|
||||||
"ON CONFLICT (id) DO NOTHING",
|
"ON CONFLICT (id) DO NOTHING",
|
||||||
games_vals
|
games_vals
|
||||||
|
@ -193,7 +190,6 @@ def store_new_games(games: Dict[int, GameInfo]):
|
||||||
def detailed_fetch_game(game_id: int) -> bool:
|
def detailed_fetch_game(game_id: int) -> bool:
|
||||||
"""
|
"""
|
||||||
Fetches full game details from the server and stores it in local DB if this game is a league game.
|
Fetches full game details from the server and stores it in local DB if this game is a league game.
|
||||||
@warning: Game data has to be present in database already, game details will then be added.
|
|
||||||
@param game_id: Game ID from hanab.live
|
@param game_id: Game ID from hanab.live
|
||||||
@return: Whether the processed game was accepted as a league game, i.e. inserted into the DB
|
@return: Whether the processed game was accepted as a league game, i.e. inserted into the DB
|
||||||
"""
|
"""
|
||||||
|
@ -246,8 +242,14 @@ def detailed_fetch_game(game_id: int) -> bool:
|
||||||
|
|
||||||
conn = conn_manager.get_connection()
|
conn = conn_manager.get_connection()
|
||||||
cur = conn_manager.get_new_cursor()
|
cur = conn_manager.get_new_cursor()
|
||||||
# Note that we assume the game is present in the database already
|
# Insert the game into the database if not present
|
||||||
|
cur.execute("INSERT INTO games "
|
||||||
|
"(id, num_players, variant_id, seed, score, num_turns) "
|
||||||
|
"VALUES "
|
||||||
|
"(%s, %s, %s, %s, %s, %s) "
|
||||||
|
"ON CONFLICT (id) DO NOTHING",
|
||||||
|
(game_id, num_players, var_id, seed, game.score, len(actions)))
|
||||||
|
# TODO Max: Check if len(actions) is the correct number here, in case there was a VTK action, we might want to subtract one
|
||||||
|
|
||||||
game_participants_vals = []
|
game_participants_vals = []
|
||||||
for seat, user_id in enumerate(user_ids):
|
for seat, user_id in enumerate(user_ids):
|
||||||
|
|
|
@ -7,9 +7,6 @@ import urllib.parse
|
||||||
import jinja2
|
import jinja2
|
||||||
import datetime
|
import datetime
|
||||||
import psycopg2.extras
|
import psycopg2.extras
|
||||||
import requests_cache
|
|
||||||
import platformdirs
|
|
||||||
|
|
||||||
import stats
|
import stats
|
||||||
|
|
||||||
import constants
|
import constants
|
||||||
|
@ -20,7 +17,6 @@ from dataclasses import dataclass
|
||||||
from database import conn_manager
|
from database import conn_manager
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PlayerEntry:
|
class PlayerEntry:
|
||||||
player_name: str
|
player_name: str
|
||||||
|
@ -114,7 +110,6 @@ class GameRow:
|
||||||
seed: str
|
seed: str
|
||||||
score: int
|
score: int
|
||||||
num_turns: int
|
num_turns: int
|
||||||
datetime_finished: datetime.datetime
|
|
||||||
league_id: int
|
league_id: int
|
||||||
num_bdrs: int
|
num_bdrs: int
|
||||||
num_crits_lost: int
|
num_crits_lost: int
|
||||||
|
@ -178,7 +173,6 @@ def get_games() -> List[GameRow]:
|
||||||
" seed,"
|
" seed,"
|
||||||
" score,"
|
" score,"
|
||||||
" num_turns,"
|
" num_turns,"
|
||||||
" datetime_finished,"
|
|
||||||
" game_data.league_id,"
|
" game_data.league_id,"
|
||||||
" num_bottom_deck_risks AS num_bdrs,"
|
" num_bottom_deck_risks AS num_bdrs,"
|
||||||
" num_crits_lost,"
|
" num_crits_lost,"
|
||||||
|
@ -198,7 +192,6 @@ def get_games() -> List[GameRow]:
|
||||||
" seed,"
|
" seed,"
|
||||||
" score,"
|
" score,"
|
||||||
" num_turns,"
|
" num_turns,"
|
||||||
" datetime_finished,"
|
|
||||||
" games.league_id,"
|
" games.league_id,"
|
||||||
" num_bottom_deck_risks,"
|
" num_bottom_deck_risks,"
|
||||||
" num_crits_lost "
|
" num_crits_lost "
|
||||||
|
@ -224,7 +217,7 @@ def get_games() -> List[GameRow]:
|
||||||
" ON variant_ratings.league_id = game_data.league_id AND variant_ratings.primary_change = true "
|
" ON variant_ratings.league_id = game_data.league_id AND variant_ratings.primary_change = true "
|
||||||
"GROUP BY ("
|
"GROUP BY ("
|
||||||
" game_data.game_id, game_data.num_players, users, user_ids, game_data.variant_id, variants.name, seed, score, num_turns,"
|
" game_data.game_id, game_data.num_players, users, user_ids, game_data.variant_id, variants.name, seed, score, num_turns,"
|
||||||
" game_data.league_id, num_bottom_deck_risks, num_crits_lost, change, value_after, rating_type, user_rating_changes, user_ratings_after, datetime_finished"
|
" game_data.league_id, num_bottom_deck_risks, num_crits_lost, change, value_after, rating_type, user_rating_changes, user_ratings_after"
|
||||||
" ) "
|
" ) "
|
||||||
"ORDER BY league_id DESC",
|
"ORDER BY league_id DESC",
|
||||||
(True,)
|
(True,)
|
||||||
|
@ -232,13 +225,11 @@ def get_games() -> List[GameRow]:
|
||||||
res = []
|
res = []
|
||||||
for row in cur.fetchall():
|
for row in cur.fetchall():
|
||||||
row['game_outcomes'] = [stats.GameOutcome(outcome).string for outcome in row['game_outcomes']]
|
row['game_outcomes'] = [stats.GameOutcome(outcome).string for outcome in row['game_outcomes']]
|
||||||
game_row = GameRow(**row)
|
if row['variant_rating_change'] is not None:
|
||||||
if game_row.variant_rating_change is not None:
|
row['variant_rating_change'] = round(row['variant_rating_change'], 2)
|
||||||
game_row.variant_rating_change = round(game_row.variant_rating_change, 2)
|
if row['variant_rating_after'] is not None:
|
||||||
if game_row.variant_rating_after is not None:
|
row['variant_rating_after'] = round(row['variant_rating_after'], 2)
|
||||||
game_row.variant_rating_after = round(game_row.variant_rating_after, 2)
|
res.append(GameRow(**row))
|
||||||
game_row.datetime_finished = game_row.datetime_finished.astimezone(datetime.timezone.utc).isoformat()
|
|
||||||
res.append(game_row)
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@ -597,18 +588,6 @@ def render_main_site(env: jinja2.Environment, out_dir: Path):
|
||||||
shutil.copytree('deps/tabulator/dist/css', 'build/css', dirs_exist_ok=True)
|
shutil.copytree('deps/tabulator/dist/css', 'build/css', dirs_exist_ok=True)
|
||||||
shutil.copytree('deps/tabulator/dist/js', 'build/js', dirs_exist_ok=True)
|
shutil.copytree('deps/tabulator/dist/js', 'build/js', dirs_exist_ok=True)
|
||||||
|
|
||||||
session = requests_cache.CachedSession(
|
|
||||||
platformdirs.user_cache_dir(constants.APP_NAME) + '/luxon.cache',
|
|
||||||
urls_expire_after={
|
|
||||||
'*': requests_cache.NEVER_EXPIRE,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
response = session.get("https://moment.github.io/luxon/global/luxon.min.js")
|
|
||||||
if not response.status_code == 200:
|
|
||||||
raise ValueError("Failed to get luxon library.")
|
|
||||||
with open('build/js/luxon.min.js', 'w') as file:
|
|
||||||
file.write(response.text)
|
|
||||||
|
|
||||||
|
|
||||||
def render_variant_pages(env: jinja2.Environment, out_dir: Path):
|
def render_variant_pages(env: jinja2.Environment, out_dir: Path):
|
||||||
variant_template = env.get_template('variant.html')
|
variant_template = env.get_template('variant.html')
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
<!-- Tabulator JS dependency -->
|
<!-- Tabulator JS dependency -->
|
||||||
<script type="text/javascript" src="/js/tabulator.min.js"></script>
|
<script type="text/javascript" src="/js/tabulator.min.js"></script>
|
||||||
<!-- Luxon JS dependency. Needed for some tabulator formatters. -->
|
|
||||||
<script type="text/javascript" src="/js/luxon.min.js"></script>
|
|
||||||
|
|
||||||
{% block navbar %}{% endblock %}
|
{% block navbar %}{% endblock %}
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|
|
@ -75,11 +75,6 @@ var table_{{div_id}} = new Tabulator("#table-{{div_id}}", {
|
||||||
urlPrefix: "https://hanab.live/replay/",
|
urlPrefix: "https://hanab.live/replay/",
|
||||||
target:"_blank"
|
target:"_blank"
|
||||||
}},
|
}},
|
||||||
{title: "Played", field: "datetime_finished", formatter: "datetime", formatterParams:{
|
|
||||||
inputFormat: "iso",
|
|
||||||
timezone: "system",
|
|
||||||
outputFormat: "dd/MM HH:mm"
|
|
||||||
}},
|
|
||||||
{% if show_player_num %}
|
{% if show_player_num %}
|
||||||
{title: "# Players", field: "num_players"},
|
{title: "# Players", field: "num_players"},
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue