Add reversible gap allocation choices to review and conversion
This commit is contained in:
parent
58aeb56a36
commit
5e3d3236b7
|
|
@ -64,6 +64,7 @@ struct PreviewRow {
|
|||
decisions: String,
|
||||
kind: String,
|
||||
gap: bool,
|
||||
gap_key: Option<String>,
|
||||
}
|
||||
|
||||
/// Combine timed draft entries and omitted problem rows without changing the IR.
|
||||
|
|
@ -100,6 +101,7 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
decisions: e.decisions.join("\n"),
|
||||
kind: e.kind.clone(),
|
||||
gap: false,
|
||||
gap_key: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -158,12 +160,14 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
.collect(),
|
||||
decisions: String::new(),
|
||||
gap: false,
|
||||
gap_key: None,
|
||||
kind: a
|
||||
.rundown
|
||||
.as_ref()
|
||||
.and_then(|r| {
|
||||
if r.gaps
|
||||
.iter()
|
||||
.chain(&r.resolved_gaps)
|
||||
.any(|g| g.source_rows.iter().any(|s| s.row == row))
|
||||
{
|
||||
return Some("Gap · no timer".into());
|
||||
|
|
@ -182,11 +186,16 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
if let Some(gap) = rundown
|
||||
.gaps
|
||||
.iter()
|
||||
.chain(&rundown.resolved_gaps)
|
||||
.find(|g| g.source_rows.iter().any(|s| s.row == row.row))
|
||||
{
|
||||
row.start = gap.start_ms.map(display).unwrap_or_else(|| "?".into());
|
||||
row.end = gap.end_ms.map(display).unwrap_or_else(|| "?".into());
|
||||
row.gap = true;
|
||||
row.gap_key = Some(gap.key());
|
||||
if rundown.resolved_gaps.iter().any(|g| g.key() == gap.key()) {
|
||||
row.kind = "Allocated gap · included in adjacent timer".into();
|
||||
}
|
||||
row.duration = gap
|
||||
.start_ms
|
||||
.zip(gap.end_ms)
|
||||
|
|
@ -197,7 +206,14 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
}
|
||||
rows.sort_by_key(|r| r.row);
|
||||
if let Some(rundown) = &a.rundown {
|
||||
for gap in rundown.gaps.iter().filter(|gap| gap.source_rows.is_empty()) {
|
||||
let mut gaps: Vec<_> = rundown
|
||||
.gaps
|
||||
.iter()
|
||||
.chain(&rundown.resolved_gaps)
|
||||
.filter(|gap| gap.source_rows.is_empty())
|
||||
.collect();
|
||||
gaps.sort_by_key(|gap| gap.start_ms);
|
||||
for gap in gaps {
|
||||
let position = rows
|
||||
.iter()
|
||||
.position(|row| {
|
||||
|
|
@ -212,12 +228,17 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec<PreviewRow> {
|
|||
start: gap.start_ms.map(display).unwrap_or_else(|| "?".into()),
|
||||
end: gap.end_ms.map(display).unwrap_or_else(|| "?".into()),
|
||||
duration: gap.start_ms.zip(gap.end_ms).map(|(start, end)| display(end - start)).unwrap_or_else(|| "?".into()),
|
||||
title: gap.title.clone(),
|
||||
title: if rundown.resolved_gaps.iter().any(|g| g.key() == gap.key()) {
|
||||
"Allocated gap · included in adjacent timer".into()
|
||||
} else { gap.title.clone() },
|
||||
source_only: true,
|
||||
issues: a.diagnostics.iter().enumerate().filter(|(_, d)| d.location == format!("{} gap {:?}–{:?}", rundown.title, gap.after_row, gap.before_row)).map(|(i, _)| i).collect(),
|
||||
decisions: "Unallocated time between scheduled events. This interval does not display a timer; clarify nearby unresolved rows to explain it.".into(),
|
||||
kind: "Gap · no timer".into(),
|
||||
decisions: "Keep the interval untimed, extend the previous event to its end, or start the next event at its beginning. Recheck to apply the choice.".into(),
|
||||
kind: if rundown.resolved_gaps.iter().any(|g| g.key() == gap.key()) {
|
||||
"Allocated gap · included in adjacent timer".into()
|
||||
} else { "Gap · no timer".into() },
|
||||
gap: true,
|
||||
gap_key: Some(gap.key()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -613,7 +634,7 @@ impl App {
|
|||
ui.horizontal_wrapped(|ui| {
|
||||
ui.colored_label(PREVIEW_AMBER, "Unresolved");
|
||||
ui.colored_label(PREVIEW_RED, "Error");
|
||||
ui.colored_label(PREVIEW_GAP, "Gap · no timer");
|
||||
ui.colored_label(PREVIEW_GAP, "Gap / allocated interval");
|
||||
ui.weak("Ignored");
|
||||
ui.small("? unknown · * inferred · edits require recheck");
|
||||
});
|
||||
|
|
@ -799,8 +820,22 @@ impl App {
|
|||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(105.0);
|
||||
if row.row == 0 {
|
||||
ui.small("Inferred gap").on_hover_text("No source row to edit. Resolve adjacent rows and recheck to update this interval. Duration is elapsed time, not a timer.");
|
||||
if let Some(key) = &row.gap_key {
|
||||
let mut action = profile.gap_resolutions.get(key).cloned().unwrap_or_else(|| "keep".into());
|
||||
egui::ComboBox::from_id_salt(("gap_resolution", key))
|
||||
.width(95.0)
|
||||
.selected_text(match action.as_str() {
|
||||
"extend_previous" => "Extend prev.",
|
||||
"add_to_next" => "Add to next",
|
||||
_ => "Keep gap",
|
||||
})
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut action, "keep".into(), "Keep gap");
|
||||
ui.selectable_value(&mut action, "extend_previous".into(), "Extend previous timing");
|
||||
ui.selectable_value(&mut action, "add_to_next".into(), "Add to next timing");
|
||||
}).response.on_hover_text("Keep gap leaves this interval untimed. Extend previous timing lengthens the preceding event. Add to next timing starts the next event earlier and preserves its end. Apply & recheck updates the schedule and export.");
|
||||
if action == "keep" { profile.gap_resolutions.remove(key); }
|
||||
else { profile.gap_resolutions.insert(key.clone(), action); }
|
||||
return;
|
||||
}
|
||||
ui.push_id(("schedule_kind", row.row), |ui| {
|
||||
|
|
@ -1012,8 +1047,35 @@ mod tests {
|
|||
configure_style(&ctx);
|
||||
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 == "Inferred gap"));
|
||||
assert!(labels.iter().any(|(s, _)| s == "Keep gap"));
|
||||
assert!(!app.dirty);
|
||||
let button = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Keep gap")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, button, [860.0, 900.0]);
|
||||
let menu = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
let next = menu
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Add to next timing")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, next, [860.0, 900.0]);
|
||||
assert!(app.dirty);
|
||||
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
|
||||
assert_eq!(
|
||||
profile.gap_resolutions.values().next().unwrap(),
|
||||
"add_to_next"
|
||||
);
|
||||
let a = pipeline::analyze(&app.tables[0], &profile, &AtomicBool::new(false), |_, _| {});
|
||||
assert!(a.rundown.as_ref().unwrap().gaps.is_empty());
|
||||
let rows = preview_rows(&a, Some(&app.tables[0]));
|
||||
let resolved = rows.iter().find(|r| r.gap).unwrap();
|
||||
assert!(resolved.kind.starts_with("Allocated gap"));
|
||||
assert!(resolved.gap_key.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ pub struct Profile {
|
|||
pub row_kinds: BTreeMap<usize, String>,
|
||||
/// Explicit duration overrides, expressed with units (e.g. 2 min).
|
||||
pub durations: BTreeMap<usize, String>,
|
||||
/// Exact gap key -> keep, extend_previous, or add_to_next.
|
||||
pub gap_resolutions: BTreeMap<String, String>,
|
||||
}
|
||||
impl Profile {
|
||||
pub fn usage(&self, col: usize) -> Option<&str> {
|
||||
|
|
@ -123,6 +125,14 @@ pub struct Gap {
|
|||
pub source_rows: Vec<SourceRow>,
|
||||
pub display_timer: bool,
|
||||
}
|
||||
impl Gap {
|
||||
pub fn key(&self) -> String {
|
||||
format!(
|
||||
"{:?}:{:?}:{:?}:{:?}",
|
||||
self.after_row, self.before_row, self.start_ms, self.end_ms
|
||||
)
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Rundown {
|
||||
pub schema_version: u32,
|
||||
|
|
@ -130,6 +140,9 @@ pub struct Rundown {
|
|||
pub mapping: Mapping,
|
||||
pub entries: Vec<Entry>,
|
||||
pub gaps: Vec<Gap>,
|
||||
/// Original intervals absorbed into event timing, retained for review/undo.
|
||||
#[serde(default)]
|
||||
pub resolved_gaps: Vec<Gap>,
|
||||
pub decisions: Vec<String>,
|
||||
}
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ pub fn construct(
|
|||
mapping: map.clone(),
|
||||
entries: vec![],
|
||||
gaps: vec![],
|
||||
resolved_gaps: vec![],
|
||||
decisions: vec![],
|
||||
};
|
||||
let mut errors = vec![];
|
||||
|
|
@ -453,8 +454,91 @@ pub fn construct(
|
|||
}
|
||||
}
|
||||
result.gaps = gaps;
|
||||
errors.extend(resolve_gaps(&mut result, profile));
|
||||
(result, errors)
|
||||
}
|
||||
/// Apply explicit gap choices only to contiguous timed events. Recompute from source
|
||||
/// on every analysis, so changing a choice never accumulates timing adjustments.
|
||||
fn resolve_gaps(rundown: &mut Rundown, profile: &Profile) -> Vec<Diagnostic> {
|
||||
let mut errors = Vec::new();
|
||||
for (key, action) in &profile.gap_resolutions {
|
||||
if !matches!(action.as_str(), "keep" | "extend_previous" | "add_to_next")
|
||||
|| !rundown.gaps.iter().any(|gap| gap.key() == *key)
|
||||
{
|
||||
errors.push(Diagnostic::new(3, "INVALID_GAP_RESOLUTION", &rundown.title,
|
||||
format!("Gap resolution {key} is stale or has an unknown action. Remove it from gap_resolutions in Setup, or reset decisions and recheck.")));
|
||||
}
|
||||
}
|
||||
for action in ["extend_previous", "add_to_next"] {
|
||||
rundown.gaps.sort_by_key(|gap| gap.start_ms);
|
||||
if action == "add_to_next" {
|
||||
rundown.gaps.reverse();
|
||||
}
|
||||
let mut retained = Vec::new();
|
||||
for gap in std::mem::take(&mut rundown.gaps) {
|
||||
if profile.gap_resolutions.get(&gap.key()).map(String::as_str) != Some(action) {
|
||||
retained.push(gap);
|
||||
continue;
|
||||
}
|
||||
let location = format!(
|
||||
"{} gap {:?}–{:?}",
|
||||
rundown.title, gap.after_row, gap.before_row
|
||||
);
|
||||
let bounds = gap.start_ms.zip(gap.end_ms).filter(|(s, e)| e > s);
|
||||
let target = bounds.and_then(|(start, end)| {
|
||||
if rundown
|
||||
.entries
|
||||
.iter()
|
||||
.any(|e| e.kind == "event" && e.start_ms < end && e.end_ms > start)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let candidates: Vec<_> = rundown
|
||||
.entries
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, e)| {
|
||||
e.kind == "event"
|
||||
&& if action == "extend_previous" {
|
||||
e.end_ms == start
|
||||
} else {
|
||||
e.start_ms == end
|
||||
}
|
||||
})
|
||||
.map(|(i, _)| i)
|
||||
.collect();
|
||||
(candidates.len() == 1).then(|| candidates[0])
|
||||
});
|
||||
if let Some(index) = target {
|
||||
let (start, end) = bounds.unwrap();
|
||||
let event = &mut rundown.entries[index];
|
||||
if action == "extend_previous" {
|
||||
event.end_ms = end;
|
||||
} else {
|
||||
event.start_ms = start;
|
||||
event.explicit_start = false;
|
||||
}
|
||||
event.duration_ms = event.end_ms - event.start_ms;
|
||||
event.decisions.push(format!(
|
||||
"Gap resolution {action}: absorbed {} ms from {} to {}",
|
||||
end - start,
|
||||
start,
|
||||
end
|
||||
));
|
||||
rundown.resolved_gaps.push(gap);
|
||||
} else {
|
||||
errors.push(Diagnostic::new(3, "GAP_RESOLUTION_UNAVAILABLE", location,
|
||||
"This gap needs positive, known boundaries and one adjacent timed event without overlap. Choose Keep gap or correct the neighboring timing."));
|
||||
retained.push(gap);
|
||||
}
|
||||
}
|
||||
rundown.gaps = retained;
|
||||
}
|
||||
rundown.gaps.sort_by_key(|gap| gap.start_ms);
|
||||
rundown.resolved_gaps.sort_by_key(|gap| gap.start_ms);
|
||||
errors
|
||||
}
|
||||
|
||||
/// Stage 4 validation is also invoked by every exporter.
|
||||
pub fn validate(r: &Rundown) -> Vec<Diagnostic> {
|
||||
let mut errors = vec![];
|
||||
|
|
|
|||
|
|
@ -709,3 +709,102 @@ fn column_usage_excludes_data_candidates_and_rejects_conflicting_profiles() {
|
|||
.any(|d| d.code == "INVALID_MAPPING")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gap_choices_adjust_adjacent_timers_and_can_be_reversed() {
|
||||
for named in [false, true] {
|
||||
let t = if named {
|
||||
table(&[
|
||||
&["Start", "Duration", "Title"],
|
||||
&["11:45", "15 min", "Morning"],
|
||||
&["", "", "Lunch break"],
|
||||
&["13:30", "20 min", "Afternoon"],
|
||||
])
|
||||
} else {
|
||||
simple()
|
||||
};
|
||||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||||
let key = baseline.gaps[0].key();
|
||||
for action in ["keep", "extend_previous", "add_to_next"] {
|
||||
let mut profile = Profile::default();
|
||||
profile.gap_resolutions.insert(key.clone(), action.into());
|
||||
// Profiles saved by either interface preserve the choice.
|
||||
let profile: Profile =
|
||||
serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
|
||||
let a = analyze(&t, &profile);
|
||||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||||
let r = a.rundown.unwrap();
|
||||
assert_eq!(r.entries.len(), 2);
|
||||
assert_eq!(r.gaps.len(), usize::from(action == "keep"));
|
||||
assert_eq!(r.resolved_gaps.len(), usize::from(action != "keep"));
|
||||
assert_eq!(r.entries[0].start_ms, baseline.entries[0].start_ms);
|
||||
assert_eq!(r.entries[1].end_ms, baseline.entries[1].end_ms);
|
||||
if action == "extend_previous" {
|
||||
assert_eq!(r.entries[0].end_ms, baseline.entries[1].start_ms);
|
||||
assert_eq!(r.entries[1].start_ms, baseline.entries[1].start_ms);
|
||||
} else if action == "add_to_next" {
|
||||
assert_eq!(r.entries[1].start_ms, baseline.entries[0].end_ms);
|
||||
assert_eq!(r.entries[0].end_ms, baseline.entries[0].end_ms);
|
||||
assert!(!r.entries[1].explicit_start);
|
||||
}
|
||||
let exported = export::ontime(&r).unwrap();
|
||||
for e in &r.entries {
|
||||
let timer = &exported["rundowns"]["default"]["entries"][&e.id];
|
||||
assert_eq!(timer["duration"], e.end_ms - e.start_ms);
|
||||
assert_eq!(timer["timeStart"], e.start_ms);
|
||||
}
|
||||
assert_eq!(
|
||||
serde_json::to_value(&r).unwrap(),
|
||||
serde_json::to_value(analyze(&t, &profile).rundown.unwrap()).unwrap()
|
||||
);
|
||||
}
|
||||
let restored = analyze(&t, &Profile::default()).rundown.unwrap();
|
||||
assert_eq!(
|
||||
serde_json::to_value(restored).unwrap(),
|
||||
serde_json::to_value(baseline).unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_or_unavailable_gap_choices_block_export() {
|
||||
let t = simple();
|
||||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||||
let mut profile = Profile::default();
|
||||
profile
|
||||
.gap_resolutions
|
||||
.insert(baseline.gaps[0].key(), "unknown".into());
|
||||
assert!(
|
||||
analyze(&t, &profile)
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|d| d.code == "INVALID_GAP_RESOLUTION")
|
||||
);
|
||||
profile.gap_resolutions = [("stale".into(), "extend_previous".into())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
assert!(
|
||||
analyze(&t, &profile)
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|d| d.code == "INVALID_GAP_RESOLUTION")
|
||||
);
|
||||
let t = table(&[
|
||||
&["Start", "Duration", "Title"],
|
||||
&["09:00", "30 min", "Lunch break"],
|
||||
&["09:30", "20 min", "Opening"],
|
||||
]);
|
||||
profile = Profile::default();
|
||||
profile.row_kinds.insert(2, "gap".into());
|
||||
let baseline = analyze(&t, &profile).rundown.unwrap();
|
||||
profile.gap_resolutions = [(baseline.gaps[0].key(), "extend_previous".into())]
|
||||
.into_iter()
|
||||
.collect();
|
||||
let a = analyze(&t, &profile);
|
||||
assert!(
|
||||
a.diagnostics
|
||||
.iter()
|
||||
.any(|d| d.code == "GAP_RESOLUTION_UNAVAILABLE")
|
||||
);
|
||||
assert_eq!(a.rundown.unwrap().gaps.len(), 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,15 @@ click **Analyze rundown**. Review has two views:
|
|||
parent timer instead of duplicating it. Amber means unresolved, red means an
|
||||
error, gray means ignored, and teal marks gaps. Gaps appear in schedule order
|
||||
with their start, end and elapsed duration (no timer). Named breaks use their
|
||||
source row; inferred gaps have no editable source row and update after recheck.
|
||||
source row; inferred gaps update after recheck. Each gap offers **Keep gap**
|
||||
(default, no timer), **Extend previous timing** (extend the preceding event's end),
|
||||
or **Add to next timing** (start the following event earlier, keeping its end).
|
||||
Apply & recheck updates durations and Ontime output. Allocated intervals remain
|
||||
in the preview for review and undo; choose Keep gap to restore original timings.
|
||||
The selected event must touch the gap, and unresolved/overlapping intervals
|
||||
cannot be absorbed. Choices are saved in resolution profiles as `gap_resolutions`,
|
||||
keyed by exact gap boundaries. If other corrections change those boundaries,
|
||||
remove the stale choice in Setup or reset decisions and recheck.
|
||||
Unknown values show `?`.
|
||||
Hover over a title or issue button for row status and full diagnostic explanations.
|
||||
Double-click a row number/title to read all original cells. **Issues** opens the issue
|
||||
|
|
|
|||
Loading…
Reference in New Issue