Support mixed timing column extraction

This commit is contained in:
Dandaedre 2026-11-04 16:30:53 +01:00
parent 6c8b581599
commit fcb81e2e7c
9 changed files with 641 additions and 37 deletions

View File

@ -1,6 +1,6 @@
use crate::{
model::*,
time::{clock, clock_range, duration, normalize},
time::{clock, clock_range, duration, normalize, select_durations},
};
fn role(header: &str) -> Option<&'static str> {
@ -537,6 +537,30 @@ fn infer_inner(
let end = selected.get("end").copied();
let dur = selected.get("duration").copied();
let mut unit = profile.duration_unit.clone();
let duration_mode = profile.duration_mode.as_deref().unwrap_or("strict");
if !["strict", "minimum", "maximum", "sum", "margin", "split"].contains(&duration_mode) {
diagnostics.push(err(
"INVALID_DURATION_MODE",
table,
header,
dur.unwrap_or(start),
"Use strict, minimum, maximum, sum, margin or split",
));
}
if duration_mode == "split"
&& profile
.duration_separator
.as_deref()
.is_some_and(str::is_empty)
{
diagnostics.push(err(
"INVALID_DURATION_SEPARATOR",
table,
header,
dur.unwrap_or(start),
"Split separator cannot be empty; use \\n for newline",
));
}
if let Some(u) = &unit
&& !["minutes", "seconds", "hh:mm", "mm:ss", "excel"].contains(&u.as_str())
{
@ -643,7 +667,13 @@ fn infer_inner(
"start" => clock_range(&cell).is_some(),
"start_end" => clock_range(&cell).is_some_and(|(_, end)| end.is_some()),
"end" => clock(&cell).is_some(),
_ => duration(&cell, unit.as_deref()).is_some(),
_ => select_durations(
&cell,
unit.as_deref(),
profile.duration_mode.as_deref(),
profile.duration_separator.as_deref(),
)
.is_some(),
};
if !valid {
diagnostics.push(err("INCONSISTENT_COLUMN_MEANING",table,row,col,format!("Value {:?} does not fit {}{} for the whole column. Clarify headers/units or correct this value; rows cannot switch meanings.",cell.text,role_label(r),if r=="duration" {" with an unambiguous duration unit"}else{""})));
@ -664,6 +694,8 @@ fn infer_inner(
duration: dur,
title: selected["title"],
duration_unit: unit,
duration_mode: profile.duration_mode.clone(),
duration_separator: profile.duration_separator.clone(),
evidence: evidence.clone(),
column_usage,
column_labels,

View File

@ -62,6 +62,55 @@ impl ExportChoice {
}
}
}
fn duration_mode_label(mode: &str) -> &'static str {
match mode {
"minimum" => "Minimum",
"maximum" => "Maximum",
"sum" => "Sum",
"margin" => "Add margin",
"split" => "Split into entries",
_ => "Use the whole cell",
}
}
fn duration_handling_controls(ui: &mut egui::Ui, profile: &mut Profile, id: egui::Id) {
ui.indent(id.with("indent"), |ui| {
ui.horizontal_wrapped(|ui| {
ui.weak("Duration handling");
let mut mode = profile
.duration_mode
.clone()
.unwrap_or_else(|| "strict".into());
egui::ComboBox::from_id_salt(id.with("mode"))
.selected_text(duration_mode_label(&mode))
.show_ui(ui, |ui| {
for (value, label) in [
("strict", "Use the whole cell"),
("minimum", "Minimum"),
("maximum", "Maximum"),
("sum", "Sum"),
("margin", "Add margin"),
("split", "Split into entries"),
] {
ui.selectable_value(&mut mode, value.into(), label);
}
})
.response
.on_hover_text("Choose how duration values are extracted when one cell contains several values. Add margin uses the largest value for the event and keeps the remainder as a gap.");
profile.duration_mode = (mode != "strict").then_some(mode.clone());
if mode == "split" {
let separator = profile
.duration_separator
.get_or_insert_with(|| "\\n".into());
ui.label("Separator");
ui.add(egui::TextEdit::singleline(separator).desired_width(70.0))
.on_hover_text("Use \\n for a newline, \\n\\n for a blank line, \\t for a tab, or enter a literal separator.");
}
});
});
}
struct App {
input: String,
output: String,
@ -473,6 +522,20 @@ impl App {
}
}
});
let duration_available = profile.columns.contains_key("duration")
|| self
.analysis
.as_ref()
.and_then(|analysis| analysis.mapping.as_ref())
.and_then(|mapping| mapping.duration)
.is_some();
if duration_available {
duration_handling_controls(
ui,
&mut profile,
egui::Id::new("setup_duration_handling"),
);
}
if before != serde_json::to_string(&profile).unwrap() {
self.profile = serde_json::to_string_pretty(&profile).unwrap();
self.decisions_changed();
@ -504,7 +567,7 @@ impl App {
self.decisions_changed();
}
}
ui.label("Optional JSON profile: columns (start/start_end/end/duration/title), column_usage (notes/metadata/ignore), duration_unit, row_kinds, titles, starts, ends, durations, untimed_as_notes, ignore_warnings. Column letters and source rows are shown in diagnostics.");
ui.label("Optional JSON profile: columns (start/start_end/end/duration/title), column_usage (notes/metadata/ignore), duration_unit, duration_mode, duration_separator, row_kinds, titles, starts, ends, durations, untimed_as_notes, ignore_warnings. Column letters and source rows are shown in diagnostics.");
if ui
.add(
egui::TextEdit::multiline(&mut self.profile)

View File

@ -591,6 +591,8 @@ fn column_settings_changed(current: &Profile, analyzed: &Profile) -> bool {
|| current.column_usage != analyzed.column_usage
|| current.expected_headers != analyzed.expected_headers
|| current.duration_unit != analyzed.duration_unit
|| current.duration_mode != analyzed.duration_mode
|| current.duration_separator != analyzed.duration_separator
}
fn schedule_settings_changed(current: &Profile, analyzed: &Profile) -> bool {
@ -1650,6 +1652,18 @@ impl App {
.collect::<Vec<_>>()
.join(" / ");
ui.label(samples);
let duration_selected = column_choice(&profile, c) == Some("duration")
|| (column_choice(&profile, c).is_none()
&& mapping
.as_ref()
.is_ok_and(|mapping| mapping.duration == Some(c)));
if duration_selected {
super::duration_handling_controls(
ui,
&mut profile,
egui::Id::new(("review_duration_handling", c)),
);
}
});
if mapping_focus_scroll == Some(c) {
ui.scroll_to_rect(response.response.rect, Some(egui::Align::Center));
@ -3351,6 +3365,38 @@ mod tests {
assert!(!profile.columns.contains_key("start"));
assert!(app.dirty);
}
#[test]
fn duration_column_exposes_handling_without_extra_column_roles() {
let mut app = sample();
app.review_view = ReviewView::Columns;
let ctx = egui::Context::default();
configure_style(&ctx);
let size = [860.0, 900.0];
render(&mut app, &ctx, size, vec![]);
let labels = render(&mut app, &ctx, size, vec![]);
assert!(labels.iter().any(|(text, _)| text == "Duration handling"));
let button = labels
.iter()
.find(|(text, _)| text == "Use the whole cell")
.expect("duration handling menu")
.1
.center();
click_size(&mut app, &ctx, button, size);
let menu = render(&mut app, &ctx, size, vec![]);
let maximum = menu
.iter()
.rev()
.find(|(text, _)| text == "Maximum")
.expect("maximum duration policy")
.1
.center();
click_size(&mut app, &ctx, maximum, size);
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
assert_eq!(profile.duration_mode.as_deref(), Some("maximum"));
assert!(app.dirty);
}
#[test]
fn column_help_stays_hidden_until_the_tab_is_hovered() {
let mut app = sample();

View File

@ -69,6 +69,10 @@ pub struct Profile {
pub expected_headers: BTreeMap<String, String>,
/// minutes, seconds, hh:mm, mm:ss, or excel.
pub duration_unit: Option<String>,
/// strict, minimum, maximum, sum, margin, or split.
pub duration_mode: Option<String>,
/// Separator used by split mode. Escaped forms such as \\n and \\t are accepted.
pub duration_separator: 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.
@ -105,6 +109,10 @@ pub struct Mapping {
pub duration: Option<usize>,
pub title: usize,
pub duration_unit: Option<String>,
#[serde(default)]
pub duration_mode: Option<String>,
#[serde(default)]
pub duration_separator: Option<String>,
pub evidence: Vec<String>,
#[serde(default)]
pub column_usage: BTreeMap<String, String>,

View File

@ -1,7 +1,7 @@
use crate::{
detect,
model::*,
time::{clock, clock_range, duration, normalize},
time::{SelectedDurations, clock, clock_range, duration, normalize, select_durations},
};
use std::sync::atomic::{AtomicBool, Ordering};
use uuid::Uuid;
@ -36,7 +36,12 @@ fn is_gap(title: &str) -> bool {
.iter()
.any(|word| s == *word || s.starts_with(&format!("{word} ")))
}
fn supplied_duration(table: &Table, row: usize, map: &Mapping, profile: &Profile) -> Option<i64> {
fn duration_plan(
table: &Table,
row: usize,
map: &Mapping,
profile: &Profile,
) -> Option<SelectedDurations> {
if let Some(s) = profile.durations.get(&(row + 1)) {
duration(
&Cell {
@ -45,11 +50,28 @@ fn supplied_duration(table: &Table, row: usize, map: &Mapping, profile: &Profile
},
Some("hh:mm"),
)
.map(|value| SelectedDurations {
events: vec![value],
margin: 0,
})
} else {
map.duration
.and_then(|c| duration(&table.cell(row, c), map.duration_unit.as_deref()))
map.duration.and_then(|c| {
select_durations(
&table.cell(row, c),
map.duration_unit.as_deref(),
profile.duration_mode.as_deref(),
profile.duration_separator.as_deref(),
)
})
}
}
fn supplied_duration(table: &Table, row: usize, map: &Mapping, profile: &Profile) -> Option<i64> {
duration_plan(table, row, map, profile).map(|plan| plan.events.iter().sum())
}
fn supplied_span(table: &Table, row: usize, map: &Mapping, profile: &Profile) -> Option<i64> {
duration_plan(table, row, map, profile)
.map(|plan| plan.events.iter().sum::<i64>() + plan.margin)
}
fn supplied_title(table: &Table, row: usize, map: &Mapping, profile: &Profile) -> String {
profile
.titles
@ -88,7 +110,7 @@ fn times(
(
override_clock(&profile.starts, row).or_else(|| pair.map(|p| p.0)),
override_clock(&profile.ends, row).or_else(|| {
pair.and_then(|p| p.1)
pair.and_then(|p| map.start_end.then_some(p.1).flatten())
.or_else(|| map.end.and_then(|c| clock(&table.cell(row, c))))
}),
)
@ -136,7 +158,7 @@ pub fn identify_gaps(table: &Table, map: &Mapping, profile: &Profile) -> Vec<Gap
let (start, end) = times(table, r, map, profile);
let end = end.or_else(|| {
start
.zip(supplied_duration(table, r, map, profile))
.zip(supplied_span(table, r, map, profile))
.map(|(s, d)| s + d)
});
Some(Gap {
@ -162,7 +184,7 @@ pub fn identify_gaps(table: &Table, map: &Mapping, profile: &Profile) -> Vec<Gap
let (start, end) = times(table, a, map, profile);
let end = end.or_else(|| {
start
.zip(supplied_duration(table, a, map, profile))
.zip(supplied_span(table, a, map, profile))
.map(|(s, d)| s + d)
});
if let (Some(end), Some(next)) = (end, times(table, b, map, profile).0)
@ -190,14 +212,21 @@ struct EntryTiming {
inferred_duration: bool,
}
fn entry(table: &Table, row: usize, kind: &str, timing: EntryTiming) -> Entry {
fn entry(
table: &Table,
row: usize,
virtual_part: Option<usize>,
kind: &str,
timing: EntryTiming,
) -> Entry {
let identity = virtual_part.map_or_else(
|| format!("rundown/{}/{row}", table.name),
|part| format!("rundown/{}/{row}/part/{part}", table.name),
);
Entry {
id: Uuid::new_v5(
&Uuid::NAMESPACE_URL,
format!("rundown/{}/{row}", table.name).as_bytes(),
)
.simple()
.to_string(),
id: Uuid::new_v5(&Uuid::NAMESPACE_URL, identity.as_bytes())
.simple()
.to_string(),
kind: kind.into(),
title: String::new(),
start_ms: timing.start,
@ -309,8 +338,11 @@ pub fn construct(
continue;
}
let (given_start, given_end) = times(table, r, &map, profile);
let d = supplied_duration(table, r, &map, profile);
if profile.durations.contains_key(&(r + 1)) && d.is_none() {
let duration_plan = duration_plan(table, r, &map, profile);
let d = duration_plan
.as_ref()
.map(|plan| plan.events.iter().sum::<i64>());
if profile.durations.contains_key(&(r + 1)) && duration_plan.is_none() {
errors.push(Diagnostic::new(
3,
"INVALID_DURATION_OVERRIDE",
@ -369,6 +401,7 @@ pub fn construct(
let mut e = entry(
table,
r,
None,
"marker",
EntryTiming {
start,
@ -401,19 +434,69 @@ pub fn construct(
}
let merge_end = table.merged_until(r, map.start);
let duration_merge = map.duration.map_or(r, |c| table.merged_until(r, c));
// A shared clock window with per-row durations represents bounded child cues.
let child_group = merge_end > r && duration_merge == r && d.is_some();
if child_group {
if let Some(end) = given_end {
group = Some((merge_end, start, end));
} else {
if duration_plan
.as_ref()
.is_some_and(|plan| plan.events.len() > 1)
{
if merge_end > r || duration_merge > r {
errors.push(Diagnostic::new(
3,
"MERGED_START_WITHOUT_END",
"SPLIT_MERGED_TIMING",
at(table, r),
"Merged start with child durations needs an explicit group end",
"A split duration cannot be combined with a merged timing block. Unmerge it or use Minimum, Maximum or Sum.",
));
continue;
}
let plan = duration_plan.as_ref().expect("checked above");
if let Some(end) = given_end {
let selected: i64 = plan.events.iter().sum();
if end - start != selected {
errors.push(Diagnostic::new(
4,
"CONFLICTING_TIMES",
at(table, r),
"The selected split durations do not match the explicit start–end window.",
));
}
}
let count = plan.events.len();
let mut part_start = start;
for (part, &duration) in plan.events.iter().enumerate() {
let part_end = part_start + duration;
let mut e = entry(
table,
r,
Some(part),
"event",
EntryTiming {
start: part_start,
end: part_end,
duration,
explicit_start: part == 0 && given_start.is_some(),
inferred_end: true,
inferred_duration: false,
},
);
e.title = format!("{title} ({}/{count})", part + 1);
e.decisions.push(format!(
"Virtual entry {}/{} created by splitting the selected duration cell",
part + 1,
count
));
if part > 0 {
e.decisions
.push("Start derived from the preceding virtual entry".into());
}
result.entries.push(e);
part_start = part_end;
}
cursor = Some(part_start);
continue;
}
// A shared clock window with per-row durations represents bounded child cues.
let child_group = merge_end > r && duration_merge == r && d.is_some();
if child_group && let Some(end) = given_end {
group = Some((merge_end, start, end));
}
let event_end = if child_group { None } else { given_end };
let duration = d.or_else(|| event_end.map(|e| e - start));
@ -426,6 +509,7 @@ pub fn construct(
let mut e = entry(
table,
r,
None,
"event",
EntryTiming {
start,
@ -464,6 +548,12 @@ pub fn construct(
if profile.durations.contains_key(&(r + 1)) {
e.decisions
.push("Duration explicitly overridden by profile; original cells retained".into());
} else if let Some(mode) = profile.duration_mode.as_deref()
&& mode != "strict"
{
e.decisions.push(format!(
"Duration selected with the {mode} policy from mixed source text"
));
}
if merge_end > r && !child_group {
for continuation in r + 1..=merge_end.min(table.rows.len() - 1) {
@ -478,12 +568,28 @@ pub fn construct(
.push("Rows share a merged timing block and remain one timer".into());
row = merge_end + 1;
}
let margin = duration_plan.as_ref().map_or(0, |plan| plan.margin);
let occupied_end = end + margin;
if margin > 0 {
gaps.push(Gap {
after_row: Some(r + 1),
before_row: None,
start_ms: Some(end),
end_ms: Some(occupied_end),
title: "Duration margin".into(),
source_rows: vec![source_row(table, r)],
display_timer: false,
});
e.decisions.push(format!(
"A {margin} ms margin after this event was retained as a gap"
));
}
if let Some((last, _, boundary)) = group {
e.decisions.push(format!(
"Merged block ends at {boundary} ms (source row {})",
last + 1
));
if end > boundary {
if occupied_end > boundary {
errors.push(Diagnostic::new(
4,
"GROUP_OVERFLOW",
@ -492,11 +598,11 @@ pub fn construct(
));
}
if r == last {
if end < boundary {
if occupied_end < boundary {
gaps.push(Gap {
after_row: Some(r + 1),
before_row: Some(r + 2),
start_ms: Some(end),
start_ms: Some(occupied_end),
end_ms: Some(boundary),
title: "Unallocated time within merged block".into(),
source_rows: vec![],
@ -506,10 +612,10 @@ pub fn construct(
cursor = Some(boundary);
group = None;
} else {
cursor = Some(end);
cursor = Some(occupied_end);
}
} else {
cursor = Some(end);
cursor = Some(occupied_end);
}
result.entries.push(e);
}

View File

@ -76,6 +76,182 @@ pub fn duration(cell: &Cell, unit: Option<&str>) -> Option<i64> {
}
unsigned_duration(cell, unit)
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SelectedDurations {
/// One duration per event. More than one value creates virtual split entries.
pub events: Vec<i64>,
/// Untimed interval inserted after the event or split entries.
pub margin: i64,
}
fn separator(value: Option<&str>) -> &str {
match value.unwrap_or("\\n") {
"\\n" => "\n",
"\\n\\n" => "\n\n",
"\\t" => "\t",
other => other,
}
}
fn explicit_duration_values(text: &str, unit: Option<&str>) -> Vec<i64> {
let cell = Cell {
text: text.trim().into(),
..Cell::default()
};
if cell.text.is_empty() || clock_range(&cell).is_some_and(|(_, end)| end.is_some()) {
return vec![];
}
if let Some(value) = duration(&cell, unit) {
return vec![value];
}
let normalized = normalize(&cell.text)
.replace("minutes", "m")
.replace("minute", "m")
.replace("mins", "m")
.replace("min", "m")
.replace("mn", "m")
.replace("secondes", "s")
.replace("seconds", "s")
.replace("seconde", "s")
.replace("second", "s")
.replace("secs", "s")
.replace("sec", "s");
let chars: Vec<char> = normalized.chars().collect();
let mut values = Vec::new();
let mut index = 0;
while index < chars.len() {
if !chars[index].is_ascii_digit() && chars[index] != '.' && chars[index] != ',' {
index += 1;
continue;
}
let start = index;
while index < chars.len()
&& (chars[index].is_ascii_digit() || matches!(chars[index], '.' | ','))
{
index += 1;
}
let number: String = chars[start..index].iter().collect();
while index < chars.len() && chars[index].is_whitespace() {
index += 1;
}
let Some(&unit_char) = chars.get(index) else {
continue;
};
let factor = match unit_char {
'h' => 3_600_000.0,
'm' => 60_000.0,
's' => 1_000.0,
_ => continue,
};
let Some(number) = number.replace(',', ".").parse::<f64>().ok() else {
index += 1;
continue;
};
index += 1;
let mut value = number * factor;
// Accept compact durations such as 1h30, while complete clock ranges were
// removed above and therefore cannot be mistaken for durations here.
if unit_char == 'h' {
let minute_start = index;
while index < chars.len() && chars[index].is_ascii_digit() {
index += 1;
}
if index > minute_start {
let minutes: String = chars[minute_start..index].iter().collect();
if let Ok(minutes) = minutes.parse::<f64>() {
value += minutes * 60_000.0;
}
}
}
if let Some(value) = millis(value) {
values.push(value);
}
}
values
}
/// Extract a duration from mixed text using an explicit, column-wide policy.
pub fn select_durations(
cell: &Cell,
unit: Option<&str>,
mode: Option<&str>,
split_separator: Option<&str>,
) -> Option<SelectedDurations> {
let mode = mode.unwrap_or("strict");
if mode == "strict" {
return duration(cell, unit).map(|value| SelectedDurations {
events: vec![value],
margin: 0,
});
}
if mode == "split" {
let events: Vec<i64> = cell
.text
.split(separator(split_separator))
.filter_map(|part| {
let lines: Vec<Vec<i64>> = part
.lines()
.map(|line| explicit_duration_values(line, unit))
.filter(|values| !values.is_empty())
.collect();
let largest = lines.iter().map(Vec::len).max()?;
Some(
lines
.iter()
.filter(|values| values.len() == largest)
.flatten()
.sum(),
)
})
.collect();
return (!events.is_empty()).then_some(SelectedDurations { events, margin: 0 });
}
let groups: Vec<Vec<i64>> = cell
.text
.split(separator(split_separator))
.flat_map(|part| part.lines())
.map(|part| explicit_duration_values(part, unit))
.filter(|values| !values.is_empty())
.collect();
let largest = groups.iter().map(Vec::len).max()?;
// A one-value summary followed by a detailed “25 min + 5 min” line is an
// alternative expression of the same duration, not three independent values.
let preferred: Vec<Vec<i64>> = groups
.into_iter()
.filter(|values| values.len() == largest)
.collect();
let values: Vec<i64> = preferred.iter().flatten().copied().collect();
let selected = match mode {
"minimum" => SelectedDurations {
events: vec![*values.iter().min()?],
margin: 0,
},
"maximum" => SelectedDurations {
events: vec![*values.iter().max()?],
margin: 0,
},
"sum" => SelectedDurations {
events: vec![values.iter().sum()],
margin: 0,
},
"margin" => {
let mut event = 0;
let mut margin = 0;
for group in preferred {
let maximum = *group.iter().max()?;
event += maximum;
margin += group.iter().sum::<i64>() - maximum;
}
SelectedDurations {
events: vec![event],
margin,
}
}
_ => return None,
};
(!selected.events.is_empty()).then_some(selected)
}
fn unsigned_duration(cell: &Cell, unit: Option<&str>) -> Option<i64> {
let mut s = normalize(cell.text.trim()).replace(',', ".");
if cell.numeric && cell.time_style {
@ -108,6 +284,7 @@ fn unsigned_duration(cell: &Cell, unit: Option<&str>) -> Option<i64> {
("minute", "m"),
("mins", "m"),
("min", "m"),
("mn", "m"),
("secondes", "s"),
("seconds", "s"),
("seconde", "s"),

View File

@ -106,6 +106,153 @@ fn combined_start_end_column_is_inferred_and_enforced_across_rows() {
);
}
#[test]
fn start_role_extracts_only_start_from_a_mixed_clock_range() {
let t = table(&[
&["Horaires", "Durée", "Title"],
&["08h45 - 09h10", "20 min + 5 min QR", "Welcome"],
]);
let profile = Profile {
header_row: Some(1),
columns: BTreeMap::from([
("start".into(), "A".into()),
("duration".into(), "B".into()),
("title".into(), "C".into()),
]),
duration_mode: Some("maximum".into()),
..Profile::default()
};
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let event = &a.rundown.unwrap().entries[0];
assert_eq!(event.start_ms, (8 * 60 + 45) * 60_000);
assert_eq!(event.duration_ms, 20 * 60_000);
assert_eq!(event.end_ms, (9 * 60 + 5) * 60_000);
}
#[test]
fn duration_policies_extract_values_from_mixed_text() {
let cell = Cell {
text: "08h45 - 09h10\n20 min + 5 min QR".into(),
..Cell::default()
};
let selected = |mode| time::select_durations(&cell, None, Some(mode), Some("\\n")).unwrap();
assert_eq!(selected("minimum").events, [5 * 60_000]);
assert_eq!(selected("maximum").events, [20 * 60_000]);
assert_eq!(selected("sum").events, [25 * 60_000]);
assert_eq!(selected("margin").events, [20 * 60_000]);
assert_eq!(selected("margin").margin, 5 * 60_000);
let split = Cell {
text: "08:00 - 08:15\n10 min + 5 min|20 min".into(),
..Cell::default()
};
assert_eq!(
time::select_durations(&split, None, Some("split"), Some("|"))
.unwrap()
.events,
[15 * 60_000, 20 * 60_000]
);
let summary_and_detail = Cell {
text: "30 mn\n25 min + 5 min questions".into(),
..Cell::default()
};
assert_eq!(
time::select_durations(&summary_and_detail, None, Some("sum"), Some("\\n"))
.unwrap()
.events,
[30 * 60_000]
);
}
#[test]
fn start_only_merged_anchor_allows_sequential_child_durations() {
let mut t = table(&[
&["Horaires", "Durée", "Title"],
&["08h45 - 10h00", "20 min + 5 min", "First"],
&["", "20 min + 5 min", "Second"],
&["", "20 min + 5 min", "Third"],
]);
t.merges.push(Merge {
first_row: 1,
last_row: 3,
first_col: 0,
last_col: 0,
});
let profile = Profile {
header_row: Some(1),
columns: BTreeMap::from([
("start".into(), "A".into()),
("duration".into(), "B".into()),
("title".into(), "C".into()),
]),
duration_mode: Some("margin".into()),
..Profile::default()
};
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let rundown = a.rundown.unwrap();
assert_eq!(rundown.entries.len(), 3);
assert_eq!(rundown.entries[0].start_ms, (8 * 60 + 45) * 60_000);
assert_eq!(rundown.entries[1].start_ms, (9 * 60 + 10) * 60_000);
assert_eq!(rundown.entries[2].start_ms, (9 * 60 + 35) * 60_000);
assert_eq!(
rundown
.gaps
.iter()
.filter(|gap| gap.title == "Duration margin")
.count(),
3
);
}
#[test]
fn duration_margin_becomes_an_explicit_untimed_gap() {
let t = table(&[
&["Start", "Duration", "Title"],
&["08:00", "20 min + 5 min", "Welcome"],
]);
let profile = Profile {
duration_mode: Some("margin".into()),
..Profile::default()
};
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let rundown = a.rundown.unwrap();
assert_eq!(rundown.entries[0].duration_ms, 20 * 60_000);
let margin = rundown
.gaps
.iter()
.find(|gap| gap.title == "Duration margin")
.expect("duration margin gap");
assert_eq!(margin.start_ms, Some((8 * 60 + 20) * 60_000));
assert_eq!(margin.end_ms, Some((8 * 60 + 25) * 60_000));
}
#[test]
fn split_duration_creates_sequential_virtual_entries() {
let t = table(&[
&["Start", "Duration", "Title"],
&["08:00", "10 min\n5 min", "Welcome"],
]);
let profile = Profile {
duration_mode: Some("split".into()),
duration_separator: Some("\\n".into()),
..Profile::default()
};
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let entries = a.rundown.unwrap().entries;
assert_eq!(entries.len(), 2);
assert_eq!(entries[0].duration_ms, 10 * 60_000);
assert_eq!(entries[1].duration_ms, 5 * 60_000);
assert_eq!(entries[0].end_ms, entries[1].start_ms);
assert_ne!(entries[0].id, entries[1].id);
assert_eq!(entries[0].title, "Welcome (1/2)");
assert_eq!(entries[1].title, "Welcome (2/2)");
}
#[test]
fn combined_start_end_mapping_rejects_separate_start_or_end_roles() {
let t = table(&[
@ -320,7 +467,7 @@ fn merged_window_with_individual_durations_leaves_slack() {
&["09h00-09h10", "3 min", "A"],
&["", "3 min", "B"],
&["", "3 min", "C"],
&["09h10", "5 min", "Next"],
&["09h10-09h15", "5 min", "Next"],
]);
t.merges = vec![Merge {
first_row: 1,

View File

@ -15,7 +15,7 @@ schedule models, packaging and stretch goals.
| Area | Status | Evidence or remaining work |
| --- | --- | --- |
| 1. Whole-column inference | Complete | Header/data evidence, manual mapping and whole-column contradictions are implemented and tested. |
| 1. Whole-column inference | Complete | Header/data evidence, manual mapping and whole-column contradictions are implemented and tested. Explicit roles can select the start component of a mixed range and apply one documented extraction policy to a mixed duration column. |
| 2. Untimed gaps | Complete | Named and inferred gaps enter the IR; keep/extend previous/add to next resolutions are available. |
| 3. Complete IR | Complete for supported single-day schedules | Explicit and inferred timing provenance, notes, metadata, corrections and exclusions are retained. |
| 4. Consistency checks | Complete for supported single-track schedules | Conflicting triples, backward/negative timing, overlaps and gap boundaries block export. |
@ -296,6 +296,10 @@ errors must remain visible with direct corrective actions.
- [x] Stage 1: implement whole-column inference, explicit mappings and located
errors. Test ambiguous cells clarified by other rows, incompatible meanings in
one column, structural rows and misleading headers/units.
- [x] Keep one Duration column role while offering nested whole-cell, minimum,
maximum, sum, margin and split extraction policies. Let a Start mapping select
only the first clock in a mixed range; retain margin gaps and split entries in
the IR.
- [x] Stage 2: identify untimed gaps and populate draft IR constraints. Test named
and unnamed breaks, unknown boundaries and distinction from timed break cues.
- [x] Stage 3: construct the complete IR from times and gap constraints. Test

View File

@ -119,7 +119,12 @@ visually distinct from labels and ordinary actions; the active tab uses the stro
full inference and validation details; hover the **Columns** tab for a compact
explanation of the role choices. **Start–end** maps one column containing full
ranges such as `08h00 - 08h30`; every relevant timing cell must contain both
bounds. Selecting one duration column explicitly resolves duplicate TIMER headers.
bounds. **Start** selects only the first clock from a cell, so a mixed
`08h45 - 09h10` value can provide the 08:45 anchor while the selected duration
column determines the timer. A duration column has a nested **Duration handling**
choice instead of extra column roles: whole cell, minimum, maximum, sum, add
margin or split into entries. Selecting one duration column explicitly resolves
duplicate TIMER headers.
**Notes** appends a column's values to Ontime event notes. **Metadata**
creates an Ontime custom field named from the source header. **Ignore** excludes
the column from inference and Ontime output. Several columns can use any of these
@ -206,6 +211,9 @@ values from calculated values, unresolved values and gaps.
| --- | --- |
| Cue at 11:45 lasting 15 minutes; next cue at 13:30 | Preserve a 12:00–13:30 gap and the 13:30 start |
| Start–end cell `08h00 - 08h30` | Use 08:00 and 08:30 directly and derive a 30-minute duration |
| Start cell `08h45 - 09h10`, duration `20 min + 5 min` with Maximum | Use 08:45 and a 20-minute timer; the unused end in the Start cell does not constrain it |
| Duration `20 min + 5 min` with Add margin | Create a 20-minute event followed by a five-minute untimed gap |
| Multiline duration with Split | Create sequential virtual entries, one for each separated duration group |
| Named lunch row from 12:00 to 13:30 | Preserve an explicit break with its original label |
| Cue at 11:45; next cue at 13:30; no end or duration | Event duration versus break is unknown; do not invent a lunch break |
| Start 11:45, end 12:00, duration 20 minutes | Report conflicting timing and request clarification |
@ -255,7 +263,9 @@ Pass `--profile mapping.json`, or load/edit the same JSON in the desktop app:
```json
{
"header_row": 1,
"columns": {"start_end": "A", "duration": "B", "title": "G"},
"columns": {"start": "A", "duration": "B", "title": "G"},
"duration_mode": "split",
"duration_separator": "\\n\\n",
"column_usage": {"C": "notes", "D": "metadata", "F": "ignore"},
"expected_headers": {"A": "Horaires", "B": "Durée"},
"untimed_as_notes": true,
@ -271,7 +281,8 @@ This illustrates options, not a profile to apply blindly to the supplied files.
Rows are one-based original worksheet rows; columns use Excel letters. Supported
roles are `start`, `start_end`, `end`, `duration` and `title`. A `start_end`
column requires a complete clock range such as `08h00 - 08h30` in every relevant
timed cell and supplies both values without a separate `end` mapping.
timed cell and supplies both values without a separate `end` mapping. A `start`
mapping extracts only the first clock when its cell also contains an end clock.
`duration_unit` accepts `minutes`,
`seconds`, `hh:mm`, `mm:ss` or `excel`. Cell number formats establish Excel time
units where available; otherwise units must be explicit or consistently supported
@ -280,6 +291,16 @@ are errors. `titles`, `starts`, `ends` and `durations` are keyed by one-based so
corrected cells are excluded from whole-column validation while all remaining
explicit mappings still undergo it.
`duration_mode` is optional and remains attached to the single `duration` role.
`minimum`, `maximum` and `sum` select from explicit duration values in mixed text.
`margin` uses the largest value in each duration group for the event and preserves
the remainder as an untimed gap. `split` creates sequential virtual events from
groups separated by `duration_separator`; `\\n`, `\\n\\n` and `\\t` mean newline,
blank line and tab. The default `strict` behavior requires the complete cell to be
one duration. For non-split policies, a one-value summary line followed by a more
detailed multi-value line is treated as an alternative expression, avoiding double
counting.
`column_usage` maps column letters to `notes`, `metadata` or `ignore`. Every choice
prevents that column from being inferred as a start, start–end, end, duration or
title, and a column cannot also have an explicit timing or title mapping. Notes values are joined