From 50f65abcedb97bf4b70f204a07731808e6915eec Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Tue, 3 Dec 2024 04:27:35 -0800 Subject: [PATCH] Make the info panel show the correct last alerting Before, it was checking against the moved pointer, which could cause inaccurate --- token_bot/history_manager/update_trigger.py | 6 ++++++ token_bot/tracker.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/token_bot/history_manager/update_trigger.py b/token_bot/history_manager/update_trigger.py index cff4c9f..94058e5 100644 --- a/token_bot/history_manager/update_trigger.py +++ b/token_bot/history_manager/update_trigger.py @@ -10,6 +10,7 @@ class UpdateTrigger: def __init__(self, alert: Alert): self._alert : Alert = alert self._last_trigger : Tuple[datetime.datetime, int] | None = None + self._last_alerting: Tuple[datetime.datetime, int] | None = None self._squelched : bool = False @property @@ -20,6 +21,9 @@ class UpdateTrigger: def last_trigger(self) -> Tuple[datetime.datetime, int] | None: return self._last_trigger + def last_alerting(self) -> Tuple[datetime.datetime, int] | None: + return self._last_alerting + 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: @@ -78,6 +82,7 @@ class UpdateTrigger: if new_datum[0] > now - time_range: if self._last_trigger is None: self._last_trigger = new_datum + self._last_alerting = new_datum return True # If the self._last_trigger falls out of scope of the alert, find the next thing that would have triggered @@ -88,6 +93,7 @@ class UpdateTrigger: if comparison_operator(new_datum[1], self._last_trigger[1]): self._last_trigger = new_datum + self._last_alerting = new_datum was_squelched = self._squelched self._squelched = True return not was_squelched diff --git a/token_bot/tracker.py b/token_bot/tracker.py index 1c8230b..73da91d 100644 --- a/token_bot/tracker.py +++ b/token_bot/tracker.py @@ -289,8 +289,8 @@ class Tracker(Extension): history = await self._history_manager.get_history(alert.flavor, alert.region) trigger = await history.find_update_trigger_from_alert(alert) if trigger.last_trigger is not None: - alert_str = (f"Last Alerting Price Value: {format(trigger.last_trigger[1], ",")}\n" - f"Last Alerting Time: {trigger.last_trigger[0].strftime('%Y-%m-%d %H:%M:%S UTC')}\n") + alert_str = (f"Last Alerting Price Value: {format(trigger.last_alerting()[1], ",")}\n" + f"Last Alerting Time: {trigger.last_alerting()[0].strftime('%Y-%m-%d %H:%M:%S UTC')}\n") else: alert_str = "You should only be seeing this if the bot has not finished importing history at startup." fields.append(