Correctly determine ATH and ATL based on start date for each history

This commit is contained in:
Emily Doherty 2024-12-03 04:12:48 -08:00
parent 130406786f
commit 96249bd608

View File

@ -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