Display metric units in web UI, make seed idempotent, simplify code

- Load m.unit in get_domain() so MetricBound carries units from DB
- Add Unit column to domains list template
- Make load_transport_seed() idempotent with IntegrityError handling
  and metric unit backfill for existing DBs
- Remove unused imports (json, sqlite3, Entity)
- Simplify combinator loop to list comprehension
- Merge duplicate conditional/valid branches in pipeline
- Consolidate duplicated SQL in get_all_results()
- Expand CLAUDE.md with fuller architecture docs and conventions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 16:18:50 -06:00
parent d2028a642b
commit f1b3c75190
9 changed files with 63 additions and 53 deletions

View File

@@ -265,22 +265,35 @@ INTERPLANETARY = Domain(
def load_transport_seed(repo) -> dict:
"""Load all transport seed data into the repository. Returns counts."""
"""Load all transport seed data into the repository. Idempotent — safe to re-run."""
import sqlite3
from physcom.db.repository import Repository
repo: Repository
counts = {"platforms": 0, "power_sources": 0, "domains": 0}
for entity in PLATFORMS:
repo.add_entity(entity)
counts["platforms"] += 1
try:
repo.add_entity(entity)
counts["platforms"] += 1
except sqlite3.IntegrityError:
pass
for entity in POWER_SOURCES:
repo.add_entity(entity)
counts["power_sources"] += 1
try:
repo.add_entity(entity)
counts["power_sources"] += 1
except sqlite3.IntegrityError:
pass
repo.add_domain(URBAN_COMMUTING)
repo.add_domain(INTERPLANETARY)
counts["domains"] = 2
for domain in (URBAN_COMMUTING, INTERPLANETARY):
try:
repo.add_domain(domain)
counts["domains"] += 1
except sqlite3.IntegrityError:
pass
# Backfill metric units on existing DBs (ensure_metric is idempotent).
for mb in domain.metric_bounds:
repo.ensure_metric(mb.metric_name, unit=mb.unit)
return counts