From 895e50bdd3f249e4f7f38b29939b72f5edfdccb6 Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Sat, 7 Dec 2024 15:18:25 -0800 Subject: [PATCH] Hopefully fix the issue with the last_trigger pointer being incorrectly set to a very old data point --- token_bot/history_manager/update_trigger.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/token_bot/history_manager/update_trigger.py b/token_bot/history_manager/update_trigger.py index 1a109dc..e6db9e4 100644 --- a/token_bot/history_manager/update_trigger.py +++ b/token_bot/history_manager/update_trigger.py @@ -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: