Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miili committed Oct 29, 2023
1 parent 85a75b9 commit 820a9bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
31 changes: 18 additions & 13 deletions lassie/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@
FastMarchingTracer,
RayTracers,
)
from lassie.utils import PhaseDescription, alog_call, datetime_now, time_to_path
from lassie.utils import (
PhaseDescription,
alog_call,
datetime_now,
human_readable_bytes,
time_to_path,
)
from lassie.waveforms import PyrockoSquirrel, WaveformProviderType

if TYPE_CHECKING:
Expand Down Expand Up @@ -99,7 +105,7 @@ class Search(BaseModel):

# Signals
_new_detection: Signal[EventDetection] = PrivateAttr(Signal())
_batch_ptime: Deque[timedelta] = PrivateAttr(
_batch_proc_time: Deque[timedelta] = PrivateAttr(
default_factory=lambda: deque(maxlen=25)
)
_batch_cum_durations: Deque[timedelta] = PrivateAttr(
Expand Down Expand Up @@ -269,17 +275,20 @@ async def start(self, force_rundir: bool = False) -> None:
self._detections.dump_detections(jitter_location=self.octree.size_limit)

processing_time = datetime_now() - batch_processing_start
self._batch_ptime.append(processing_time)
self._batch_proc_time.append(processing_time)
self._batch_cum_durations.append(batch.cumulative_duration)

processed_percent = (
((batch.i_batch + 1) / batch.n_batches) * 100
if batch.n_batches
else 0.0
)
processing_rate = (
sum(self._batch_cum_durations, timedelta())
/ sum(self._batch_ptime, timedelta()).total_seconds()
# processing_rate = (
# sum(self._batch_cum_durations, timedelta())
# / sum(self._batch_proc_time, timedelta()).total_seconds()
# )
processing_rate_bytes = human_readable_bytes(
batch.cumulative_bytes / processing_time.total_seconds()
)

logger.info(
Expand All @@ -289,17 +298,13 @@ async def start(self, force_rundir: bool = False) -> None:
processing_time,
)
if batch.n_batches:
remaining_time = timedelta(
seconds=float(
np.median(
[t_batch.total_seconds() for t_batch in self._batch_ptime]
)
)
remaining_time = sum(self._batch_proc_time, timedelta()) / len(
self._batch_proc_time
)
remaining_time *= batch.n_batches - batch.i_batch - 1
logger.info(
"processing rate %s/s - %s remaining - estimated finish at %s",
processing_rate,
processing_rate_bytes,
remaining_time,
datetime.now() + remaining_time, # noqa: DTZ005
)
Expand Down
4 changes: 4 additions & 0 deletions lassie/waveforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def cumulative_duration(self) -> timedelta:
seconds += tr.tmax - tr.tmin
return timedelta(seconds=seconds)

@property
def cumulative_bytes(self) -> int:
return sum(tr.ydata.nbytes for tr in self.traces)

def is_empty(self) -> bool:
"""Check if the batch is empty.
Expand Down

0 comments on commit 820a9bc

Please sign in to comment.