Skip to content

Commit

Permalink
Only send analysis time updates every second
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren authored and sondreso committed Oct 24, 2024
1 parent e47bc09 commit 50f9efe
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ def noop_progress_callback(_: AnalysisEvent) -> None:


class TimedIterator(Generic[T]):
SEND_FREQUENCY = 1.0 # seconds

def __init__(
self, iterable: Sequence[T], callback: Callable[[AnalysisEvent], None]
) -> None:
self._start_time = time.perf_counter()
self._iterable = iterable
self._callback = callback
self._index = 0
self._last_send_time = 0.0

def __iter__(self) -> Self:
return self
Expand All @@ -88,11 +91,14 @@ def __next__(self) -> T:
estimated_remaining_time = (elapsed_time / (self._index)) * (
len(self._iterable) - self._index
)
self._callback(
AnalysisTimeEvent(
remaining_time=estimated_remaining_time, elapsed_time=elapsed_time
if elapsed_time - self._last_send_time > self.SEND_FREQUENCY:
self._callback(
AnalysisTimeEvent(
remaining_time=estimated_remaining_time,
elapsed_time=elapsed_time,
)
)
)
self._last_send_time = elapsed_time

self._index += 1
return result
Expand Down

0 comments on commit 50f9efe

Please sign in to comment.