Skip to main content

wellfare_core/anatomy/
coverage.rs

1//! Seeded **per-system coverage** — how complete the *Qualia* organ map is today.
2//!
3//! This is the authority for “which of the 17 systems have parts.” It is not a
4//! Python report. Overlay systems (ECS, ENS, glymphatic) are complete *as
5//! overlays* when they have hosts, not when they have an organ file.
6
7use super::model::{
8    SystemRepresentation, overlay_host_systems, primary_organ_system_pairs,
9    secondary_organ_system_pairs, system_representation,
10};
11use super::registry::{SystemTier, seed_tier};
12use super::systems::{BODY_SYSTEMS, BodySystem};
13
14/// One row of the seed coverage matrix.
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct SystemCoverage {
17    pub system: &'static BodySystem,
18    pub representation: SystemRepresentation,
19    pub tier: SystemTier,
20    /// Organs whose *primary* home is this system.
21    pub primary_parts: usize,
22    /// Organs that list this system as a secondary membership.
23    pub secondary_parts: usize,
24    pub overlay_host_count: usize,
25}
26
27impl SystemCoverage {
28    /// Discrete systems need at least one primary part to paint. Overlays need hosts
29    /// (empty hosts = whole-body cue, still valid for ECS).
30    pub fn seed_paint_ok(self) -> bool {
31        match self.representation {
32            SystemRepresentation::DiscreteOrgans => self.primary_parts > 0,
33            SystemRepresentation::DistributedOverlay => true,
34        }
35    }
36}
37
38/// Coverage of the 17 seeded systems against the curated organ map (not a pack on disk).
39pub fn seed_system_coverage() -> [SystemCoverage; 17] {
40    assert_eq!(BODY_SYSTEMS.len(), 17);
41    let mut out = [SystemCoverage {
42        system: &BODY_SYSTEMS[0],
43        representation: SystemRepresentation::DiscreteOrgans,
44        tier: SystemTier::CanonicalMajor,
45        primary_parts: 0,
46        secondary_parts: 0,
47        overlay_host_count: 0,
48    }; 17];
49    for (i, sys) in BODY_SYSTEMS.iter().enumerate() {
50        let primary_parts = primary_organ_system_pairs()
51            .iter()
52            .filter(|(_, s)| *s == sys.id)
53            .count();
54        let secondary_parts = secondary_organ_system_pairs()
55            .iter()
56            .filter(|(_, s)| *s == sys.id)
57            .count();
58        out[i] = SystemCoverage {
59            system: sys,
60            representation: system_representation(sys.id),
61            tier: seed_tier(sys.id),
62            primary_parts,
63            secondary_parts,
64            overlay_host_count: overlay_host_systems(sys.id).len(),
65        };
66    }
67    out
68}
69
70/// Markdown table for manuals / CLI (cold path).
71pub fn seed_system_coverage_markdown() -> String {
72    let mut s = String::from(
73        "| System | Paint | Seed parts (primary+secondary) | Improvement |\n\
74         |---|---|---|---|\n",
75    );
76    for row in seed_system_coverage() {
77        let paint = match row.representation {
78            SystemRepresentation::DiscreteOrgans => "organs",
79            SystemRepresentation::DistributedOverlay => {
80                if row.overlay_host_count == 0 {
81                    "overlay (whole body)"
82                } else {
83                    "overlay (hosts)"
84                }
85            }
86        };
87        let parts = format!("{}+{}", row.primary_parts, row.secondary_parts);
88        let note = if row.representation == SystemRepresentation::DistributedOverlay {
89            "highlight hosts — do not add a fake organ"
90        } else if row.primary_parts <= 2 {
91            "thin — needs SA/HRA parts"
92        } else {
93            "grow named parts + graph join"
94        };
95        s.push_str(&format!(
96            "| {} (`{}`) | {paint} | {parts} | {note} |\n",
97            row.system.label, row.system.id
98        ));
99    }
100    s
101}
102
103#[cfg(test)]
104mod tests {
105    use super::*;
106
107    #[test]
108    fn seventeen_systems_and_overlays_do_not_need_organs() {
109        let rows = seed_system_coverage();
110        assert_eq!(rows.len(), 17);
111        for row in rows {
112            assert!(row.seed_paint_ok(), "{}", row.system.id);
113            if row.system.id == "ecs" || row.system.id == "ens" || row.system.id == "glymphatic" {
114                assert_eq!(row.representation, SystemRepresentation::DistributedOverlay);
115                assert_eq!(row.primary_parts, 0);
116            }
117        }
118    }
119
120    #[test]
121    fn listed_majors_have_at_least_one_primary_part() {
122        for id in [
123            "circulatory",
124            "respiratory",
125            "digestive",
126            "nervous",
127            "skeletal",
128            "muscular",
129            "endocrine",
130            "immune_lymphatic",
131            "integumentary",
132            "urinary",
133            "reproductive",
134            "sensory",
135            "vestibular",
136            "exocrine",
137        ] {
138            let row = seed_system_coverage()
139                .into_iter()
140                .find(|r| r.system.id == id)
141                .unwrap();
142            assert!(row.primary_parts > 0, "{id} has no primary part");
143        }
144    }
145}