From 96249bd608ca489a9af2c315c0a4745ca0d3e794 Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Tue, 3 Dec 2024 04:12:48 -0800 Subject: [PATCH] Correctly determine ATH and ATL based on start date for each history --- token_bot/history_manager/update_trigger.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/token_bot/history_manager/update_trigger.py b/token_bot/history_manager/update_trigger.py index b7a46f5..cff4c9f 100644 --- a/token_bot/history_manager/update_trigger.py +++ b/token_bot/history_manager/update_trigger.py @@ -3,6 +3,7 @@ import operator from typing import Tuple, List from token_bot.persistant_database import Alert, AlertType +from token_bot.token_database.flavor import Flavor class UpdateTrigger: @@ -15,6 +16,10 @@ class UpdateTrigger: def alert(self) -> Alert: return self._alert + @property + def last_trigger(self) -> Tuple[datetime.datetime, int] | None: + return self._last_trigger + def _find_next_trigger(self, comparison_operator: operator, starting_point: datetime.datetime, history: List[Tuple[datetime.datetime, int]]): candidate_datum : Tuple[datetime.datetime, int] | None = None for datum in history: @@ -25,6 +30,14 @@ class UpdateTrigger: self._last_trigger = candidate_datum def check_and_update(self, new_datum: Tuple[datetime.datetime, int], history: List[Tuple[datetime.datetime, int]]) -> bool: + match self.alert.flavor: + case Flavor.RETAIL: + start_time = datetime.datetime.fromisoformat('2020-11-15 00:00:01.000000000+00:00') + case Flavor.CLASSIC: + start_time = datetime.datetime.fromisoformat('2023-05-23 00:00:01.000000000+00:00') + case _: + raise NotImplementedError + now = datetime.datetime.now(tz=datetime.timezone.utc) match self._alert.alert_type: case AlertType.DAILY_LOW: @@ -52,11 +65,10 @@ class UpdateTrigger: time_range = datetime.timedelta(days=365) comparison_operator = operator.gt case AlertType.ALL_TIME_LOW: - # TODO Make this calculate based on Flavor and current time the range back to look - time_range = datetime.timedelta(days=int(365.25 * 6)) + time_range = now - start_time comparison_operator = operator.lt case AlertType.ALL_TIME_HIGH: - time_range = datetime.timedelta(days=int(365.25 * 6)) + time_range = now - start_time comparison_operator = operator.gt case _: # TODO: The logic here is certainly wrong for Custom @@ -78,7 +90,7 @@ class UpdateTrigger: self._last_trigger = new_datum was_squelched = self._squelched self._squelched = True - return not was_squelched # Returns True if squelched otherwise True + return not was_squelched elif self._squelched: self._squelched = False return False \ No newline at end of file