diff --git a/crates/rundown-converter/src/detect.rs b/crates/rundown-converter/src/detect.rs index d2e0d10..c56c34b 100644 --- a/crates/rundown-converter/src/detect.rs +++ b/crates/rundown-converter/src/detect.rs @@ -6,7 +6,19 @@ use crate::{ fn role(header: &str) -> Option<&'static str> { let h = normalize(header); let h = h.trim(); - if h.contains("duration") || h.contains("duree") || h == "timer" { + if [ + "start-end", + "start / end", + "start to end", + "debut-fin", + "debut / fin", + "debut a fin", + "horaire debut-fin", + ] + .contains(&h) + { + Some("start_end") + } else if h.contains("duration") || h.contains("duree") || h == "timer" { Some("duration") } else if ["end", "end time", "fin", "heure fin", "heure de fin"].contains(&h) { Some("end") @@ -44,6 +56,13 @@ fn role(header: &str) -> Option<&'static str> { None } } +fn role_label(role: &str) -> &str { + if role == "start_end" { + "start–end" + } else { + role + } +} fn loc(table: &Table, row: usize, col: usize) -> String { format!("{}!{}{}", table.name, column_name(col), row + 1) } @@ -286,13 +305,13 @@ fn infer_inner( let mut selected = std::collections::BTreeMap::new(); for (r, col) in &profile.columns { - if !["start", "end", "duration", "title"].contains(&r.as_str()) { + if !["start", "start_end", "end", "duration", "title"].contains(&r.as_str()) { diagnostics.push(err( "INVALID_MAPPING", table, header, 0, - format!("Unknown role {r}; use start, end, duration or title"), + format!("Unknown role {r}; use start, start_end, end, duration or title"), )); continue; } @@ -306,7 +325,7 @@ fn infer_inner( )), Some(c) => { selected.insert(r.as_str(), c); - evidence.push(format!("Explicit {r} column {col}")); + evidence.push(format!("Explicit {} column {col}", role_label(r))); } None => diagnostics.push(err( "INVALID_MAPPING", @@ -317,7 +336,12 @@ fn infer_inner( )), } } - for r in ["start", "end", "duration", "title"] { + for r in ["start_end", "start", "end", "duration", "title"] { + if matches!(r, "start" | "start_end") + && (selected.contains_key("start") || selected.contains_key("start_end")) + { + continue; + } if selected.contains_key(r) { continue; } @@ -326,20 +350,37 @@ fn infer_inner( .filter(|c| role(&table.cell(header, *c).text) == Some(r)) .collect(); if candidates.len() == 1 { - selected.insert(r, candidates[0]); + let candidate = candidates[0]; + let timing_cells: Vec<_> = rows + .iter() + .map(|row| table.cell(*row, candidate)) + .filter(|cell| !placeholder(&cell.text)) + .collect(); + let detected_role = if r == "start" + && !timing_cells.is_empty() + && timing_cells + .iter() + .all(|cell| clock_range(cell).is_some_and(|(_, end)| end.is_some())) + { + "start_end" + } else { + r + }; + selected.insert(detected_role, candidate); evidence.push(format!( - "Header suggests {r} in {}", - column_name(candidates[0]) + "Header suggests {} in {}", + role_label(detected_role), + column_name(candidate) )); } else if candidates.len() > 1 { - diagnostics.push(err("AMBIGUOUS_COLUMN",table,header,candidates[0],format!("Several {r} columns: {}. Clarify headers or explicitly select the intended column; parent and child timers cannot be flattened automatically.",candidates.iter().map(|c| column_name(*c)).collect::>().join(", ")))); + diagnostics.push(err("AMBIGUOUS_COLUMN",table,header,candidates[0],format!("Several {} columns: {}. Clarify headers or explicitly select the intended column; parent and child timers cannot be flattened automatically.",role_label(r),candidates.iter().map(|c| column_name(*c)).collect::>().join(", ")))); } } - // Data can supply a missing start or duration role when the whole column agrees. - for r in ["start", "duration"] { - if selected.contains_key(r) || diagnostics.iter().any(|d| d.code == "AMBIGUOUS_COLUMN") { - continue; - } + // Data can supply a missing start role when exactly one whole column agrees. + if !selected.contains_key("start") + && !selected.contains_key("start_end") + && !diagnostics.iter().any(|d| d.code == "AMBIGUOUS_COLUMN") + { let candidates: Vec<_> = (0..width) .filter(|c| !excluded.contains(c)) .filter(|c| !selected.values().any(|v| v == c)) @@ -349,20 +390,53 @@ fn infer_inner( .map(|row| table.cell(*row, *c)) .filter(|c| !placeholder(&c.text)) .collect(); - cells.len() >= 2 - && cells.iter().all(|cell| { - if r == "start" { - clock_range(cell).is_some() - } else { - duration(cell, None).is_some() - } - }) + cells.len() >= 2 && cells.iter().all(|cell| clock_range(cell).is_some()) }) .collect(); if candidates.len() == 1 { - selected.insert(r, candidates[0]); + let candidate = candidates[0]; + let combined = rows + .iter() + .map(|row| table.cell(*row, candidate)) + .filter(|cell| !placeholder(&cell.text)) + .all(|cell| clock_range(&cell).is_some_and(|(_, end)| end.is_some())); + let inferred_role = if combined { "start_end" } else { "start" }; + selected.insert(inferred_role, candidate); evidence.push(format!( - "All populated data cells support {r} in {}", + "All populated data cells support {} in {}", + role_label(inferred_role), + column_name(candidate) + )); + } else if candidates.len() > 1 { + diagnostics.push(err( + "AMBIGUOUS_COLUMN", + table, + header, + candidates[0], + "Multiple data columns can mean start or start–end; clarify headers or select a column", + )); + } + } + // Duration inference remains separate from clock/range inference. + if !selected.contains_key("duration") + && !diagnostics.iter().any(|d| d.code == "AMBIGUOUS_COLUMN") + { + let candidates: Vec<_> = (0..width) + .filter(|c| !excluded.contains(c)) + .filter(|c| !selected.values().any(|v| v == c)) + .filter(|c| { + let cells: Vec<_> = rows + .iter() + .map(|row| table.cell(*row, *c)) + .filter(|cell| !placeholder(&cell.text)) + .collect(); + cells.len() >= 2 && cells.iter().all(|cell| duration(cell, None).is_some()) + }) + .collect(); + if candidates.len() == 1 { + selected.insert("duration", candidates[0]); + evidence.push(format!( + "All populated data cells support duration in {}", column_name(candidates[0]) )); } else if candidates.len() > 1 { @@ -371,7 +445,7 @@ fn infer_inner( table, header, candidates[0], - format!("Multiple data columns can mean {r}; clarify headers or select a column"), + "Multiple data columns can mean duration; clarify headers or select a column", )); } } @@ -386,7 +460,12 @@ fn infer_inner( } } for required in ["start", "title"] { - if !selected.contains_key(required) { + let present = if required == "start" { + selected.contains_key("start") || selected.contains_key("start_end") + } else { + selected.contains_key(required) + }; + if !present { diagnostics.push(err( "MISSING_COLUMN", table, @@ -399,6 +478,26 @@ fn infer_inner( if !diagnostics.is_empty() { return Err(diagnostics); } + if selected.contains_key("start") && selected.contains_key("start_end") { + diagnostics.push(err( + "INVALID_MAPPING", + table, + header, + selected["start_end"], + "Choose either a Start column or a Start–end column, not both", + )); + return Err(diagnostics); + } + if selected.contains_key("start_end") && selected.contains_key("end") { + diagnostics.push(err( + "INVALID_MAPPING", + table, + header, + selected["end"], + "A Start–end column already supplies both values; remove the separate End mapping", + )); + return Err(diagnostics); + } let mut used = std::collections::BTreeSet::new(); for (&r, &c) in &selected { if !used.insert(c) { @@ -433,7 +532,8 @@ fn infer_inner( ) }) .collect(); - let start = selected["start"]; + let start_end = selected.get("start_end").copied(); + let start = start_end.unwrap_or_else(|| selected["start"]); let end = selected.get("end").copied(); let dur = selected.get("duration").copied(); let mut unit = profile.duration_unit.clone(); @@ -515,6 +615,9 @@ fn infer_inner( let cell = table.cell(row, col); let overridden = match r { "start" => profile.starts.contains_key(&(row + 1)), + "start_end" => { + profile.starts.contains_key(&(row + 1)) && profile.ends.contains_key(&(row + 1)) + } "end" => profile.ends.contains_key(&(row + 1)), "duration" => profile.durations.contains_key(&(row + 1)), _ => false, @@ -538,11 +641,12 @@ fn infer_inner( } let valid = match r { "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(), }; if !valid { - diagnostics.push(err("INCONSISTENT_COLUMN_MEANING",table,row,col,format!("Value {:?} does not fit {r}{} for the whole column. Clarify headers/units or correct this value; rows cannot switch meanings.",cell.text,if r=="duration" {" with an unambiguous duration unit"}else{""}))); + 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{""}))); } } } @@ -555,6 +659,7 @@ fn infer_inner( Ok(Mapping { header_row: header + 1, start, + start_end: start_end.is_some(), end, duration: dur, title: selected["title"], diff --git a/crates/rundown-converter/src/gui.rs b/crates/rundown-converter/src/gui.rs index 1306778..9bb92ba 100644 --- a/crates/rundown-converter/src/gui.rs +++ b/crates/rundown-converter/src/gui.rs @@ -428,8 +428,15 @@ impl App { }); let width = table.rows.iter().map(Vec::len).max().unwrap_or(0); egui::Grid::new("mapping_controls").show(ui, |ui| { - for role in ["start", "end", "duration", "title"] { - ui.label(role); + for role in ["start", "start_end", "end", "duration", "title"] { + ui.label(match role { + "start" => "Start", + "start_end" => "Start–end", + "end" => "End", + "duration" => "Duration", + "title" => "Title", + _ => role, + }); let mut col = profile.columns.get(role).cloned().unwrap_or_default(); let previous = col.clone(); egui::ComboBox::from_id_salt(role) @@ -497,7 +504,7 @@ impl App { self.decisions_changed(); } } - ui.label("Optional JSON profile: columns (start/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, 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) diff --git a/crates/rundown-converter/src/gui/review.rs b/crates/rundown-converter/src/gui/review.rs index 27ec9e4..8583619 100644 --- a/crates/rundown-converter/src/gui/review.rs +++ b/crates/rundown-converter/src/gui/review.rs @@ -1570,7 +1570,7 @@ impl App { let old = chosen.clone(); let detected_role = mapping.as_ref().ok().map(|m| { if m.start == c { - "Start" + if m.start_end { "Start–end" } else { "Start" } } else if m.title == c { "Title" } else if m.end == Some(c) { @@ -1591,6 +1591,7 @@ impl App { } else { match chosen.as_str() { "start" => "Start", + "start_end" => "Start–end", "end" => "End", "duration" => "Duration", "title" => "Title", @@ -1610,6 +1611,7 @@ impl App { ("notes", "Notes"), ("metadata", "Metadata"), ("start", "Start"), + ("start_end", "Start–end"), ("end", "End"), ("duration", "Duration"), ("title", "Title"), @@ -3315,6 +3317,40 @@ mod tests { ); } } + + #[test] + fn column_menu_can_select_combined_start_end_role() { + 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![]); + let button = labels + .iter() + .find(|(text, _)| text == "Auto (Start)") + .expect("detected Start column") + .1 + .center(); + click_size(&mut app, &ctx, button, size); + let menu = render(&mut app, &ctx, size, vec![]); + let option = menu + .iter() + .rev() + .find(|(text, _)| text == "Start–end") + .expect("Start–end role") + .1 + .center(); + click_size(&mut app, &ctx, option, size); + let profile: Profile = serde_json::from_str(&app.profile).unwrap(); + assert_eq!( + profile.columns.get("start_end").map(String::as_str), + Some("A") + ); + assert!(!profile.columns.contains_key("start")); + assert!(app.dirty); + } #[test] fn column_help_stays_hidden_until_the_tab_is_hovered() { let mut app = sample(); diff --git a/crates/rundown-converter/src/model.rs b/crates/rundown-converter/src/model.rs index b920713..9be73c6 100644 --- a/crates/rundown-converter/src/model.rs +++ b/crates/rundown-converter/src/model.rs @@ -98,6 +98,9 @@ impl Profile { pub struct Mapping { pub header_row: usize, pub start: usize, + /// The start column contains a complete start/end range in every timed cell. + #[serde(default)] + pub start_end: bool, pub end: Option, pub duration: Option, pub title: usize, diff --git a/crates/rundown-converter/tests/conversion.rs b/crates/rundown-converter/tests/conversion.rs index 2280e5c..3d04cef 100644 --- a/crates/rundown-converter/tests/conversion.rs +++ b/crates/rundown-converter/tests/conversion.rs @@ -67,6 +67,100 @@ fn ir_records_inferred_start_end_and_duration_provenance() { assert!(!entries[1].inferred_end); assert!(entries[1].inferred_duration); } + +#[test] +fn combined_start_end_column_is_inferred_and_enforced_across_rows() { + let t = table(&[ + &["Horaires", "Title"], + &["08h00 - 08h30", "Welcome"], + &["08h30-09h15", "Keynote"], + ]); + let a = analyze(&t, &Profile::default()); + assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics); + let mapping = a.mapping.unwrap(); + assert!(mapping.start_end); + assert_eq!(mapping.start, 0); + let entries = a.rundown.unwrap().entries; + assert_eq!(entries[0].start_ms, 8 * 3_600_000); + assert_eq!(entries[0].end_ms, 8 * 3_600_000 + 30 * 60_000); + assert_eq!(entries[0].duration_ms, 30 * 60_000); + + let malformed = table(&[ + &["Window", "Title"], + &["08:00 - 08:30", "Welcome"], + &["08:30", "Keynote"], + ]); + let profile = Profile { + header_row: Some(1), + columns: BTreeMap::from([ + ("start_end".into(), "A".into()), + ("title".into(), "B".into()), + ]), + ..Profile::default() + }; + let a = analyze(&malformed, &profile); + assert!( + a.diagnostics + .iter() + .any(|d| { d.code == "INCONSISTENT_COLUMN_MEANING" && d.location.ends_with("A3") }) + ); +} + +#[test] +fn combined_start_end_mapping_rejects_separate_start_or_end_roles() { + let t = table(&[ + &["Window", "Finish", "Title"], + &["08:00 - 08:30", "08:30", "Welcome"], + ]); + for columns in [ + BTreeMap::from([ + ("start".into(), "A".into()), + ("start_end".into(), "A".into()), + ("title".into(), "C".into()), + ]), + BTreeMap::from([ + ("start_end".into(), "A".into()), + ("end".into(), "B".into()), + ("title".into(), "C".into()), + ]), + ] { + let a = analyze( + &t, + &Profile { + header_row: Some(1), + columns, + ..Profile::default() + }, + ); + assert!( + a.diagnostics.iter().any(|d| d.code == "INVALID_MAPPING"), + "{:?}", + a.diagnostics + ); + } +} + +#[test] +fn combined_ranges_do_not_hide_another_possible_start_column() { + let t = table(&[ + &["Window", "Anchor", "Title"], + &["08:00 - 08:30", "08:00", "Welcome"], + &["08:30 - 09:15", "08:30", "Keynote"], + ]); + let a = analyze( + &t, + &Profile { + header_row: Some(1), + columns: BTreeMap::from([("title".into(), "C".into())]), + ..Profile::default() + }, + ); + assert!( + a.diagnostics.iter().any(|d| { + d.code == "AMBIGUOUS_COLUMN" && d.message.contains("start or start–end") + }) + ); +} #[test] fn named_untimed_break_occupies_time_without_timer() { let t = table(&[ diff --git a/docs/rundown-converter.md b/docs/rundown-converter.md index 660a737..ff4b2b1 100644 --- a/docs/rundown-converter.md +++ b/docs/rundown-converter.md @@ -117,8 +117,10 @@ visually distinct from labels and ordinary actions; the active tab uses the stro - **Columns** shows a concise verified mapping summary, green detected roles, per-column role dropdowns, and sample values. Expand **Detection evidence** for full inference and validation details; hover the **Columns** tab for a compact - explanation of the role choices. Selecting one duration column explicitly resolves duplicate TIMER - headers. **Notes** appends a column's values to Ontime event notes. **Metadata** + 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. + **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 destinations. **Auto** restores inference: production headers such as video, @@ -203,6 +205,7 @@ values from calculated values, unresolved values and gaps. | Source evidence | Interpretation | | --- | --- | | 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 | | 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 | @@ -252,9 +255,9 @@ Pass `--profile mapping.json`, or load/edit the same JSON in the desktop app: ```json { "header_row": 1, - "columns": {"start": "A", "duration": "B", "title": "G"}, + "columns": {"start_end": "A", "duration": "B", "title": "G"}, "column_usage": {"C": "notes", "D": "metadata", "F": "ignore"}, - "expected_headers": {"A": "Heure", "B": "Durée"}, + "expected_headers": {"A": "Horaires", "B": "Durée"}, "untimed_as_notes": true, "row_kinds": {"20": "marker"}, "titles": {"8": "Opening remarks"}, @@ -266,7 +269,10 @@ Pass `--profile mapping.json`, or load/edit the same JSON in the desktop app: 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`, `end`, `duration` and `title`. `duration_unit` accepts `minutes`, +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. +`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 by independent start/end pairs. Unknown profile keys and changed expected headers @@ -275,8 +281,8 @@ corrected cells are excluded from whole-column validation while all remaining explicit mappings still undergo it. `column_usage` maps column letters to `notes`, `metadata` or `ignore`. Every choice -prevents that column from being inferred as a start, end, duration or title, and a -column cannot also have an explicit timing or title mapping. Notes values are joined +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 into the Ontime event note, including values from attached note rows and merged continuations. Metadata creates a project-level Ontime text custom field and stores each event's value in its `custom` object. Ignore removes the values from Ontime; diff --git a/docs/rundown-corpus.md b/docs/rundown-corpus.md index 448f3d8..ba97264 100644 --- a/docs/rundown-corpus.md +++ b/docs/rundown-corpus.md @@ -1,9 +1,9 @@ # Rundown evaluation corpus -The first implementation was evaluated on two supplied XLSX workbooks (three -sheets), two supplied PDFs, seven downloaded public XLSX workbooks and three -public CSV files. Source -originals remain in ignored `rundowns/` and `downloads/rundown-corpus/`; they are +The implementation was evaluated on three supplied XLSX workbooks (five sheets), +two supplied PDFs, seven downloaded public XLSX workbooks and three +public CSV files. Source originals remain in ignored `rundowns/` and +`downloads/rundown-corpus/`; they are not redistributed in Git. Automated regression tests use synthetic data. The [public source manifest](../crates/rundown-converter/tests/public-corpus.json) @@ -19,6 +19,7 @@ behaviors and limitations, not a general success percentage. | ESTIVALES, OUVERTURE | Correctly identifies Heure, Durée and Contenu / Détail. Shared merged durations remain one timer; merged windows with individual durations become consecutive cues with leftover slack. Untimed production directions need a note classification. Final 11:45 cue lacks duration and blocks export pending clarification. | | ESTIVALES, CLOTURE | Five timing blocks. With the explicit `untimed_as_notes` policy, converts to five timers; all original continuation/direction rows remain in the IR and exported notes. This policy is a test scenario, not a confirmed interpretation from the owner. | | Plénière 2, Feuil1 | Both C and D are named TIMER and contain plausible durations. Returns `AMBIGUOUS_COLUMN`; parent-segment versus child-cue timing needs clarification. No automatic conversion is claimed. | +| GIFAV 2026 Auditorium | `Horaires` contains consistent parent-session start/end ranges and is detected as a combined Start–end column. `Durée` mixes child ranges with speaking/QA text, so it cannot be flattened into one duration role. Mapping Start–end to A and Title to D, retaining presentations as notes, validates Thursday with 11 entries and three gaps. Friday reaches schedule validation with 10 entries and three gaps, then correctly reports the source overlap between the 13:45–15:45 poster session and the 14:45–15:45 following session. | | Montage PDF | Text is extractable, but includes overlapping logistics tasks, missing durations and different locations. Not a single established timer sequence. | | Exploitation/démontage PDF | Text is extractable; page-spanning directions, simultaneous activities and untimed arrivals require track and row classification. PDF import remains a stretch goal. |