From c0e9f8e2f4a0fdc1a6743824dfd3eaf4cb7ed180 Mon Sep 17 00:00:00 2001 From: Oleg <18466855+EvaTheSalmon@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:29:32 +0300 Subject: [PATCH] feat(export): pick a range by stored markers (#160) Exporting one recipe meant reading its start and end off the chart and typing both into the export window. The SCADA now stores recipe markers, but the export could use neither them nor the operator's markers. Each range edge now has a date line and a line with its time and a marker box. The start box offers user and recipe-start markers of the selected day; the end box offers user, recipe-end and interrupted markers strictly after the start. Choosing a marker writes its date and time, while a hand edit or a date change releases it. A labelled start marker also supplies the suggested CSV file name. The marker lists keep stable collection instances so ComboBox selections survive updates. The end is rounded to the next second because export slices exclude their end bound. Documentation covers the new controls, rounding and file-name rules. Co-Authored-By: Claude Code --- .../UI/Export/CsvExportStand.cs | 12 +- .../UI/Export/CsvExportViewModelTests.cs | 46 ++ .../UI/Export/CsvExportWindowTests.cs | 575 +++++++++++++++++- .../UI/Export/ExportFileNameTests.cs | 93 +++ .../UI/Export/ExportMarkerChoiceTests.cs | 468 ++++++++++++++ .../UI/MainWindow/MainWindowViewModelTests.cs | 27 + SemiPlot/SemiPlot.UI/Chart/ChartMarkers.cs | 6 + .../SemiPlot.UI/Export/CsvExportViewModel.cs | 235 ++++++- .../SemiPlot.UI/Export/CsvExportWindow.axaml | 106 +++- .../Export/CsvExportWindow.axaml.cs | 5 +- .../SemiPlot.UI/Export/CsvFileExporter.cs | 10 - SemiPlot/SemiPlot.UI/Export/ExportFileName.cs | 61 ++ .../SemiPlot.UI/Export/ExportMarkerChoice.cs | 71 +++ .../SemiPlot.UI/Localization/Resources.resx | 6 + .../Localization/Resources.ru.resx | 6 + .../MainWindow/MainWindowViewModel.cs | 10 +- .../SemiPlot.UI/MainWindow/TrendWindow.cs | 5 +- .../Navigation/WallClockRangeForm.cs | 72 ++- docs/architecture/charting.md | 2 +- docs/architecture/overview.md | 18 +- docs/architecture/ui-text.md | 10 +- docs/architecture/ui-theme.md | 72 ++- .../20261028-export-range-by-markers.md | 380 ++++++++++++ readme.md | 5 +- 24 files changed, 2169 insertions(+), 132 deletions(-) create mode 100644 SemiPlot/SemiPlot.Tests.Unit/UI/Export/ExportFileNameTests.cs create mode 100644 SemiPlot/SemiPlot.Tests.Unit/UI/Export/ExportMarkerChoiceTests.cs create mode 100644 SemiPlot/SemiPlot.UI/Export/ExportFileName.cs create mode 100644 SemiPlot/SemiPlot.UI/Export/ExportMarkerChoice.cs create mode 100644 docs/plans/completed/20261028-export-range-by-markers.md diff --git a/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportStand.cs b/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportStand.cs index 5ea5041..fc82786 100644 --- a/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportStand.cs +++ b/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportStand.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging.Abstractions; +using SemiPlot.Core.Data; using SemiPlot.Core.Export; using SemiPlot.Core.Trends; using SemiPlot.UI.Export; @@ -25,13 +26,19 @@ internal static class CsvExportStand public static readonly Pen Argon = new(3, "Argon flow", [], "#FF7F0E", "sccm"); public static readonly Pen Power = new(12, "Bias power", [], "#2CA02C"); + public static DateTime ToUtc(DateTime wallClock) + { + return DateTime.SpecifyKind(wallClock - PlusThree.BaseUtcOffset, DateTimeKind.Utc); + } + public static CsvExportViewModel Build( FakeArchiveRowReader reader, MessagePanelViewModel messagePanel, IScheduler uiScheduler, IReadOnlyList pens, DateTime? newestSampleUtc = null, - Func>>>? readArchiveDays = null) + Func>>>? readArchiveDays = null, + IReadOnlyList? markers = null) { return new CsvExportViewModel( reader, @@ -45,6 +52,7 @@ public static CsvExportViewModel Build( StartUtc.AddHours(1), FirstSampleUtc, newestSampleUtc, - pens); + pens, + markers ?? []); } } diff --git a/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportViewModelTests.cs b/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportViewModelTests.cs index 41d3cb5..3cdeb48 100644 --- a/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportViewModelTests.cs +++ b/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportViewModelTests.cs @@ -729,6 +729,52 @@ public async Task APartialFileThatCannotBeDeleted_IsNamedInTheReportedFailure() .Which.View.Detail.Should().Contain(partialPath); } + [AvaloniaFact] + public void TheSuggestedName_FollowsTheStartBoxsChoice() + { + var markerWallClock = _startWallClock.AddMinutes(20).AddSeconds(15).AddMilliseconds(400); + var marker = new StoredMarker( + 1, CsvExportStand.ToUtc(markerWallClock), "RecipeName.csv", MarkerKind.RecipeStart); + var unlabelled = new StoredMarker(2, CsvExportStand.ToUtc(markerWallClock), null, MarkerKind.User); + using var viewModel = CsvExportStand.Build( + _reader, + _messagePanel, + _scheduler, + [new ExportPenChoice(CsvExportStand.Pressure, true)], + markers: [marker, unlabelled]); + + viewModel.SuggestedFileName().Should().Be("semiplot_20261013_080000-20261013_090000.csv"); + + viewModel.SelectedStartMarker = viewModel.StartMarkers[0]; + + viewModel.SuggestedFileName().Should().Be("RecipeName_2026-10-13_08-20.csv"); + + viewModel.SelectedStartMarker = viewModel.StartMarkers[1]; + + viewModel.SuggestedFileName() + .Should().Be("semiplot_20261013_082015-20261013_090000.csv", "an unlabelled marker names nothing"); + + viewModel.SelectedStartMarker = viewModel.StartMarkers[0]; + viewModel.SelectedStartMarker = viewModel.StartChoices[0]; + + viewModel.SuggestedFileName() + .Should().Be("semiplot_20261013_082015-20261013_090000.csv", "no marker keeps the range name"); + + viewModel.SelectedStartMarker = viewModel.StartMarkers[0]; + viewModel.Form.StartTimeText = "08:20:16"; + + viewModel.SuggestedFileName().Should().Be("semiplot_20261013_082016-20261013_090000.csv"); + + viewModel.Form.StartTimeText = "08:20:15"; + + viewModel.SuggestedFileName() + .Should().Be("semiplot_20261013_082015-20261013_090000.csv", "a typed time names nothing, the box does"); + + viewModel.Form.StartTimeText = "08:20"; + + viewModel.SuggestedFileName().Should().BeNull("an invalid range proposes no name"); + } + private CsvExportViewModel BuildNamesakes(bool secondIsTicked) { SetSlices(call => call.From == _startWallClock diff --git a/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportWindowTests.cs b/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportWindowTests.cs index 0c93652..161bbad 100644 --- a/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportWindowTests.cs +++ b/SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportWindowTests.cs @@ -8,6 +8,8 @@ using Avalonia.Input; using Avalonia.Layout; using Avalonia.Media; +using Avalonia.Platform; +using Avalonia.Threading; using Avalonia.VisualTree; using AwesomeAssertions; @@ -16,6 +18,8 @@ using Microsoft.Reactive.Testing; +using ReactiveUI.Avalonia; + using SemiPlot.Core.Data; using SemiPlot.Core.Data.Errors; using SemiPlot.UI; @@ -24,6 +28,8 @@ using SemiPlot.UI.Messages; using SemiPlot.UI.Startup; +using SkiaSharp; + using Xunit; using static SemiPlot.Tests.Unit.UI.ViewProbe; @@ -552,26 +558,51 @@ public void TheMessageRow_SitsAboveTheButtons_AndSpansTheContentWidth() } } - [AvaloniaFact] - public void EachRangeRow_PutsTheTimeBoxLeftOfTheDatePicker_AndTheTabOrderFollows() + [AvaloniaTheory] + [InlineData("ru")] + [InlineData("en")] + public void EachEdge_PutsTheDateOverTheTimeAndTheMarkerBox_AndTheTabOrderFollows(string culture) { - using var viewModel = Build(); + using var cultureScope = new CultureScope(culture); + using var viewModel = BuildWithMarkers(); var window = Realise(new CsvExportWindow { DataContext = viewModel }); try { - foreach (var (time, date) in new[] { ("ExportStartTime", "ExportStartDate"), ("ExportEndTime", "ExportEndDate") }) + foreach (var (label, date, time, marker) in new[] + { + (Resources.ExportStartLabel, "ExportStartDate", "ExportStartTime", "ExportStartMarker"), + (Resources.ExportEndLabel, "ExportEndDate", "ExportEndTime", "ExportEndMarker") + }) { - var timeBox = Named(window, time); + var labelBlock = window.GetVisualDescendants().OfType().Single(block => block.Text == label); var datePicker = Named(window, date); - - RightOf(window, timeBox).Should().BeLessThan(LeftOf(window, datePicker), time); - timeBox.Bounds.Top.Should().Be(datePicker.Bounds.Top, "one row holds both"); + var timeBox = Named(window, time); + var markerBox = Named(window, marker); + + LeftOf(window, timeBox).Should().Be(LeftOf(window, datePicker), time); + timeBox.Bounds.Width.Should().Be(110, time); + (LeftOf(window, markerBox) - RightOf(window, timeBox)).Should().Be(8, marker); + RightOf(window, markerBox).Should().Be(RightOf(window, datePicker), marker); + (TopOf(window, timeBox) - BottomOf(window, datePicker)).Should().Be(10, "the second line is 10 px under"); + TopOf(window, markerBox).Should().Be(TopOf(window, timeBox), "one line holds both"); + CentreOf(window, labelBlock).Should().Be(CentreOf(window, datePicker), "the label is centred on the date"); + new Control[] { datePicker, timeBox, markerBox } + .Should().OnlyContain(control => control.Bounds.Height == 32, "the controls keep Semi's height"); } + (TopOf(window, Named(window, "ExportEndDate")) + - BottomOf(window, Named(window, "ExportStartMarker"))) + .Should().Be(20, "the edges stand 20 px apart"); + + string[] edgeControls = + [ + "ExportStartDate", "ExportStartTime", "ExportStartMarker", + "ExportEndDate", "ExportEndTime", "ExportEndMarker" + ]; var order = window.GetVisualDescendants().OfType() .Select(control => control.Name) - .Where(name => name is "ExportStartTime" or "ExportStartDate" or "ExportEndTime" or "ExportEndDate"); - order.Should().Equal("ExportStartTime", "ExportStartDate", "ExportEndTime", "ExportEndDate"); + .Where(name => edgeControls.Contains(name)); + order.Should().Equal(edgeControls); } finally { @@ -579,18 +610,24 @@ public void EachRangeRow_PutsTheTimeBoxLeftOfTheDatePicker_AndTheTabOrderFollows } } - [AvaloniaFact] - public void TheListAndTheMessage_EndAtTheRightEdgeOfTheDatePickers() + [AvaloniaTheory] + [InlineData("ru")] + [InlineData("en")] + public void TheDatesTheMarkerBoxesTheListAndTheMessage_EndAtOneRightEdge(string culture) { - using var viewModel = Build(); + using var cultureScope = new CultureScope(culture); + using var viewModel = BuildWithMarkers(); var window = Realise(new CsvExportWindow { DataContext = viewModel }); try { var edge = RightOf(window, Named(window, "ExportStartDate")); RightOf(window, Named(window, "ExportEndDate")).Should().Be(edge); + RightOf(window, Named(window, "ExportStartMarker")).Should().Be(edge); + RightOf(window, Named(window, "ExportEndMarker")).Should().Be(edge); RightOf(window, Named(window, "ExportPens")).Should().Be(edge); RightOf(window, Named(window, "ExportMessage")).Should().Be(edge); + edge.Should().Be(370); window.Width.Should().Be(edge + 20, "the margin is the only space right of the form"); } finally @@ -666,7 +703,7 @@ public async Task WhileAnExportRuns_SaveAsIsDisabledAndCancelIsEnabled_AndTheRev return Result.Ok>([]); } }; - using var viewModel = Build(reader); + using var viewModel = BuildWithMarkers(reader); var window = Realise(new CsvExportWindow { DataContext = viewModel }); try { @@ -682,7 +719,9 @@ public async Task WhileAnExportRuns_SaveAsIsDisabledAndCancelIsEnabled_AndTheRev { Named(window, "ExportStartDate"), Named(window, "ExportEndTime"), - Named(window, "ExportPens") + Named(window, "ExportPens"), + Named(window, "ExportStartMarker"), + Named(window, "ExportEndMarker") }; formControls.Should().OnlyContain( control => !control.IsEffectivelyEnabled, "the form is frozen while it exports"); @@ -746,17 +785,452 @@ public async Task AfterASuccess_TheMessageLineToolTipIsTheFullPath() } } + [AvaloniaFact] + public async Task ChoosingAStartAndAnEndMarker_FillsBothEdges_AndTheCountAndTheExportReadThatSpan() + { + using var directory = new TemporaryDirectory("csv-export-markers"); + var reader = new FakeArchiveRowReader(); + using var viewModel = BuildWithMarkers(reader); + var window = Realise(new CsvExportWindow { DataContext = viewModel }); + try + { + var startBox = Named(window, "ExportStartMarker"); + var endBox = Named(window, "ExportEndMarker"); + + HeadlessInput.Pick(window, startBox, viewModel.StartMarkers.Single()); + HeadlessInput.Pick(window, endBox, viewModel.EndMarkers.Single()); + + Named(window, "ExportStartTime").Text.Should().Be("08:15:00"); + Named(window, "ExportEndTime").Text + .Should().Be("08:45:01", "the end keeps every row of its second"); + Named(window, "ExportStartDate").SelectedDate.Should().Be(_startDay); + Named(window, "ExportEndDate").SelectedDate.Should().Be(_startDay); + ShownText(startBox).Should().Be("Etch.csv", "the time box beside it shows the time"); + ShownText(endBox).Should().Be("Etch.csv"); + viewModel.Form.IsValid.Should().BeTrue(); + Named