From ef6b6ac20bf4c3ca213ab958513760b4f535672c Mon Sep 17 00:00:00 2001 From: Jon Holba Date: Tue, 11 Mar 2025 10:41:56 +0100 Subject: [PATCH] Set negative durations to 0 in simulation status Will also log warnings when encountering these issues. --- src/ert/gui/model/snapshot.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ert/gui/model/snapshot.py b/src/ert/gui/model/snapshot.py index 79466882eae..567bcb6223f 100644 --- a/src/ert/gui/model/snapshot.py +++ b/src/ert/gui/model/snapshot.py @@ -69,6 +69,8 @@ state.COLOR_NOT_ACTIVE: QColor(*state.COLOR_NOT_ACTIVE), } +_warn_once = True + def _estimate_duration( start_time: datetime, end_time: datetime | None = None @@ -429,6 +431,16 @@ def _fm_step_data( ) # There is no method for truncating microseconds, so we remove them delta -= timedelta(microseconds=delta.microseconds) + if delta < timedelta(): + global _warn_once # noqa: PLW0603 + if _warn_once: + _warn_once = False + logger.warning( + "Negative duration in snapshot encountered. " + f"start_time={start_time} end_time={node.data.get(ids.END_TIME)} " + f"delta={delta}" + ) + delta = timedelta() return str(delta) return node.data.get(data_name)