INNER CODE UNIT · Python
summarize_history
lij768423-svg/grok-register-panel · batch_traffic.py:170
def summarize_history(history: object, current: object | None = None) -> dict:
stored = history if isinstance(history, dict) else _empty_history()
entries = [
entry
for raw in (stored.get("batches") or [])
if (entry := _history_entry(raw)) is not None and entry["bytes_total"] > 0
]
archived_ids = {entry["batch_id"] for entry in entries}
includes_current = False
current_entry = _history_entry(current)
if (
current_entry is not None
and current_entry["bytes_total"] > 0
and current_entry["batch_id"] not in archived_ids
):
entries.append(current_entry)
includes_current = True
total_bytes = sum(entry["bytes_total"] for entry in entries)