aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs
blob: 2a298777b7552ab56e679db52d9399b7aad72646 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using Tango.BL.Enumerations;
using Tango.BL.ValueObjects;
using Tango.Core;

namespace Tango.MachineStudio.Statistics.Models
{
    public class StatisticsValue
    {
        public string Name { get; set; }

        public double Value { get; set; }

        public string Unit { get; set; }
    }
    public class MoreValue
    {
        public string Text { get; set; }
    }

    public class StatisticsValueCollection: ExtendedObject
    {
        private List<Color> _pieColors;

        #region Properties

        private ObservableCollection<StatisticsValue> _statisticsCollection;

        public ObservableCollection<StatisticsValue> StatisticsCollection
        {
            get { return _statisticsCollection; }
            set { _statisticsCollection = value;
                RaisePropertyChangedAuto();
            }
        }

        private List<StatisticsValue> _threadConsumptionPerThread;

        public List<StatisticsValue> ThreadConsumptionPerThread
        {
            get { return _threadConsumptionPerThread; }
            set { _threadConsumptionPerThread = value; RaisePropertyChangedAuto(); }
        }

        public CompositeCollection ThreadConsumptionPerThreadCollection { get; set; }

        private LabeledSeriesCollection _pieJobSource;
        public LabeledSeriesCollection PieJobSource
        {
            get { return _pieJobSource; }
            set { _pieJobSource = value; RaisePropertyChangedAuto(); }
        }

        private LabeledSeriesCollection _pieJobRunStatus;
        public LabeledSeriesCollection PieJobRunStatus
        {
            get { return _pieJobRunStatus; }
            set { _pieJobRunStatus = value; RaisePropertyChangedAuto(); }
        }

        private LabeledSeriesCollection _pieGradientSolid;
        public LabeledSeriesCollection PieGradientSolid
        {
            get { return _pieGradientSolid; }
            set { _pieGradientSolid = value; RaisePropertyChangedAuto(); }
        }

        private List<JobRunLiquidQuantity> _liquidQuantities;
        public List<JobRunLiquidQuantity> LiquidQuantities
        {
            get
            {
                if (_liquidQuantities == null)
                {
                    _liquidQuantities = new List<JobRunLiquidQuantity>();
                }
                return _liquidQuantities;
            }
            set
            { _liquidQuantities = value; RaisePropertyChangedAuto(); }
        }

        private int _totalLiquidQuantities;

        public int TotalLiquidQuantities
        {
            get { return _totalLiquidQuantities; }
            set { _totalLiquidQuantities = value; RaisePropertyChangedAuto(); }
        }

        #endregion

        public StatisticsValueCollection()
        {
            StatisticsCollection = new ObservableCollection<StatisticsValue>();
            ThreadConsumptionPerThread = new List<StatisticsValue>();
            ThreadConsumptionPerThreadCollection = new CompositeCollection();

            _pieColors = new List<Color>();
            _pieColors.Add(Color.FromRgb(239, 131, 43));//green
            _pieColors.Add(Color.FromRgb(144, 233, 144));//orange
            _pieColors.Add(Color.FromRgb(100, 184, 236));//blue


            PieJobSource = new LabeledSeriesCollection()
            {
                Title = "PPC/MS",
                SeriesColors = _pieColors,
            };
            PieJobRunStatus = new LabeledSeriesCollection()
            {
                Title = "Failed/Aborted/Completed",
                SeriesColors = _pieColors,
            };
            PieGradientSolid = new LabeledSeriesCollection()
            {
                Title = "Gradient/Solid",
                SeriesColors = _pieColors,
            };
        }

        public void Clean()
        {
            StatisticsCollection.Clear();
            ThreadConsumptionPerThreadCollection.Clear();
            ThreadConsumptionPerThread.Clear();
            PieJobSource.SeriesCollection.Clear();
            PieJobRunStatus.SeriesCollection.Clear();
            PieGradientSolid.SeriesCollection.Clear();
        }

        public void AddStatisticsValue( string name, double value, string unit)
        {
            StatisticsCollection.Add(new StatisticsValue() { Name = name, Value=value, Unit = unit });
            RaisePropertyChanged("StatisticsCollection");
        }

        public void CreateThreadConsumptionPerThread(List<StatisticsValue> threads)
        {
            ThreadConsumptionPerThreadCollection.Add(new CollectionContainer() { Collection = threads.Take(threads.Count() > 2 ? 2 : threads.Count()) });
            if (threads.Count() > 2)
            {
                ThreadConsumptionPerThreadCollection.Add(new CollectionContainer() { Collection = new List<MoreValue>() { new MoreValue(){ Text="More threads ..." } } });
                ThreadConsumptionPerThread = threads.Skip(2).ToList();
            }
                
            RaisePropertyChanged("ThreadConsumptionPerThreadCollection");
        }

        #region GeneratePieChart
        Func<ChartPoint, string> labelPoint = chartPoint =>
            string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

        public void GeneratePieJobSource(int PPCCount, int MSCount)
        {
            var series = new PieSeries()
            {
                Title = "PPC",
                Values = new ChartValues<int>() { PPCCount },
                Fill = new SolidColorBrush(_pieColors[0]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint

            };

            PieJobSource.SeriesCollection.Add(series);
            
            series = new PieSeries()
            {
                Title = "MS",
                Values = new ChartValues<int>() { MSCount },
                Fill = new SolidColorBrush(_pieColors[2]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };
            PieJobSource.SeriesCollection.Add(series);
            RaisePropertyChanged("PieJobSource");
        }

        public void GeneratePieJobRunStatus(int failedCount, int abortedCount, int completedCount)
        {
            var series = new PieSeries()
            {
                Title = "Failed",
                Values = new ChartValues<int>() { failedCount },
                Fill = new SolidColorBrush(_pieColors[0]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };

            PieJobRunStatus.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "Aborted",
                Values = new ChartValues<int>() { abortedCount },
                Fill = new SolidColorBrush(_pieColors[2]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint,
               
            };
            PieJobRunStatus.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "Completed",
                Values = new ChartValues<int>() { completedCount },
                Fill = new SolidColorBrush(_pieColors[1]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };
            PieJobRunStatus.SeriesCollection.Add(series);

            RaisePropertyChanged("PieJobRunStatus");
        }

        public void GeneratePieGradientSolid(int gradientCount, int solidCount)
        {
            var series = new PieSeries()
            {
                Title = "Solid",
                Values = new ChartValues<int>() { solidCount },
                Fill = new SolidColorBrush(_pieColors[0]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };
            PieGradientSolid.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "Gradient",
                Values = new ChartValues<int>() { gradientCount },
                Fill = new SolidColorBrush(_pieColors[2]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint

            };

            PieGradientSolid.SeriesCollection.Add(series);

            
            RaisePropertyChanged("PieGradientSolid");
        }
        #endregion

        public void GenerateStatisticsLiquidQuantity(List<JobRunLiquidQuantity> liquidQuantities)
        {
            LiquidQuantities = liquidQuantities;
            TotalLiquidQuantities = liquidQuantities.Sum(x => x.Quantity);
        }

    }
}