Skip to content

Commit

Permalink
fix old bugs: 4 minute offset and total star2 time
Browse files Browse the repository at this point in the history
previously, total star2 time was actually the total time,
and total time was double counting.
  • Loading branch information
katrinafyi committed Dec 1, 2024
1 parent 91b7d26 commit 1fd826d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions uqcsbot/utils/advent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1fd826d

Please sign in to comment.