babylon.engine.systems.territory_diagnostics
Hex-county-state diagnostics for TerritorySystem (Spec 062 T053).
Constitution II.6: state is data, engine is transformation. Aggregation is a read operation on the graph — never a write — so this module provides pure functions that compute county/state/national rollups for diagnostic display. Primary state remains hex-level (FR-018).
These helpers are the in-memory complement to the Postgres v_*_aggregate views. The view is authoritative; this module covers the case where the engine wants to report per-county production rates inside the same tick, before the envelope commits to Postgres.
See also
babylon.persistence.postgres_aggregation: persisted variant.
Functions
|
Aggregate county rollups into state-level rollups. |
|
Compute per-county totals from in-memory hex nodes. |
Classes
|
Per-county aggregation of hex-level c/v/s/k + substrate stocks. |
- class babylon.engine.systems.territory_diagnostics.HexCountyRollup(county_fips, c_sum, v_sum, s_sum, k_sum, biocapacity_sum, hex_count)[source]
Bases:
objectPer-county aggregation of hex-level c/v/s/k + substrate stocks.
- Parameters:
- babylon.engine.systems.territory_diagnostics.aggregate_hexes_by_county(graph)[source]
Compute per-county totals from in-memory hex nodes.
Only nodes with
_node_type == "hex"AND acounty_fipsattribute are counted. Other node types (external, county, state) are skipped.- Parameters:
graph (
GraphProtocol) – World graph with hex nodes carrying c/v/s/k.- Return type:
- Returns:
{county_fips: HexCountyRollup}map. Empty when no hex nodes carry county_fips attributes (e.g., a fresh empty graph).
- babylon.engine.systems.territory_diagnostics.aggregate_counties_by_state(county_rollups, county_to_state=None)[source]
Aggregate county rollups into state-level rollups.
- Parameters:
- Return type:
- Returns:
{state_fips: HexCountyRollup}wherecounty_fipsfield carries the 2-digit state FIPS (the model is reused; the field is polymorphic for diagnostic display).