fix(simulation): resolve corp_presence location granularity bug (#805)
import_corp_presence() was inserting system IDs with location_type='system', violating the schema which expects body/station IDs (location_type='body'|'station'). Fix: - import_economics.py: add _resolve_hq_location() that picks the most-populated body in the HQ system (falling back to any body, then any station) - econ-sim/db.rs: load_corp_presences() now JOINs bodies/stations to recover system_id from body/station location_ids, dropping the 'system' filter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -282,12 +282,18 @@ fn load_gate_links(conn: &Connection) -> Vec<GateLink> {
|
||||
}
|
||||
|
||||
fn load_corp_presences(conn: &Connection) -> Vec<CorpPresence> {
|
||||
// Resolve body/station location_id back to system_id via LEFT JOINs.
|
||||
// corp_presence.location_type is 'body' | 'station' per schema.
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT corp_id, location_id, primary_operation
|
||||
FROM corp_presence
|
||||
WHERE location_type = 'system'
|
||||
ORDER BY location_id, corp_id",
|
||||
"SELECT cp.corp_id,
|
||||
COALESCE(b.system_id, s.system_id) AS system_id,
|
||||
cp.primary_operation
|
||||
FROM corp_presence cp
|
||||
LEFT JOIN bodies b ON cp.location_type = 'body' AND cp.location_id = b.body_id
|
||||
LEFT JOIN stations s ON cp.location_type = 'station' AND cp.location_id = s.station_id
|
||||
WHERE COALESCE(b.system_id, s.system_id) IS NOT NULL
|
||||
ORDER BY system_id, cp.corp_id",
|
||||
)
|
||||
.expect("prepare corp_presence");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user