fix(data): star map bodies + population from systems.db, not wiki

Generator now queries bodies/stations tables directly for habitable
count, inhabited count, and total population. All 301 systems have
data — unsettled systems show "0 habitable · 0 inhabited" and "0".
Fixed stale worktree path to systems.db.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 12:11:39 +02:00
co-authored by Claude Opus 4.6
parent 3f611ae0f7
commit 9cdc86d65d
2 changed files with 627 additions and 17 deletions
File diff suppressed because it is too large Load Diff
+33 -5
View File
@@ -32,7 +32,7 @@ _PROJECT_ROOT = os.path.dirname(_SCRIPT_DIR)
_WORKTREE_PARENT = os.path.dirname(_PROJECT_ROOT)
STAR_MAP_PATH = os.path.join(_PROJECT_ROOT, "docs", "design", "star-map.json")
SYSTEMS_DB_PATH = os.path.join(_WORKTREE_PARENT, "server", "server", "data", "systems.db")
SYSTEMS_DB_PATH = os.path.join(_PROJECT_ROOT, "server", "data", "systems.db")
WIKI_PATH = os.path.join(_PROJECT_ROOT, "wiki", "star-systems")
OUTPUT_PATH = os.path.join(_PROJECT_ROOT, "client", "data", "star_map_data.json")
@@ -142,6 +142,26 @@ def generate() -> dict:
"FROM star_systems"
)
db_lookup = {row["system_id"]: dict(row) for row in cur.fetchall()}
# Aggregate body data per system from the bodies table
cur.execute("""
SELECT system_id,
SUM(CASE WHEN atmosphere IN ('breathable','standard') AND body_type IN ('planet','moon') THEN 1 ELSE 0 END) AS habitable,
SUM(CASE WHEN inhabited = 1 THEN 1 ELSE 0 END) AS inhabited,
SUM(CASE WHEN inhabited = 1 THEN COALESCE(population, 0) ELSE 0 END) AS total_pop
FROM bodies
GROUP BY system_id
""")
body_stats = {row["system_id"]: dict(row) for row in cur.fetchall()}
# Also sum station populations
cur.execute("""
SELECT system_id,
SUM(COALESCE(population, 0)) AS station_pop
FROM stations
GROUP BY system_id
""")
station_stats = {row["system_id"]: dict(row) for row in cur.fetchall()}
conn.close()
adjacency = build_adjacency(star_map["edges"])
@@ -172,10 +192,18 @@ def generate() -> dict:
}
if wiki["star_type"]:
entry["star_type"] = wiki["star_type"]
if wiki["bodies"]:
entry["bodies"] = wiki["bodies"]
if wiki["population"]:
entry["population"] = wiki["population"]
# Bodies + population from systems.db (authoritative, not wiki)
bs = body_stats.get(sid, {})
ss = station_stats.get(sid, {})
hab = int(bs.get("habitable", 0))
inh = int(bs.get("inhabited", 0))
body_pop = int(bs.get("total_pop", 0))
sta_pop = int(ss.get("station_pop", 0))
total_pop = body_pop + sta_pop
entry["bodies"] = "%d habitable · %d inhabited" % (hab, inh)
entry["population"] = "{:,}".format(total_pop)
if gttr:
entry["gttr_excerpt"] = gttr
if n.get("is_gateway"):