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

@@ -204,7 +204,7 @@ class Repository:
if not row:
return None
weights = self.conn.execute(
"""SELECT m.name, dmw.weight, dmw.norm_min, dmw.norm_max, dmw.metric_id
"""SELECT m.name, m.unit, dmw.weight, dmw.norm_min, dmw.norm_max, dmw.metric_id
FROM domain_metric_weights dmw
JOIN metrics m ON dmw.metric_id = m.id
WHERE dmw.domain_id = ?""",
@@ -218,7 +218,7 @@ class Repository:
MetricBound(
metric_name=w["name"], weight=w["weight"],
norm_min=w["norm_min"], norm_max=w["norm_max"],
metric_id=w["metric_id"],
metric_id=w["metric_id"], unit=w["unit"] or "",
)
for w in weights
],
@@ -411,26 +411,17 @@ class Repository:
def get_all_results(self, domain_name: str, status: str | None = None) -> list[dict]:
"""Return all results for a domain, optionally filtered by combo status."""
query = """SELECT cr.*, c.hash, c.status as combo_status, d.name as domain_name
FROM combination_results cr
JOIN combinations c ON cr.combination_id = c.id
JOIN domains d ON cr.domain_id = d.id
WHERE d.name = ?"""
params: list = [domain_name]
if status:
rows = self.conn.execute(
"""SELECT cr.*, c.hash, c.status as combo_status, d.name as domain_name
FROM combination_results cr
JOIN combinations c ON cr.combination_id = c.id
JOIN domains d ON cr.domain_id = d.id
WHERE d.name = ? AND c.status = ?
ORDER BY cr.composite_score DESC""",
(domain_name, status),
).fetchall()
else:
rows = self.conn.execute(
"""SELECT cr.*, c.hash, c.status as combo_status, d.name as domain_name
FROM combination_results cr
JOIN combinations c ON cr.combination_id = c.id
JOIN domains d ON cr.domain_id = d.id
WHERE d.name = ?
ORDER BY cr.composite_score DESC""",
(domain_name,),
).fetchall()
query += " AND c.status = ?"
params.append(status)
query += " ORDER BY cr.composite_score DESC"
rows = self.conn.execute(query, params).fetchall()
results = []
for r in rows:
combo = self.get_combination(r["combination_id"])