62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""Compact metrics panel for overview pane right side.
|
|
Run: watch -n10 python3 bin/metrics.py
|
|
"""
|
|
import os
|
|
import sys
|
|
from datetime import datetime, timezone
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from log_append import read_entries
|
|
|
|
from rich.console import Console
|
|
from rich.panel import Panel
|
|
from rich.text import Text
|
|
|
|
console = Console(width=38)
|
|
|
|
|
|
def summarize(entries: list) -> tuple:
|
|
today = datetime.now(timezone.utc).date().isoformat()
|
|
today_entries = [e for e in entries if (e.get('ts') or '').startswith(today)]
|
|
total = len(today_entries)
|
|
kept = sum(1 for e in today_entries if e.get('kept'))
|
|
projects: dict = {}
|
|
for e in today_entries:
|
|
p = e.get('project') or 'unknown'
|
|
projects.setdefault(p, {'total': 0, 'kept': 0})
|
|
projects[p]['total'] += 1
|
|
if e.get('kept'):
|
|
projects[p]['kept'] += 1
|
|
return total, kept, projects
|
|
|
|
|
|
def render() -> None:
|
|
entries = read_entries()
|
|
total, kept, projects = summarize(entries)
|
|
rate = f"{kept / total * 100:.0f}%" if total else "—"
|
|
|
|
text = Text()
|
|
text.append(f"Today: {total} experiments\n", style="bold")
|
|
text.append(f"Kept: {kept}", style="green bold")
|
|
text.append(f" ({rate})\n\n", style="dim")
|
|
|
|
if projects:
|
|
text.append("Per project:\n", style="bold dim")
|
|
for p, s in sorted(projects.items()):
|
|
r = f"{s['kept']}/{s['total']}"
|
|
bar = "█" * s['kept'] + "░" * (s['total'] - s['kept'])
|
|
text.append(f" {p[:14]:<14} {r:>5} {bar[:8]}\n")
|
|
else:
|
|
text.append("No experiments today.", style="dim italic")
|
|
|
|
console.print(Panel(
|
|
text,
|
|
title="[bold #DA251C]Metrics[/bold #DA251C]",
|
|
border_style="#FFD802",
|
|
expand=False,
|
|
))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
render()
|