using Chronos.Core.Analysis; using Chronos.Core.Analysis.Deep; using Chronos.Core.Localization; using Chronos.Ui.Controls; namespace Chronos.App.Editor; /// A finding of the analyses on the Analysis step: what it says, the frame it starts at and the step that deals with it. public sealed class AnalysisFinding { private readonly EditorViewModel _editor; internal AnalysisFinding(EditorViewModel editor, FindingItem item, string? stepKey) { _editor = editor; Kind = item.Kind; Text = item.Text; Frame = item.Frame; StepKey = stepKey; } public StatusKind Kind { get; } public string Text { get; } /// The first frame it concerns; null for a finding about the whole sequence. public int? Frame { get; } /// The step that deals with it; null when no step does. public string? StepKey { get; } /// The step that deals with it (looked up when shown: the steps exist once the editor does). public EditorTab? Step => StepKey is null ? null : _editor.Tabs.FirstOrDefault(t => t.Key == StepKey); /// "Open Exposure, the step that deals with this ยท Alt+3". public string? GoToToolTip => Step is { } step ? Loc.L("Tooltips.Editor.Analysis.GoTo", step.Header, step.Number) : null; /// The sentence (what UI Automation reads for a row the list has not realised). public override string ToString() => Text; } /// /// The first step of the Edit path (owner review 1, R7): every finding of the analyses with the step that deals with it, /// what the deep analysis measured (light, flicker, exposure steps received, shake, flagged frames) and where each later /// step stands. Analyse runs from here as from the header. /// public sealed class AnalysisTab : EditorTab { private IReadOnlyList _findings = []; private AnalysisFinding? _selected; public AnalysisTab(EditorViewModel editor) : base(editor, EditPath.Analysis, null) { Rows = [ new InfoRow("Editor.Analysis.Light", "Tooltips.Editor.Analysis.Light", () => Measured(d => LightText(d.Sky.Light))), // The finding's and the deflicker reason's measure (the deviation from the smooth course), rounded as they are. new InfoRow("Editor.Analysis.Flicker", "Tooltips.Editor.Analysis.Flicker", () => Measured(d => Loc.L("Editor.Value.Ev", double.Round(d.Flicker.AmplitudeEv, 3, MidpointRounding.AwayFromZero).ToString("0.###", Loc.Culture)))), new InfoRow("Editor.Analysis.Steps", "Tooltips.Editor.Analysis.Steps", () => Measured(d => Loc.L("Editor.Analysis.StepsValue", d.Exposure.ReceivedSteps, d.Exposure.MetadataSteps))), new InfoRow("Editor.Analysis.Shake", "Tooltips.Editor.Analysis.Shake", ShakeValue), new InfoRow("Editor.Analysis.Flagged", "Tooltips.Editor.Analysis.Flagged", () => Measured(d => Loc.Plural("Editor.Value.Frames", d.Issues.Excludable().Length))), ]; Load(); Refresh(); } /// The findings, the most severe first. public IReadOnlyList Findings { get => _findings; private set { if (Set(ref _findings, value)) OnPropertyChanged(nameof(HasFindings)); } } public bool HasFindings => _findings.Count > 0; /// The finding chosen in the list: the preview seeks its first frame. public AnalysisFinding? SelectedFinding { get => _selected; set { if (!Set(ref _selected, value) || value?.Frame is not { } frame) return; Editor.CurrentIndex = frame; } } /// Instead of an empty list: the analysis running, not run yet, or nothing found. public string EmptyText => StateText.Length > 0 && Status == StepStatus.Running ? StateText : Editor.Session.Content.Deep is null ? Loc.L("Editor.Chart.NotAnalysed") : Loc.L("Editor.Frames.NoWarnings"); /// The glyph beside the step's state in its panel. public StatusKind StateKind => Status switch { StepStatus.Done => StatusKind.Analysed, StepStatus.Running => StatusKind.Analysing, StepStatus.Attention => StatusKind.Warning, _ => StatusKind.NotAnalysed, }; /// The path's other steps, each with where it stands. public IEnumerable PathSteps => Editor.Tabs.Where(t => !ReferenceEquals(t, this)); public override bool PrefersTallMeasure => true; public override void OnContentChanged() { Load(); base.OnContentChanged(); } /// The step's state changed: the panel's glyph and the empty list's sentence follow. internal void OnStepChanged() { OnPropertyChanged(nameof(StateKind)); OnPropertyChanged(nameof(EmptyText)); } private void Load() { Findings = [.. Editor.Session.Advice.Findings.OrderByDescending(f => f.Severity) .Select(f => new AnalysisFinding(Editor, FramesTab.ToItem(f), EditPath.StepOf(f.Key)))]; _selected = null; OnPropertyChanged(nameof(SelectedFinding)); OnPropertyChanged(nameof(EmptyText)); } /// The camera's wobble, or n/a when too few frame pairs could be measured (the Motion step asks for it then). private (string? Value, string? NotApplicableReason) ShakeValue() { if (Editor.Session.Content.Deep is { Shake: { MeasuredFraction: < ShakeSummary.MinMeasuredFraction } shake }) return (null, Loc.L("Advisor.Missing.Shake", (100 * shake.MeasuredFraction).ToString("0", Loc.Culture))); return Measured(d => Loc.L("Editor.Value.Pixels", d.Shake.RmsPx.ToString("0.#", Loc.Culture))); } /// A value of the deep analysis, or n/a saying it needs the analysis. private (string? Value, string? NotApplicableReason) Measured(Func value) => Editor.Session.Content.Deep is { } deep ? (value(deep), null) : (null, Loc.L("Tooltips.Editor.NotApplicable.NeedsAnalysis")); private static string LightText(DayNight light) => Loc.L(light switch { DayNight.Day => "Editor.Analysis.Light.Day", DayNight.Night => "Editor.Analysis.Light.Night", DayNight.DayToNight => "Editor.Analysis.Light.DayToNight", DayNight.NightToDay => "Editor.Analysis.Light.NightToDay", _ => "Editor.Analysis.Light.Unknown", }); }