From 9a9be38af4834c96dc648d807ab9192ebc6ed654 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 5 Nov 2026 09:06:04 +0100 Subject: [PATCH] Use upper median for duration selection --- crates/rundown-converter/src/gui.rs | 4 ++-- crates/rundown-converter/src/model.rs | 2 +- crates/rundown-converter/src/time.rs | 8 +++----- crates/rundown-converter/tests/conversion.rs | 9 +++++---- docs/rundown-converter-plan.md | 2 +- docs/rundown-converter.md | 9 +++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/rundown-converter/src/gui.rs b/crates/rundown-converter/src/gui.rs index cfc00ab..8b0ceee 100644 --- a/crates/rundown-converter/src/gui.rs +++ b/crates/rundown-converter/src/gui.rs @@ -86,7 +86,7 @@ fn duration_mode_label(mode: &str) -> &'static str { match mode { "minimum" => "Minimum", "maximum" => "Maximum", - "median" => "Median", + "median" => "Upper median", "sum" => "Sum", _ => "Use the whole cell", } @@ -126,7 +126,7 @@ fn duration_handling_controls(ui: &mut egui::Ui, profile: &mut Profile, id: egui ("strict", "Use the whole cell"), ("minimum", "Minimum"), ("maximum", "Maximum"), - ("median", "Median"), + ("median", "Upper median"), ("sum", "Sum"), ] { ui.selectable_value(&mut mode, value.into(), label); diff --git a/crates/rundown-converter/src/model.rs b/crates/rundown-converter/src/model.rs index 70ebc0d..a4455b9 100644 --- a/crates/rundown-converter/src/model.rs +++ b/crates/rundown-converter/src/model.rs @@ -71,7 +71,7 @@ pub struct Profile { pub secondary_title_mode: Option, /// minutes, seconds, hh:mm, mm:ss, or excel. pub duration_unit: Option, - /// strict, minimum, maximum, median, sum, or margin (legacy split is accepted). + /// strict, minimum, maximum, median (upper median), sum, or margin (legacy split is accepted). pub duration_mode: Option, /// Separator used by split mode. Escaped forms such as \\n and \\t are accepted. pub duration_separator: Option, diff --git a/crates/rundown-converter/src/time.rs b/crates/rundown-converter/src/time.rs index cdc5b3d..9157523 100644 --- a/crates/rundown-converter/src/time.rs +++ b/crates/rundown-converter/src/time.rs @@ -221,11 +221,9 @@ pub fn select_durations( let mut sorted = values; sorted.sort_unstable(); let middle = sorted.len() / 2; - let value = if sorted.len().is_multiple_of(2) { - (sorted[middle - 1] + sorted[middle]) / 2 - } else { - sorted[middle] - }; + // Upper median: retain a source value, choosing the higher middle + // duration when there are an even number of values. + let value = sorted[middle]; SelectedDurations { events: vec![value], margin: 0, diff --git a/crates/rundown-converter/tests/conversion.rs b/crates/rundown-converter/tests/conversion.rs index 01974d2..f36f223 100644 --- a/crates/rundown-converter/tests/conversion.rs +++ b/crates/rundown-converter/tests/conversion.rs @@ -1661,10 +1661,11 @@ fn fixed_margin_requires_a_value_and_applies_to_overrides_and_derived_durations( } #[test] -fn median_duration_handles_odd_even_duplicates_and_single_values() { +fn upper_median_duration_handles_odd_even_duplicates_and_single_values() { for (text, expected) in [ ("20 min + 5 min + 10 min", 600_000), - ("20 min + 5 min", 750_000), + ("20 min + 5 min", 1_200_000), + ("40 min + 5 min + 20 min + 10 min", 1_200_000), ("20 min + 5 min + 5 min", 300_000), ("3 min", 180_000), ] { @@ -1682,7 +1683,7 @@ fn median_duration_handles_odd_even_duplicates_and_single_values() { } #[test] -fn median_is_applied_per_split_entry_with_independent_fixed_margins() { +fn upper_median_is_applied_per_split_entry_with_independent_fixed_margins() { let t = table(&[ &["Start", "Duration", "Title"], &["09:00", "20 min + 5 min + 10 min\n20 min + 5 min", "Talks"], @@ -1700,7 +1701,7 @@ fn median_is_applied_per_split_entry_with_independent_fixed_margins() { let r = a.rundown.unwrap(); assert_eq!( r.entries.iter().map(|e| e.duration_ms).collect::>(), - [600_000, 750_000] + [600_000, 1_200_000] ); assert_eq!(r.entries[1].start_ms, r.entries[0].end_ms + 30_000); assert_eq!(r.gaps.len(), 2); diff --git a/docs/rundown-converter-plan.md b/docs/rundown-converter-plan.md index 7225e5f..86195d5 100644 --- a/docs/rundown-converter-plan.md +++ b/docs/rundown-converter-plan.md @@ -297,7 +297,7 @@ errors must remain visible with direct corrective actions. 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, median and sum extraction policies, plus independent margin and split toggles. Let a Start mapping select + maximum, upper median and sum extraction policies, plus independent margin and split toggles. Let a Start mapping select only the first clock in a mixed range; retain margin gaps and split entries in the IR. - [x] Add a secondary title role with Either, Merge, Notes and Metadata handling, diff --git a/docs/rundown-converter.md b/docs/rundown-converter.md index ae09ee1..6351a6c 100644 --- a/docs/rundown-converter.md +++ b/docs/rundown-converter.md @@ -144,7 +144,7 @@ visually distinct from labels and ordinary actions; the active tab uses the stro 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, median or sum. + choice instead of extra column roles: whole cell, minimum, maximum, upper median or sum. Separate **Add margin** and **Split into multiple entries** toggles can be combined with that choice. Add margin takes an explicit positive duration (for example `2 min`) and adds that gap after every entry, including the last one; @@ -333,9 +333,10 @@ both titles empty still need correction. `duration_mode` is optional and remains attached to the single `duration` role. `minimum`, `maximum`, `median` and `sum` select from explicit duration values in mixed text. -Median selects the middle value after sorting; for an even count it averages -the two middle values (rounded down to a whole millisecond). With splitting, -it operates on each separated group independently. +**Upper median** selects the middle value after sorting; for an even count it +chooses the higher of the two middle values. For example, `5 min + 20 min` +selects 20 minutes. The profile key remains `median` for compatibility with saved +resolutions. With splitting, it operates on each separated group independently. `duration_add_margin: true` with `duration_margin: "2 min"` adds a two-minute untimed gap after each event. The value is independent of the source durations and selected operation; it also applies with Sum and whole-cell handling.