-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMainWindow.IoTesting.Progress.cs
More file actions
93 lines (75 loc) · 3.73 KB
/
Copy pathMainWindow.IoTesting.Progress.cs
File metadata and controls
93 lines (75 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2026 Ari Sulistiono
// SPDX-License-Identifier: Apache-2.0
using ArIED61850Tester.Models.IoTesting;
namespace ArIED61850Tester;
public partial class MainWindow
{
internal IoFatPreparationProgressSnapshot GetIoFatPreparationProgressSnapshot(IoTestIedPlan ied)
{
ArgumentNullException.ThrowIfNull(ied);
var device = ResolveIoTestDevice(ied.LiveDeviceId)
?? ResolveIoTestDevice(ied.IpAddress)
?? ResolveIoTestDevice(ied.IedName);
var message = string.IsNullOrWhiteSpace(ied.PreparationStatusText)
? $"Preparing {ied.IedName}"
: ied.PreparationStatusText;
var requested = ied.TestPoints.Count(point => point.TestEnabled && point.ImportReady);
var live = ied.TestPoints.Count(point =>
point.TestEnabled &&
point.ImportReady &&
point.LiveBindingState == IoTestLiveBindingState.LivePointReady);
var liveRatio = requested == 0 ? 0d : Math.Clamp((double)live / requested, 0d, 1d);
if (device is null)
return new IoFatPreparationProgressSnapshot(message, 3d, "Step 1 of 10");
if (device.IsBusy)
{
var discovery = Math.Clamp(device.DiscoveryProgressPercent, 0d, 100d) / 100d;
var refreshing = HasProgressTerm(message, "refreshing live model", "full live discovery", "re-scan");
var start = refreshing ? 55d : 5d;
var span = refreshing ? 22d : 52d;
return new IoFatPreparationProgressSnapshot(
string.IsNullOrWhiteSpace(device.BusyStage) ? message : device.BusyStage,
start + discovery * span,
refreshing ? "Step 5 of 10" : device.DiscoveryProgressStepText);
}
if (!device.IsConnected)
return new IoFatPreparationProgressSnapshot(message, 8d, "Step 2 of 10");
if (HasProgressTerm(message, "association ready", "reusing the loaded model", "saved endpoint"))
return new IoFatPreparationProgressSnapshot(message, 60d, "Step 4 of 10");
if (HasProgressTerm(message, "matching", "workbook signal"))
return new IoFatPreparationProgressSnapshot(message, 68d, "Step 6 of 10");
if (HasProgressTerm(message, "refreshing report acquisition", "saved model missed"))
return new IoFatPreparationProgressSnapshot(message, 75d, "Step 7 of 10");
if (HasProgressTerm(message, "arming", "report acquisition"))
return new IoFatPreparationProgressSnapshot(message, 82d, "Step 8 of 10");
var acquisitionMode = device.AcquisitionMode ?? string.Empty;
var plannerSettling = HasProgressTerm(
acquisitionMode,
"arming",
"live start",
"preparing",
"settling");
if (device.IsMonitoring)
{
var percent = 86d + liveRatio * 12d;
if (HasProgressTerm(message, "validating", "report coverage", "fallback", "rebuilding"))
percent = Math.Max(percent, 89d);
if (requested > 0 && live == requested && !plannerSettling)
percent = 100d;
return new IoFatPreparationProgressSnapshot(
message,
percent,
requested > 0 && live == requested ? "Step 10 of 10" : "Step 9 of 10");
}
return new IoFatPreparationProgressSnapshot(message, 78d, "Step 7 of 10");
}
private static bool HasProgressTerm(string? value, params string[] terms)
{
var text = value ?? string.Empty;
return terms.Any(term => text.Contains(term, StringComparison.OrdinalIgnoreCase));
}
}
internal sealed record IoFatPreparationProgressSnapshot(
string Message,
double Percent,
string StepText);