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