Summarize engine type lane families

This commit is contained in:
Jan Petykiewicz 2026-04-21 23:07:34 -07:00
commit 2d5f5dec10
3 changed files with 128 additions and 3 deletions

View file

@ -149,6 +149,7 @@ pub struct EngineTypesInspectionReport {
pub car_auxiliary_stem_relation_counts: BTreeMap<String, usize>,
pub lco_companion_stem_counts: BTreeMap<String, usize>,
pub lco_body_type_label_counts: BTreeMap<String, usize>,
pub lco_low_cardinality_lane_counts: BTreeMap<String, BTreeMap<String, usize>>,
pub cgo_scalar_value_counts: BTreeMap<String, usize>,
pub cgo_scalar_ladder_counts: BTreeMap<String, usize>,
pub cgo_scalar_values_by_content_stem: BTreeMap<String, Vec<String>>,
@ -373,6 +374,8 @@ pub fn inspect_engine_types_dir(
.iter()
.filter_map(|family| family.body_type_label.as_deref()),
);
let lco_low_cardinality_lane_counts =
build_lco_low_cardinality_lane_counts(lco_reports.values());
let cgo_scalar_value_counts = count_owned_values(
cgo_reports
.values()
@ -440,6 +443,7 @@ pub fn inspect_engine_types_dir(
car_auxiliary_stem_relation_counts,
lco_companion_stem_counts,
lco_body_type_label_counts,
lco_low_cardinality_lane_counts,
cgo_scalar_value_counts,
cgo_scalar_ladder_counts,
cgo_scalar_values_by_content_stem,
@ -747,6 +751,35 @@ fn build_cgo_scalar_ladder_counts<'a>(
count_owned_values(ladders.map(|ladder| ladder.join(" -> ")))
}
fn build_lco_low_cardinality_lane_counts<'a>(
reports: impl Iterator<Item = &'a EngineTypeLcoInspectionReport>,
) -> BTreeMap<String, BTreeMap<String, usize>> {
let mut per_offset = BTreeMap::<usize, BTreeMap<u32, usize>>::new();
for report in reports {
for lane in &report.early_lanes {
*per_offset
.entry(lane.offset)
.or_default()
.entry(lane.raw_u32)
.or_insert(0) += 1;
}
}
per_offset
.into_iter()
.filter(|(_, counts)| counts.len() <= 10)
.map(|(offset, counts)| {
(
format!("0x{offset:04x}"),
counts
.into_iter()
.map(|(raw_u32, count)| (format!("0x{raw_u32:08x}"), count))
.collect::<BTreeMap<_, _>>(),
)
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
@ -980,6 +1013,84 @@ mod tests {
assert_eq!(ladders.get("55.000000 -> 85.000000"), Some(&1));
}
#[test]
fn builds_lco_low_cardinality_lane_counts() {
let lane_counts = build_lco_low_cardinality_lane_counts(
[
EngineTypeLcoInspectionReport {
file_size: 0,
header_magic: None,
header_magic_hex: None,
internal_stem: None,
companion_stem: None,
body_type_label: None,
early_lanes: vec![
EngineTypeRawLane {
offset: 0x20,
offset_hex: "0x0020".to_string(),
raw_u32: 0,
raw_u32_hex: "0x00000000".to_string(),
raw_f32: 0.0,
},
EngineTypeRawLane {
offset: 0x24,
offset_hex: "0x0024".to_string(),
raw_u32: 1,
raw_u32_hex: "0x00000001".to_string(),
raw_f32: 0.0,
},
],
notes: Vec::new(),
},
EngineTypeLcoInspectionReport {
file_size: 0,
header_magic: None,
header_magic_hex: None,
internal_stem: None,
companion_stem: None,
body_type_label: None,
early_lanes: vec![
EngineTypeRawLane {
offset: 0x20,
offset_hex: "0x0020".to_string(),
raw_u32: 1,
raw_u32_hex: "0x00000001".to_string(),
raw_f32: 0.0,
},
EngineTypeRawLane {
offset: 0x24,
offset_hex: "0x0024".to_string(),
raw_u32: 2,
raw_u32_hex: "0x00000002".to_string(),
raw_f32: 0.0,
},
],
notes: Vec::new(),
},
]
.iter(),
);
assert_eq!(
lane_counts
.get("0x0020")
.and_then(|counts| counts.get("0x00000000")),
Some(&1)
);
assert_eq!(
lane_counts
.get("0x0020")
.and_then(|counts| counts.get("0x00000001")),
Some(&1)
);
assert_eq!(
lane_counts
.get("0x0024")
.and_then(|counts| counts.get("0x00000002")),
Some(&1)
);
}
#[test]
fn counts_owned_value_strings() {
let counts =