Prioritize column ambiguity and render Excel times readably

This commit is contained in:
Dandaedre 2026-11-03 15:19:43 +01:00
parent e9fb447df0
commit 6c52dfe893
5 changed files with 132 additions and 8 deletions

View File

@ -231,7 +231,11 @@ impl App {
self.issue_index = 0;
self.selected_row = a.diagnostics.first().and_then(review::diagnostic_row);
self.jump_row = self.selected_row;
self.review_view = ReviewView::Rows;
self.review_view = if a.mapping.is_none() {
ReviewView::Columns
} else {
ReviewView::Rows
};
self.analysis = Some(*a);
}
Update::Exported(p) => {
@ -867,6 +871,7 @@ mod tests {
app.analysis.as_ref().unwrap().diagnostics[0].code,
"AMBIGUOUS_COLUMN"
);
assert!(app.review_view == ReviewView::Columns);
let (_, evidence) = detect::inspect(&app.tables[0], &Profile::default());
assert!(evidence.iter().any(|e| e == "Header suggests start in A"));
assert!(!evidence.iter().any(|e| e.starts_with("Every relevant")));
@ -879,6 +884,7 @@ mod tests {
app.analyze();
wait(&mut app);
assert!(app.analysis.as_ref().unwrap().diagnostics.is_empty());
assert!(app.review_view == ReviewView::Rows);
let path = dir.path().join("resolution.json");
app.save_profile(path.clone(), false).unwrap();
assert!(app.save_profile(path.clone(), false).is_err());

View File

@ -40,6 +40,21 @@ fn short(text: &str, count: usize) -> String {
result
}
/// Presentation only: retain source values and avoid treating plain numbers as times.
fn cell_text(cell: &crate::model::Cell) -> String {
if cell.time_style {
let time = if cell.numeric {
crate::time::duration(cell, None)
} else {
crate::time::clock(cell)
};
if let Some(time) = time {
return display(time);
}
}
cell.text.clone()
}
const PREVIEW_SUCCESS: Color32 = Color32::from_rgb(115, 205, 150);
const PREVIEW_AMBER: Color32 = Color32::from_rgb(235, 190, 95);
const PREVIEW_GAP: Color32 = Color32::from_rgb(110, 200, 215);
@ -127,7 +142,7 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
continue;
}
let raw = |col: Option<usize>| {
col.map(|c| table.cell(row - 1, c).text)
col.map(|c| cell_text(&table.cell(row - 1, c)))
.filter(|s| !s.trim().is_empty() && !matches!(s.trim(), "-" | "—"))
.unwrap_or("?".into())
};
@ -141,7 +156,7 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
.iter()
.enumerate()
.filter(|(_, c)| !c.text.trim().is_empty())
.map(|(c, v)| format!("{}: {}", column_name(c), v.text))
.map(|(c, v)| format!("{}: {}", column_name(c), cell_text(v)))
.collect::<Vec<_>>()
.join(" · ")
});
@ -632,7 +647,13 @@ impl App {
ui.vertical(|ui| {
ui.set_width(value_width);
if cell.text.is_empty() { ui.weak("Empty"); }
else { ui.add(egui::Label::new(&cell.text).wrap()); }
else {
let formatted = cell_text(cell);
ui.add(egui::Label::new(&formatted).wrap());
if formatted != cell.text {
ui.collapsing("Stored value", |ui| { ui.monospace(&cell.text); });
}
}
if let Some(formula) = &cell.formula {
ui.small("Formula");
ui.add(egui::Label::new(RichText::new(formula).monospace()).wrap());
@ -687,6 +708,12 @@ impl App {
PREVIEW_AMBER,
format!("! Column mapping needs attention · {} issues", errors.len()),
);
for error in errors {
ui.add(
egui::Label::new(RichText::new(&error.message).color(PREVIEW_AMBER))
.wrap(),
);
}
}
}
ui.collapsing("Detection evidence", |ui| {
@ -768,7 +795,7 @@ impl App {
.filter_map(|r| r.get(c))
.filter(|v| !v.text.trim().is_empty())
.take(3)
.map(|v| short(&v.text, 65))
.map(|v| short(&cell_text(v), 65))
.collect::<Vec<_>>()
.join(" / ");
ui.label(samples);
@ -781,6 +808,16 @@ impl App {
}
fn schedule_preview(&mut self, ui: &mut egui::Ui) {
if self.analysis.as_ref().is_some_and(|a| a.mapping.is_none()) {
ui.colored_label(PREVIEW_AMBER, "Resolve column mapping before editing rows.");
ui.label(
"The schedule cannot be interpreted until the timing columns are unambiguous.",
);
if ui.button("Review columns").clicked() {
self.review_view = ReviewView::Columns;
}
return;
}
let ignorable = self
.analysis
.as_ref()
@ -1322,6 +1359,59 @@ mod tests {
assert_eq!(app.selected_row, Some(3));
}
#[test]
fn spreadsheet_time_samples_are_readable_without_changing_source() {
let cell = |text: &str, numeric| crate::model::Cell {
text: text.into(),
numeric,
time_style: true,
..Default::default()
};
for (raw, expected) in [
("6.9444444444444441E-3", "00:10:00"),
("7.407407407407407E-4", "00:01:04"),
("-0.5", "-12:00:00"),
] {
let value = cell(raw, true);
assert_eq!(cell_text(&value), expected);
assert_eq!(value.text, raw);
}
assert_eq!(cell_text(&cell("15h30", false)), "15:30:00");
assert_eq!(cell_text(&cell("not a time", false)), "not a time");
let mut value = cell("0.5", true);
value.time_style = false;
assert_eq!(cell_text(&value), "0.5");
let mut app = sample();
app.tables[0].rows[0][2].text = "Timer".into();
app.analysis = Some(pipeline::analyze(
&app.tables[0],
&Profile::default(),
&AtomicBool::new(false),
|_, _| {},
));
assert!(app.analysis.as_ref().unwrap().mapping.is_none());
let ctx = egui::Context::default();
configure_style(&ctx);
let labels = render(&mut app, &ctx, [860.0, 620.0], vec![]);
assert!(
labels
.iter()
.any(|(s, _)| s == "Resolve column mapping before editing rows.")
);
assert!(!labels.iter().any(|(s, _)| s.starts_with("Ignore all")));
app.review_view = ReviewView::Columns;
app.tables[0].rows[1][1] = cell("6.9444444444444441E-3", true);
render(&mut app, &ctx, [860.0, 900.0], vec![]);
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
assert!(labels.iter().any(|(s, _)| s.contains("00:10:00")));
assert!(!labels.iter().any(|(s, _)| s.contains("6.944444")));
assert!(
labels
.iter()
.any(|(s, _)| s.contains("Several duration columns"))
);
}
#[test]
fn bulk_ignore_skips_timed_rows_errors_and_previous_decisions() {
let mut app = sample();

View File

@ -77,13 +77,14 @@ pub fn duration(cell: &Cell, unit: Option<&str>) -> Option<i64> {
unsigned_duration(cell, unit)
}
fn unsigned_duration(cell: &Cell, unit: Option<&str>) -> Option<i64> {
if cell.text.contains('-') {
return None;
}
let mut s = normalize(cell.text.trim()).replace(',', ".");
if cell.numeric && cell.time_style {
// Excel may serialize day fractions with a negative exponent, e.g. 6.94E-3.
return millis(s.parse::<f64>().ok()? * 86_400_000.0);
}
if cell.text.contains('-') {
return None;
}
if s.contains(':') {
let parts = s
.split(':')

View File

@ -808,3 +808,26 @@ fn invalid_or_unavailable_gap_choices_block_export() {
);
assert_eq!(a.rundown.unwrap().gaps.len(), 1);
}
#[test]
fn excel_scientific_notation_durations_reach_export_as_milliseconds() {
let mut t = simple();
t.rows[1][1] = Cell {
text: "6.9444444444444441E-3".into(),
numeric: true,
time_style: true,
..Default::default()
};
let a = analyze(&t, &Profile::default());
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let r = a.rundown.unwrap();
assert_eq!(r.entries[0].duration_ms, 600_000);
let json = export::ontime(&r).unwrap();
assert_eq!(
json["rundowns"]["default"]["entries"][&r.entries[0].id]["duration"],
600_000
);
t.rows[1][1].text = "-6.9444444444444441E-3".into();
assert_eq!(time::duration(&t.rows[1][1], None), Some(-600_000));
assert!(!analyze(&t, &Profile::default()).diagnostics.is_empty());
}

View File

@ -36,6 +36,10 @@ 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**,
**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
available after the timing mapping is unambiguous and rechecked. Spreadsheet
cells marked as times display as `HH:MM:SS` in samples and the inspector; the
original stored value remains available in the inspector.
Review has two views:
- **Schedule & corrections** combines the schedule preview and row editing in one