From 1fd826d90ab9bfb285fdb83a51a28ccb271ecd04 Mon Sep 17 00:00:00 2001 From: rina Date: Sun, 1 Dec 2024 16:19:01 +1000 Subject: [PATCH] fix old bugs: 4 minute offset and total star2 time previously, total star2 time was actually the total time, and total time was double counting. --- uqcsbot/utils/advent_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uqcsbot/utils/advent_utils.py b/uqcsbot/utils/advent_utils.py index 0bb35e1..8df4a44 100644 --- a/uqcsbot/utils/advent_utils.py +++ b/uqcsbot/utils/advent_utils.py @@ -94,14 +94,17 @@ def from_member_data(cls, data: Json, year: int) -> "Member": day = int(d) times = member.times[day] - # timestamp of puzzle unlock, rounded to whole seconds - DAY_START = int(datetime(year, 12, day, tzinfo=EST_TIMEZONE).timestamp()) + # timestamp of puzzle unlock (12AM EST) + DAY_START = EST_TIMEZONE.localize(datetime(year, 12, day)) for s, star_data in day_data.items(): star = int(s) # assert is for type checking assert star == 1 or star == 2 - times[star] = int(star_data["get_star_ts"]) - DAY_START + ts = datetime.fromtimestamp( + float(star_data["get_star_ts"]), tz=EST_TIMEZONE + ) + times[star] = int((ts - DAY_START).total_seconds()) assert times[star] >= 0 return member @@ -133,7 +136,7 @@ def get_total_star2_time(self, default: int = 0) -> int: Returns the total time working on just star 2 for all challenges in a year. The argument default determines the returned value if the total is 0. """ - total = sum(self.times[day].get(2, 0) for day in ADVENT_DAYS) + total = sum(self.get_time_delta(day) or 0 for day in ADVENT_DAYS) return total if total != 0 else default def get_total_time(self, default: int = 0) -> int: