Skip to content

Commit

Permalink
finishing rich
Browse files Browse the repository at this point in the history
  • Loading branch information
miili committed Nov 12, 2023
1 parent 007e5f4 commit 6f489b0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lassie/images/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions lassie/models/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lassie/models/semblance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
9 changes: 6 additions & 3 deletions lassie/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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
)


Expand Down
7 changes: 5 additions & 2 deletions lassie/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions lassie/waveforms/squirrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
)

Expand Down

0 comments on commit 6f489b0

Please sign in to comment.