Use upper median for duration selection

This commit is contained in:
Dandaedre 2026-11-05 09:06:04 +01:00
parent c663f32ccc
commit 9a9be38af4
6 changed files with 17 additions and 17 deletions

View File

@ -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);

View File

@ -71,7 +71,7 @@ pub struct Profile {
pub secondary_title_mode: Option<String>,
/// minutes, seconds, hh:mm, mm:ss, or excel.
pub duration_unit: Option<String>,
/// 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<String>,
/// Separator used by split mode. Escaped forms such as \\n and \\t are accepted.
pub duration_separator: Option<String>,

View File

@ -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,

View File

@ -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::<Vec<_>>(),
[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);

View File

@ -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,

View File

@ -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.