From 6f489b07f75575fd080b3f337a527b6296978006 Mon Sep 17 00:00:00 2001 From: miili Date: Sun, 12 Nov 2023 23:28:29 +0100 Subject: [PATCH] finishing rich --- lassie/images/__init__.py | 2 +- lassie/models/detection.py | 6 +++--- lassie/models/semblance.py | 2 ++ lassie/search.py | 9 ++++++--- lassie/stats.py | 7 +++++-- lassie/waveforms/squirrel.py | 6 +++--- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lassie/images/__init__.py b/lassie/images/__init__.py index 8df94cfa..89cc2f30 100644 --- a/lassie/images/__init__.py +++ b/lassie/images/__init__.py @@ -62,7 +62,7 @@ def queue_size_max(self) -> PositiveInt: return self._queue.maxsize def _populate_table(self, table: Table) -> None: - prefix = "[red][bold]" if not self.queue_size else "" + prefix = "[bold red]" if self.queue_size <= 2 else "" table.add_row("Queue", f"{prefix}{self.queue_size}/{self.queue_size_max}") table.add_row( "Waveform processing", diff --git a/lassie/models/detection.py b/lassie/models/detection.py index 1ed5da81..9c7e7289 100644 --- a/lassie/models/detection.py +++ b/lassie/models/detection.py @@ -454,7 +454,7 @@ def __str__(self) -> str: return str(self.time) -class DetectionStats(Stats): +class DetectionsStats(Stats): n_detections: int = 0 max_semblance: float = 0.0 @@ -465,14 +465,14 @@ def new_detection(self, detection: EventDetection): self.max_semblance = max(self.max_semblance, detection.semblance) def _populate_table(self, table: Table) -> None: - table.add_row("No. Detections", f"[bold]{self.n_detections}") + table.add_row("No. Detections", f"[bold]{self.n_detections} :dim_button:") table.add_row("Maximum semblance", f"{self.max_semblance:.4f}") class EventDetections(BaseModel): rundir: Path detections: list[EventDetection] = [] - _stats: DetectionStats = PrivateAttr(default_factory=DetectionStats) + _stats: DetectionsStats = PrivateAttr(default_factory=DetectionsStats) def model_post_init(self, __context: Any) -> None: EventDetection._rundir = self.rundir diff --git a/lassie/models/semblance.py b/lassie/models/semblance.py index 21cf3ac6..d84246c8 100644 --- a/lassie/models/semblance.py +++ b/lassie/models/semblance.py @@ -138,6 +138,8 @@ def apply_exponent(self, exponent: float) -> None: Args: exponent (float): Exponent """ + if exponent == 1.0: + return self.semblance_unpadded **= exponent self._clear_cache() diff --git a/lassie/search.py b/lassie/search.py index e522ce80..48d498ab 100644 --- a/lassie/search.py +++ b/lassie/search.py @@ -69,6 +69,7 @@ class SearchStats(Stats): batch_count: int = 0 batch_count_total: int = 0 processing_rate_bytes: float = 0.0 + processing_rate_time: timedelta = timedelta(seconds=0.0) _batch_processing_times: Deque[timedelta] = PrivateAttr( default_factory=lambda: deque(maxlen=25) @@ -109,6 +110,7 @@ def add_processed_batch( self.batch_time = batch.end_time self._batch_processing_times.append(duration) self.processing_rate_bytes = batch.cumulative_bytes / duration.total_seconds() + self.processing_rate_time = batch.duration / duration.total_seconds() if log: self.log() @@ -133,17 +135,18 @@ def _populate_table(self, table: Table) -> None: table.add_row( "Progress ", f"[bold]{self.processed_percent:.1f}%[/bold]" - f"([bold]{self.batch_count+1}[/bold]/{self.batch_count_total or '?'} / " + f" ([bold]{self.batch_count+1}[/bold]/{self.batch_count_total or '?'}, " f' {self.batch_time.strftime("%Y-%m-%d %H:%M:%S")})', ) table.add_row( "Processing rate", - f"{human_readable_bytes(self.processing_rate_bytes)}/s", + f"{human_readable_bytes(self.processing_rate_bytes)}/s" + f" ({self.processing_rate_time} t/s)", ) table.add_row( "Remaining Time", f"{self.time_remaining}, " - f"finish at {datetime.now() + self.time_remaining}", # noqa: DTZ005 + f"finish at {datetime.now() + self.time_remaining:%c}", # noqa: DTZ005 ) diff --git a/lassie/stats.py b/lassie/stats.py index ac6f14c2..07d2dfbc 100644 --- a/lassie/stats.py +++ b/lassie/stats.py @@ -42,7 +42,7 @@ def current(cls) -> Self: @classmethod async def live_view(cls) -> NoReturn: - def generate_table() -> Group: + def generate_table() -> Table: """Make a new table.""" table = Table(show_header=False, box=None) stats_instaces = sorted( @@ -55,7 +55,10 @@ def generate_table() -> Group: ) table.add_section() stats._populate_table(table) - return Group(PROGRESS, table) + grid = table.grid(expand=True) + grid.add_row(PROGRESS) + grid.add_row(Group(Panel(table))) + return grid with Live( generate_table(), diff --git a/lassie/waveforms/squirrel.py b/lassie/waveforms/squirrel.py index 0031e60e..f67b5f50 100644 --- a/lassie/waveforms/squirrel.py +++ b/lassie/waveforms/squirrel.py @@ -45,7 +45,7 @@ class SquirrelPrefetcher: def __init__( self, iterator: Iterator[Batch], - queue_size: int = 4, + queue_size: int = 5, highpass: float | None = None, lowpass: float | None = None, ) -> None: @@ -117,7 +117,7 @@ def queue_size_max(self) -> PositiveInt: return self._queue.maxsize def _populate_table(self, table: Table) -> None: - prefix = "[red][bold]" if not self.queue_size else "" + prefix = "[bold red]" if self.queue_size <= 1 else "" table.add_row("Queue", f"{prefix}{self.queue_size}/{self.queue_size_max}") table.add_row( "Waveform loading", @@ -165,7 +165,7 @@ class PyrockoSquirrel(WaveformProvider): "use e.g. `EN?` for selection of all accelerometer data.", ) async_prefetch_batches: PositiveInt = Field( - default=4, + default=5, description="Queue size for asynchronous pre-fetcher.", )