Compare building source assets to live bindings
This commit is contained in:
parent
c21a47d60f
commit
7a26063656
5 changed files with 307 additions and 14 deletions
|
|
@ -27,12 +27,23 @@ pub struct BuildingTypeSourceEntry {
|
|||
pub file_names: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BuildingTypeNamedBindingComparison {
|
||||
pub bindings_path: String,
|
||||
pub named_binding_count: usize,
|
||||
pub shared_canonical_stem_count: usize,
|
||||
pub binding_only_canonical_stems: Vec<String>,
|
||||
pub source_only_canonical_stems: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BuildingTypeSourceReport {
|
||||
pub directory_path: String,
|
||||
pub bca_file_count: usize,
|
||||
pub bty_file_count: usize,
|
||||
pub unique_canonical_stem_count: usize,
|
||||
#[serde(default)]
|
||||
pub named_binding_comparison: Option<BuildingTypeNamedBindingComparison>,
|
||||
pub notes: Vec<String>,
|
||||
pub files: Vec<BuildingTypeSourceFile>,
|
||||
pub entries: Vec<BuildingTypeSourceEntry>,
|
||||
|
|
@ -40,6 +51,13 @@ pub struct BuildingTypeSourceReport {
|
|||
|
||||
pub fn inspect_building_types_dir(
|
||||
path: &Path,
|
||||
) -> Result<BuildingTypeSourceReport, Box<dyn std::error::Error>> {
|
||||
inspect_building_types_dir_with_bindings(path, None)
|
||||
}
|
||||
|
||||
pub fn inspect_building_types_dir_with_bindings(
|
||||
path: &Path,
|
||||
bindings_path: Option<&Path>,
|
||||
) -> Result<BuildingTypeSourceReport, Box<dyn std::error::Error>> {
|
||||
let mut files = Vec::new();
|
||||
for entry in fs::read_dir(path)? {
|
||||
|
|
@ -129,20 +147,70 @@ pub fn inspect_building_types_dir(
|
|||
"This report is an offline asset-pool view only; it does not by itself assign live candidate ids or prove scenario candidate-table availability.".to_string(),
|
||||
];
|
||||
|
||||
let named_binding_comparison = if let Some(bindings_path) = bindings_path {
|
||||
Some(load_named_binding_comparison(bindings_path, &entries)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(BuildingTypeSourceReport {
|
||||
directory_path: path.display().to_string(),
|
||||
bca_file_count,
|
||||
bty_file_count,
|
||||
unique_canonical_stem_count: entries.len(),
|
||||
named_binding_comparison,
|
||||
notes,
|
||||
files,
|
||||
entries,
|
||||
})
|
||||
}
|
||||
|
||||
fn load_named_binding_comparison(
|
||||
bindings_path: &Path,
|
||||
entries: &[BuildingTypeSourceEntry],
|
||||
) -> Result<BuildingTypeNamedBindingComparison, Box<dyn std::error::Error>> {
|
||||
let artifact =
|
||||
serde_json::from_str::<BuildingBindingArtifact>(&fs::read_to_string(bindings_path)?)?;
|
||||
let named_binding_stems = artifact
|
||||
.bindings
|
||||
.into_iter()
|
||||
.filter_map(|binding| binding.candidate_name)
|
||||
.map(|candidate_name| canonicalize_building_stem(&candidate_name))
|
||||
.collect::<BTreeSet<_>>();
|
||||
let source_stems = entries
|
||||
.iter()
|
||||
.map(|entry| entry.canonical_stem.clone())
|
||||
.collect::<BTreeSet<_>>();
|
||||
|
||||
Ok(BuildingTypeNamedBindingComparison {
|
||||
bindings_path: bindings_path.display().to_string(),
|
||||
named_binding_count: named_binding_stems.len(),
|
||||
shared_canonical_stem_count: named_binding_stems.intersection(&source_stems).count(),
|
||||
binding_only_canonical_stems: named_binding_stems
|
||||
.difference(&source_stems)
|
||||
.cloned()
|
||||
.collect(),
|
||||
source_only_canonical_stems: source_stems
|
||||
.difference(&named_binding_stems)
|
||||
.cloned()
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
||||
fn canonicalize_building_stem(stem: &str) -> String {
|
||||
stem.chars()
|
||||
.filter(|ch| !matches!(ch, ' ' | '_' | '-'))
|
||||
.flat_map(|ch| ch.to_lowercase())
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
struct BuildingBindingArtifact {
|
||||
bindings: Vec<BuildingBindingRow>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
struct BuildingBindingRow {
|
||||
#[serde(default)]
|
||||
candidate_name: Option<String>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ pub mod summary;
|
|||
pub mod win;
|
||||
|
||||
pub use building::{
|
||||
BuildingTypeSourceEntry, BuildingTypeSourceFile, BuildingTypeSourceKind,
|
||||
BuildingTypeSourceReport, inspect_building_types_dir,
|
||||
BuildingTypeNamedBindingComparison, BuildingTypeSourceEntry, BuildingTypeSourceFile,
|
||||
BuildingTypeSourceKind, BuildingTypeSourceReport, inspect_building_types_dir,
|
||||
inspect_building_types_dir_with_bindings,
|
||||
};
|
||||
pub use calendar::{CalendarPoint, MONTH_SLOTS_PER_YEAR, PHASE_SLOTS_PER_MONTH, TICKS_PER_PHASE};
|
||||
pub use campaign_exe::{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue