From 244bed2c51d561066e7fb0a30a58161d8b5241af Mon Sep 17 00:00:00 2001 From: Brad Brown Date: Mon, 27 Jun 2022 15:07:55 -0500 Subject: [PATCH] ensure historical tables show full length --- wordlinator/utils/__init__.py | 8 ++++++-- wordlinator/web/__init__.py | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/wordlinator/utils/__init__.py b/wordlinator/utils/__init__.py index 126e26c..00601d0 100644 --- a/wordlinator/utils/__init__.py +++ b/wordlinator/utils/__init__.py @@ -57,13 +57,17 @@ class WordleDay: # Designed so that "today" will be the current date in CST # Regardless of where the code is run -def get_wordle_today(): +def get_today_central(): today = ( datetime.datetime.now(datetime.timezone.utc) .astimezone(datetime.timezone(datetime.timedelta(hours=-5), name="US Central")) .date() ) - return WordleDay.from_date(today) + return today + + +def get_wordle_today(): + return WordleDay.from_date(get_today_central()) WORDLE_TODAY = get_wordle_today() diff --git a/wordlinator/web/__init__.py b/wordlinator/web/__init__.py index b5696e8..ce77806 100644 --- a/wordlinator/web/__init__.py +++ b/wordlinator/web/__init__.py @@ -65,6 +65,16 @@ def wordle_today(): return _wordle_today(get_ttl_hash()) +def round_wordle_day(round_id): + wt = wordle_today() + rounds = games_from_db() + + matching_round = [r for r in rounds if r.game_id == round_id][0] + if matching_round.game == wt.golf_hole.game_no: + return wt + return wordlinator.utils.WordleDay.from_date(matching_round.end_date) + + @functools.lru_cache(maxsize=3) def _scores_from_db(round_id, ttl_hash=None): wordle_db = db.WordleDb() @@ -106,11 +116,12 @@ def get_leaderboard(round_id): def get_scores(round_id): score_matrix = scores_from_db(round_id) - table_rows = score_matrix.user_rows(wordle_today()) + round_day = round_wordle_day(round_id) + table_rows = score_matrix.user_rows(round_day) hole_columns = [ {"name": f"{i}", "id": f"{i}", "type": "text", "presentation": "markdown"} - for i in range(1, wordle_today().golf_hole.hole_no + 1) + for i in range(1, round_day.golf_hole.hole_no + 1) ] columns = [ {"name": "Name", "id": "Name", "type": "text"}, @@ -191,7 +202,10 @@ def get_daily_stats(round_id): {"name": n, "id": n} for n in ( "Score", - *[f"{i}" for i in range(1, wordle_today().golf_hole.hole_no + 1)], + *[ + f"{i}" + for i in range(1, round_wordle_day(round_id).golf_hole.hole_no + 1) + ], ) ] return dash.dash_table.DataTable(