Expose general warning and untimed-note policies with validated exclusions
This commit is contained in:
parent
a143f677b2
commit
e42fdcd20f
|
|
@ -252,6 +252,27 @@ impl App {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn general_options(&mut self, ui: &mut egui::Ui) {
|
||||
let Ok(mut profile) = serde_json::from_str::<Profile>(&self.profile) else {
|
||||
ui.colored_label(
|
||||
Color32::YELLOW,
|
||||
"Fix the profile JSON to change general options.",
|
||||
);
|
||||
return;
|
||||
};
|
||||
let before = serde_json::to_string(&profile).unwrap();
|
||||
ui.strong("General options");
|
||||
ui.checkbox(&mut profile.ignore_warnings, "Ignore all warnings")
|
||||
.on_hover_text("Try ignoring rows with missing timing, missing titles or unresolved notes/breaks, then rebuild and validate. Column ambiguity and inconsistent timings still block export. Existing manual corrections are preserved.");
|
||||
ui.checkbox(&mut profile.untimed_as_notes, "Treat untimed rows as notes")
|
||||
.on_hover_text("Attach untimed rows to the preceding event. Applied before automatic warning exclusions, so notes are retained where possible.");
|
||||
ui.small("Applied on analysis / recheck. Export requires a consistent schedule.");
|
||||
if before != serde_json::to_string(&profile).unwrap() {
|
||||
self.profile = serde_json::to_string_pretty(&profile).unwrap();
|
||||
self.decisions_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn mapping_controls(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Remap columns, header and units / advanced profile");
|
||||
self.mapping_fields(ui);
|
||||
|
|
@ -341,16 +362,12 @@ impl App {
|
|||
}
|
||||
});
|
||||
profile.duration_unit = (!unit.is_empty()).then_some(unit);
|
||||
ui.checkbox(
|
||||
&mut profile.untimed_as_notes,
|
||||
"Treat untimed rows as notes on the preceding event",
|
||||
);
|
||||
if before != serde_json::to_string(&profile).unwrap() {
|
||||
self.profile = serde_json::to_string_pretty(&profile).unwrap();
|
||||
self.decisions_changed();
|
||||
}
|
||||
}
|
||||
ui.label("Optional JSON profile: columns (start/end/duration/title), column_usage (metadata/ignore), duration_unit, row_kinds, durations, untimed_as_notes. Column letters and source rows are shown in diagnostics.");
|
||||
ui.label("Optional JSON profile: columns (start/end/duration/title), column_usage (metadata/ignore), duration_unit, row_kinds, durations, untimed_as_notes, ignore_warnings. Column letters and source rows are shown in diagnostics.");
|
||||
if ui
|
||||
.add(
|
||||
egui::TextEdit::multiline(&mut self.profile)
|
||||
|
|
@ -542,6 +559,8 @@ impl App {
|
|||
}
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
self.general_options(ui);
|
||||
ui.add_space(12.0);
|
||||
ui.label("Save to");
|
||||
ui.add(egui::TextEdit::singleline(&mut self.output).desired_width(f32::INFINITY));
|
||||
ui.horizontal(|ui| {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ struct PreviewRow {
|
|||
duration: String,
|
||||
title: String,
|
||||
source_only: bool,
|
||||
automatically_ignored: bool,
|
||||
issues: Vec<usize>,
|
||||
decisions: String,
|
||||
kind: String,
|
||||
|
|
@ -107,6 +108,7 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
},
|
||||
title: e.title.clone(),
|
||||
source_only: false,
|
||||
automatically_ignored: false,
|
||||
issues: a
|
||||
.diagnostics
|
||||
.iter()
|
||||
|
|
@ -167,6 +169,7 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
duration: raw(a.mapping.as_ref().and_then(|m| m.duration)),
|
||||
title,
|
||||
source_only: true,
|
||||
automatically_ignored: false,
|
||||
issues: a
|
||||
.diagnostics
|
||||
.iter()
|
||||
|
|
@ -248,6 +251,7 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
"Allocated gap · included in adjacent timer".into()
|
||||
} else { gap.title.clone() },
|
||||
source_only: true,
|
||||
automatically_ignored: false,
|
||||
issues: a.diagnostics.iter().enumerate().filter(|(_, d)| d.location == format!("{} gap {:?}–{:?}", rundown.title, gap.after_row, gap.before_row)).map(|(i, _)| i).collect(),
|
||||
decisions: "Keep the interval untimed, extend the previous event to its end, or start the next event at its beginning. Recheck to apply the choice.".into(),
|
||||
kind: if rundown.resolved_gaps.iter().any(|g| g.key() == gap.key()) {
|
||||
|
|
@ -258,6 +262,13 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
});
|
||||
}
|
||||
}
|
||||
for row in &mut rows {
|
||||
if a.automatically_ignored_rows.contains(&row.row) {
|
||||
row.automatically_ignored = true;
|
||||
row.kind = "Ignored automatically".into();
|
||||
row.decisions = "Excluded by Ignore all warnings. Disable that option in Setup and recheck to restore this row.".into();
|
||||
}
|
||||
}
|
||||
rows
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +282,7 @@ fn ignored_row(row: usize, table: Option<&Table>, profile: &Profile) -> bool {
|
|||
fn show_row(row: &PreviewRow, filter: RowFilter, table: Option<&Table>, profile: &Profile) -> bool {
|
||||
match filter {
|
||||
RowFilter::All => true,
|
||||
RowFilter::Included => !ignored_row(row.row, table, profile),
|
||||
RowFilter::Included => !row.automatically_ignored && !ignored_row(row.row, table, profile),
|
||||
RowFilter::Attention => row.gap || !row.issues.is_empty(),
|
||||
}
|
||||
}
|
||||
|
|
@ -338,6 +349,10 @@ impl App {
|
|||
ui.colored_label(color, format!("{symbol} {label}"))
|
||||
.on_hover_text(format!("{status}\n{explanation}"));
|
||||
}
|
||||
if !a.automatically_ignored_rows.is_empty() {
|
||||
ui.small(format!("{} rows ignored automatically", a.automatically_ignored_rows.len()))
|
||||
.on_hover_text(format!("Source rows: {:?}. Review them under All rows; disable Ignore all warnings in Setup and recheck to restore them.", a.automatically_ignored_rows));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -894,7 +909,7 @@ impl App {
|
|||
let mut details = None;
|
||||
let backgrounds: Vec<_> = std::iter::once(None)
|
||||
.chain(rows.iter().map(|row| {
|
||||
if ignored_row(row.row, table, &profile) {
|
||||
if row.automatically_ignored || ignored_row(row.row, table, &profile) {
|
||||
Some(Color32::from_rgb(34, 35, 39))
|
||||
} else if row
|
||||
.issues
|
||||
|
|
@ -940,7 +955,7 @@ impl App {
|
|||
ui.end_row();
|
||||
for row in &rows {
|
||||
let row_top = ui.cursor().min;
|
||||
let ignored = ignored_row(row.row, table, &profile);
|
||||
let ignored = row.automatically_ignored || ignored_row(row.row, table, &profile);
|
||||
let error = row
|
||||
.issues
|
||||
.iter()
|
||||
|
|
@ -1359,6 +1374,63 @@ mod tests {
|
|||
assert_eq!(app.selected_row, Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_options_are_visible_and_automatic_exclusions_remain_reviewable() {
|
||||
let mut app = sample();
|
||||
app.tab = Tab::Setup;
|
||||
let ctx = egui::Context::default();
|
||||
configure_style(&ctx);
|
||||
let size = [560.0, 400.0];
|
||||
render(&mut app, &ctx, size, vec![]);
|
||||
let labels = render(&mut app, &ctx, size, vec![]);
|
||||
assert!(!app.settings);
|
||||
assert!(
|
||||
labels
|
||||
.iter()
|
||||
.any(|(s, _)| s == "Treat untimed rows as notes")
|
||||
);
|
||||
let button = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Ignore all warnings")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, button, size);
|
||||
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
|
||||
assert!(profile.ignore_warnings);
|
||||
assert!(app.dirty);
|
||||
let a = pipeline::analyze(&app.tables[0], &profile, &AtomicBool::new(false), |_, _| {});
|
||||
assert!(a.diagnostics.is_empty());
|
||||
assert_eq!(a.automatically_ignored_rows.len(), 12);
|
||||
let rows = preview_rows(&a, Some(&app.tables[0]));
|
||||
let row = rows.iter().find(|r| r.row == 3).unwrap();
|
||||
assert!(row.automatically_ignored);
|
||||
assert!(show_row(
|
||||
row,
|
||||
RowFilter::All,
|
||||
Some(&app.tables[0]),
|
||||
&profile
|
||||
));
|
||||
assert!(!show_row(
|
||||
row,
|
||||
RowFilter::Included,
|
||||
Some(&app.tables[0]),
|
||||
&profile
|
||||
));
|
||||
let labels = render(&mut app, &ctx, size, vec![]);
|
||||
let notes = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Treat untimed rows as notes")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, notes, size);
|
||||
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
|
||||
assert!(profile.untimed_as_notes);
|
||||
assert!(profile.ignore_warnings);
|
||||
assert!(profile.row_kinds.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spreadsheet_time_samples_are_readable_without_changing_source() {
|
||||
let cell = |text: &str, numeric| crate::model::Cell {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ pub struct Profile {
|
|||
pub duration_unit: Option<String>,
|
||||
/// Explicitly retain rows without times as notes on the preceding event.
|
||||
pub untimed_as_notes: bool,
|
||||
/// Try excluding rows with unresolved-content warnings, then validate again.
|
||||
pub ignore_warnings: bool,
|
||||
/// One-based source row -> event, gap, marker, note, or ignore.
|
||||
pub row_kinds: BTreeMap<usize, String>,
|
||||
/// Explicit duration overrides, expressed with units (e.g. 2 min).
|
||||
|
|
@ -152,6 +154,9 @@ pub struct Analysis {
|
|||
pub mapping: Option<Mapping>,
|
||||
pub rundown: Option<Rundown>,
|
||||
pub diagnostics: Vec<Diagnostic>,
|
||||
/// Derived exclusions; never persisted as manual row decisions.
|
||||
#[serde(default)]
|
||||
pub automatically_ignored_rows: Vec<usize>,
|
||||
}
|
||||
pub fn column_name(mut col: usize) -> String {
|
||||
let mut s = String::new();
|
||||
|
|
|
|||
|
|
@ -627,11 +627,88 @@ pub fn validate(r: &Rundown) -> Vec<Diagnostic> {
|
|||
}
|
||||
errors
|
||||
}
|
||||
fn ignorable_warning(d: &Diagnostic) -> bool {
|
||||
d.stage == 3
|
||||
&& matches!(
|
||||
d.code.as_str(),
|
||||
"UNTIMED_ROW"
|
||||
| "ORPHAN_NOTE"
|
||||
| "MISSING_START"
|
||||
| "MISSING_TITLE"
|
||||
| "MISSING_DURATION"
|
||||
| "UNRESOLVED_GAP"
|
||||
)
|
||||
}
|
||||
|
||||
/// Apply optional warning exclusions as derived decisions, rebuilding and validating
|
||||
/// after each pass. Turning the policy off always restores the original input rows.
|
||||
pub fn analyze(
|
||||
table: &Table,
|
||||
profile: &Profile,
|
||||
cancel: &AtomicBool,
|
||||
mut progress: impl FnMut(u8, &str),
|
||||
) -> Analysis {
|
||||
let mut effective = profile.clone();
|
||||
let mut ignored = Vec::new();
|
||||
loop {
|
||||
let mut analysis = analyze_once(table, &effective, cancel, &mut progress);
|
||||
let row_number = |d: &Diagnostic| {
|
||||
d.location
|
||||
.strip_prefix(&format!("{}!row ", table.name))
|
||||
.and_then(|row| row.parse::<usize>().ok())
|
||||
};
|
||||
let candidates: std::collections::BTreeSet<_> = if profile.ignore_warnings
|
||||
&& analysis.mapping.is_some()
|
||||
&& !cancel.load(Ordering::Relaxed)
|
||||
{
|
||||
analysis
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|d| ignorable_warning(d))
|
||||
.filter_map(row_number)
|
||||
.filter(|row| {
|
||||
*row > 0
|
||||
&& *row <= table.rows.len()
|
||||
&& !effective.row_kinds.contains_key(row)
|
||||
&& !profile.durations.contains_key(row)
|
||||
&& !analysis
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|d| row_number(d) == Some(*row) && !ignorable_warning(d))
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
if candidates.is_empty() {
|
||||
ignored.sort_unstable();
|
||||
if !ignored.is_empty()
|
||||
&& let Some(r) = &mut analysis.rundown
|
||||
{
|
||||
r.decisions.push(format!(
|
||||
"Ignore warnings policy excluded source rows: {}",
|
||||
ignored
|
||||
.iter()
|
||||
.map(usize::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
));
|
||||
}
|
||||
analysis.automatically_ignored_rows = ignored;
|
||||
return analysis;
|
||||
}
|
||||
for row in candidates {
|
||||
effective.row_kinds.insert(row, "ignore".into());
|
||||
ignored.push(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn analyze_once(
|
||||
table: &Table,
|
||||
profile: &Profile,
|
||||
cancel: &AtomicBool,
|
||||
mut progress: impl FnMut(u8, &str),
|
||||
) -> Analysis {
|
||||
let mut a = Analysis {
|
||||
sheet: table.name.clone(),
|
||||
|
|
@ -639,6 +716,7 @@ pub fn analyze(
|
|||
mapping: None,
|
||||
rundown: None,
|
||||
diagnostics: vec![],
|
||||
automatically_ignored_rows: vec![],
|
||||
};
|
||||
let mut draft_gaps = Vec::new();
|
||||
for stage in 1..=4 {
|
||||
|
|
|
|||
|
|
@ -831,3 +831,56 @@ fn excel_scientific_notation_durations_reach_export_as_milliseconds() {
|
|||
assert_eq!(time::duration(&t.rows[1][1], None), Some(-600_000));
|
||||
assert!(!analyze(&t, &Profile::default()).diagnostics.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warning_policy_excludes_rows_rechecks_and_can_be_disabled() {
|
||||
let t = table(&[
|
||||
&["Start", "Duration", "Title"],
|
||||
&["09:00", "5 min", "Opening"],
|
||||
&["", "", "Stage direction"],
|
||||
&["09:10", "5 min", "Closing"],
|
||||
]);
|
||||
let profile = Profile {
|
||||
ignore_warnings: true,
|
||||
..Default::default()
|
||||
};
|
||||
let a = analyze(&t, &profile);
|
||||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||||
assert_eq!(a.completed_stage, 4);
|
||||
assert_eq!(a.automatically_ignored_rows, [3]);
|
||||
let r = a.rundown.unwrap();
|
||||
assert_eq!(r.entries.len(), 2);
|
||||
assert_eq!(r.gaps.len(), 1);
|
||||
assert!(export::ontime(&r).is_ok());
|
||||
assert!(profile.row_kinds.is_empty());
|
||||
assert_eq!(
|
||||
analyze(&t, &Profile::default()).diagnostics[0].code,
|
||||
"UNTIMED_ROW"
|
||||
);
|
||||
let both = Profile {
|
||||
untimed_as_notes: true,
|
||||
..profile.clone()
|
||||
};
|
||||
let a = analyze(&t, &both);
|
||||
assert!(a.diagnostics.is_empty());
|
||||
assert!(a.automatically_ignored_rows.is_empty());
|
||||
assert_eq!(a.rundown.unwrap().entries[0].source_rows.len(), 2);
|
||||
let mut overlap = t.clone();
|
||||
overlap.rows[3][0].text = "09:03".into();
|
||||
let a = analyze(&overlap, &profile);
|
||||
assert_eq!(a.automatically_ignored_rows, [3]);
|
||||
assert!(a.diagnostics.iter().any(|d| d.code == "OVERLAP"));
|
||||
assert!(export::ontime(&a.rundown.unwrap()).is_err());
|
||||
let mut ambiguity = t.clone();
|
||||
ambiguity.rows[0][2].text = "Timer".into();
|
||||
let a = analyze(&ambiguity, &profile);
|
||||
assert!(a.mapping.is_none());
|
||||
assert!(a.automatically_ignored_rows.is_empty());
|
||||
let explicit = Profile {
|
||||
row_kinds: [(3, "event".into())].into_iter().collect(),
|
||||
..profile
|
||||
};
|
||||
let a = analyze(&t, &explicit);
|
||||
assert!(!a.diagnostics.is_empty());
|
||||
assert!(a.automatically_ignored_rows.is_empty());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,20 @@ directories must already exist. Exit codes: 0 success, 1 read/profile/write fail
|
|||
CLI logs are plain text on stderr; JSON results go to stdout.
|
||||
|
||||
In the desktop app, choose or drop one file, read its sheets, select a sheet and
|
||||
click **Analyze rundown**. A compact summary shows **Columns**, **Gaps**,
|
||||
click **Analyze rundown**. Setup exposes two **General options**, also saved in
|
||||
resolution profiles and usable from the CLI:
|
||||
|
||||
- **Ignore all warnings** (`ignore_warnings`): try excluding rows with missing
|
||||
start/duration/title, untimed content, orphan notes or unresolved breaks, then
|
||||
rebuild and validate. Column ambiguity, malformed timings, overlaps and other
|
||||
inconsistencies still block export. Manual row and duration decisions are kept.
|
||||
Automatically excluded rows are counted in the summary and remain visible in
|
||||
**All rows**. Disable the option and recheck to restore them.
|
||||
- **Treat untimed rows as notes** (`untimed_as_notes`): attach untimed rows to the
|
||||
preceding event. When both options are enabled, this runs before warning
|
||||
exclusions so notes are kept wherever possible.
|
||||
|
||||
Changes take effect on analysis / recheck. A compact summary shows **Columns**, **Gaps**,
|
||||
**Schedule**, and **Checks**: green OK labels mark success, amber marks attention or
|
||||
pending recheck, and gray marks steps not yet checked. Hover for explanations.
|
||||
Blocking column errors open **Columns** automatically. Row corrections become
|
||||
|
|
|
|||
Loading…
Reference in New Issue