blob: 0c23c893064c388aa1c6e624482d80a0b7c68a4c (
plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
using RealTimeGraphX.DataPoints;
using RealTimeGraphX.WPF;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Tango.BL.Enumerations;
using Tango.FSE.Common.Diagnostics;
using Tango.FSE.Diagnostics.Project.Widgets.RealTimeGraph;
namespace Tango.FSE.Diagnostics.Project.Widgets.RealTimeGraphMultiChannel
{
[Description("Multi Series Graph")]
public class RealTimeGraphMultiChannelWidget : RealTimeGraphWidgetBase<RealTimeGraphMultiChannelWidgetSettings>
{
public RealTimeGraphMultiChannelWidget()
{
Monitor = TechMonitors.DispensersPressure;
}
public async override Task Init()
{
await base.Init();
if (!TechMonitor.MultiChannel)
{
throw new InvalidOperationException($"Cannot initialize a real-time graph multi channel widget using the single channel monitor '{Monitor}'.");
}
Controller.DataSeriesCollection.Clear();
for (int i = 0; i < TechMonitor.ChannelCount; i++)
{
Controller.DataSeriesCollection.Add(new WpfGraphDataSeries()
{
Name = $"{TechMonitor.Name.First()}{i + 1}",
Stroke = Colors.DimGray,
});
}
MachineProvider.MachineConnected -= MachineProvider_MachineConnected;
MachineProvider.MachineConnected += MachineProvider_MachineConnected;
ConfigureByConnectedMachine();
}
private void ConfigureByConnectedMachine()
{
if (MachineProvider.IsConnected && MachineProvider.Machine != null)
{
try
{
Controller.DataSeriesCollection.ToList().ForEach(x => x.IsVisible = false);
foreach (var pack in MachineProvider.Machine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).ToList())
{
Color color = Colors.DimGray;
if (pack.LiquidType.LiquidTypeColor == Colors.Black)
{
color = Colors.Gray;
}
else if (pack.LiquidType.LiquidTypeColor == Colors.Transparent)
{
color = Colors.White;
}
else
{
color = pack.LiquidType.LiquidTypeColor;
}
Controller.DataSeriesCollection[pack.PackIndex].Name = pack.LiquidType.Name;
Controller.DataSeriesCollection[pack.PackIndex].Stroke = color;
Controller.DataSeriesCollection[pack.PackIndex].IsVisible = true;
}
}
catch (Exception ex)
{
LogManager.Log(ex, $"Error initializing colors for real-time multi channel graph data series collection '{Monitor}'.");
}
}
}
public override FrameworkElement GetView()
{
return new RealTimeGraphMultiChannelWidgetView();
}
private void MachineProvider_MachineConnected(object sender, Common.Connection.MachineConnectedEventArgs e)
{
ConfigureByConnectedMachine();
}
public override void OnDiagnosticsData(DiagnosticsPackage package)
{
var matrix = package.GetMonitorMatrix(Monitor);
if (matrix.Count > 0)
{
var firstPoints = matrix.First();
if (matrix.Any(x => x.Count > 0))
{
List<TimeSpanDataPoint> dates = new List<TimeSpanDataPoint>();
DateTime dayStart = new DateTime(package.Frame.DiagnosticsTime.Year, package.Frame.DiagnosticsTime.Month, package.Frame.DiagnosticsTime.Day);
TimeSpan offset = package.Frame.DiagnosticsTime - dayStart;
for (int i = 0; i < firstPoints.Count; i++)
{
dates.Add(
offset
.Add(TimeSpan.FromMilliseconds(-package.Frame.Delta.TotalMilliseconds))
.Add(TimeSpan.FromMilliseconds(package.Frame.Delta.TotalMilliseconds * (i / (double)firstPoints.Count))));
}
List<List<TimeSpanDataPoint>> datesMatrix = new List<List<TimeSpanDataPoint>>();
List<List<DoubleDataPoint>> pointsMatrix = new List<List<DoubleDataPoint>>();
foreach (var points in matrix)
{
datesMatrix.Add(dates);
pointsMatrix.Add(points.Select(x => new DoubleDataPoint(x)).ToList());
}
Controller.PushData(datesMatrix, pointsMatrix);
}
}
}
public override List<DiagnosticsWidgetComponent<TechMonitors>> Components
{
get
{
return Services.TechComponentsService.Monitors.FindAll().Result.Where(x => x.MultiChannel).Select(x => new DiagnosticsWidgetComponent<TechMonitors>()
{
DisplayName = x.Description,
Object = (TechMonitors)x.Code,
}).OrderByAlphaNumeric(x => x.DisplayName).ToList();
}
}
}
}
|