Hopefully fix the issue with the last_trigger pointer being incorrectly set to a very old data point

This commit is contained in:
Emily Doherty 2024-12-07 15:18:25 -08:00
parent 5d084dbae5
commit 895e50bdd3

View File

@ -1,6 +1,6 @@
import datetime
import operator
from typing import Tuple, List
from typing import Tuple, List, Callable
from token_bot.persistant_database import Alert, AlertType
from token_bot.token_database.flavor import Flavor
@ -29,13 +29,12 @@ class UpdateTrigger:
def squelched(self):
return self._squelched
def _find_next_trigger(self, comparison_operator: operator, starting_point: datetime.datetime, history: List[Tuple[datetime.datetime, int]]):
def _find_next_trigger(self, comparison_operator: Callable, starting_point: datetime.datetime, history: List[Tuple[datetime.datetime, int]]):
candidate_datum : Tuple[datetime.datetime, int] | None = None
for datum in history:
if candidate_datum is None:
candidate_datum = datum
if (datum[0] > starting_point and datum != history[-1]) and comparison_operator(datum[1], candidate_datum[1]):
candidate_datum = datum
if datum[0] > starting_point and datum != history[-1]:
if candidate_datum is None or comparison_operator(datum[1], candidate_datum[1]):
candidate_datum = datum
self._last_trigger = candidate_datum
def check_and_update(self, new_datum: Tuple[datetime.datetime, int], history: List[Tuple[datetime.datetime, int]]) -> bool: