aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-03-25 17:43:49 +0200
committerAvi Levkovich <avi@twine-s.com>2020-03-25 17:43:49 +0200
commitd29da53d6f71f45749c0ede5b4cd7281ed3a270e (patch)
treefd83afc7771c0f4f19c581e1cf407bcf7c14818b /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics
parent0208e9f1800c044ec3bd002b7aa7fd00621c81be (diff)
downloadTango-d29da53d6f71f45749c0ede5b4cd7281ed3a270e.tar.gz
Tango-d29da53d6f71f45749c0ede5b4cd7281ed3a270e.zip
merge
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs41
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs31
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs319
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/TotalLiquidQuantityModel.cs15
4 files changed, 406 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs
new file mode 100644
index 000000000..cd928d9c9
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace Tango.MachineStudio.Statistics.Converters
+{
+ public class JobLengthConverter : IMultiValueConverter
+ {
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ try
+ {
+ if (values != null && values.Count() == 3)
+ {
+ double length = (double)values[0];
+ double endPoint = (double)values[1];
+ double width = (double)values[2];
+ var v = Math.Round((endPoint / length) * width, MidpointRounding.AwayFromZero);
+
+ if (double.IsInfinity(v))
+ {
+ return 0d;
+ }
+ return v;
+ }
+ }
+ catch { }
+
+ return 0d;
+ }
+
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs
new file mode 100644
index 000000000..32050cdb1
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace Tango.MachineStudio.Statistics.Converters
+{
+ public class NanoLiterToLiterFormatConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ try
+ {
+ var longValue = System.Convert.ToUInt64(value.ToString());
+ double val = (longValue / 1000000000d);
+ return val.ToString("0.0");
+ }
+ catch { }
+
+ return "";
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs
new file mode 100644
index 000000000..b5615e4d1
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs
@@ -0,0 +1,319 @@
+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;
+using System.Windows.Media;
+using System.Windows;
+
+namespace Tango.MachineStudio.Statistics.Models
+{
+ public class StatisticsValue
+ {
+ public string Name { get; set; }
+
+ public object 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;
+
+ /// <summary>
+ /// Gets or sets the statistics collection of StatisticsValue object.
+ /// </summary>
+ public ObservableCollection<StatisticsValue> StatisticsCollection
+ {
+ get { return _statisticsCollection; }
+ set
+ {
+ _statisticsCollection = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
+ private List<StatisticsValue> _threadConsumptionPerThread;
+ /// <summary>
+ /// Gets or sets the thread consumption per thread list.
+ /// </summary>
+ public List<StatisticsValue> ThreadConsumptionPerThread
+ {
+ get { return _threadConsumptionPerThread; }
+ set { _threadConsumptionPerThread = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the thread consumption per thread collection.
+ /// </summary>
+ public CompositeCollection ThreadConsumptionPerThreadCollection { get; set; }
+
+ private LabeledSeriesCollection _pieJobSource;
+
+ /// <summary>
+ /// Gets or sets the pie job source.
+ /// </summary>
+ public LabeledSeriesCollection PieJobSource
+ {
+ get { return _pieJobSource; }
+ set { _pieJobSource = value; RaisePropertyChangedAuto(); }
+ }
+
+ private LabeledSeriesCollection _pieJobRunStatus;
+
+ /// <summary>
+ /// Gets or sets the pie job run status.
+ /// </summary>
+ public LabeledSeriesCollection PieJobRunStatus
+ {
+ get { return _pieJobRunStatus; }
+ set { _pieJobRunStatus = value; RaisePropertyChangedAuto(); }
+ }
+
+ private LabeledSeriesCollection _pieGradientSolid;
+
+ /// <summary>
+ /// Gets or sets the pie gradient solid.
+ /// </summary>
+ public LabeledSeriesCollection PieGradientSolid
+ {
+ get { return _pieGradientSolid; }
+ set { _pieGradientSolid = value; RaisePropertyChangedAuto(); }
+ }
+
+ private List<TotalLiquidQuantityModel> _liquidQuantities;
+
+ /// <summary>
+ /// Gets or sets the liquid quantities.
+ /// </summary>
+ public List<TotalLiquidQuantityModel> LiquidQuantities
+ {
+ get
+ {
+ if (_liquidQuantities == null)
+ {
+ _liquidQuantities = new List<TotalLiquidQuantityModel>();
+ }
+ return _liquidQuantities;
+ }
+ set
+ { _liquidQuantities = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ulong _totalLiquidQuantities;
+
+ /// <summary>
+ /// Gets or sets the total liquid quantities.
+ /// </summary>
+ public ulong 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(((SolidColorBrush)Application.Current.Resources["RedBrush500"]).Color);
+ _pieColors.Add(((SolidColorBrush)Application.Current.Resources["OrangeBrush"]).Color);
+ _pieColors.Add(((SolidColorBrush)Application.Current.Resources["GreenBrush"]).Color);
+ _pieColors.Add(((SolidColorBrush)Application.Current.Resources["BlueBrush100"]).Color);
+ _pieColors.Add(Color.FromRgb(255, 216, 76));
+
+
+ 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,
+ };
+ }
+
+ /// <summary>
+ /// Cleans all values.
+ /// </summary>
+ public void Clean()
+ {
+ StatisticsCollection.Clear();
+ ThreadConsumptionPerThreadCollection.Clear();
+ ThreadConsumptionPerThread.Clear();
+ PieJobSource.SeriesCollection.Clear();
+ PieJobRunStatus.SeriesCollection.Clear();
+ PieGradientSolid.SeriesCollection.Clear();
+ }
+
+ /// <summary>
+ /// Adds the statistics value.
+ /// </summary>
+ public void AddStatisticsValue(string name, object value, string unit)
+ {
+ StatisticsCollection.Add(new StatisticsValue() { Name = name, Value = value, Unit = unit });
+ RaisePropertyChanged("StatisticsCollection");
+ }
+
+ /// <summary>
+ /// Creates the thread consumption per thread.
+ /// </summary>
+ 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[4]),
+ DataLabels = true,
+ ToolTip = "",
+ LabelPoint = labelPoint
+
+ };
+
+ PieJobSource.SeriesCollection.Add(series);
+
+ series = new PieSeries()
+ {
+ Title = "MS",
+ Values = new ChartValues<int>() { MSCount },
+ Fill = new SolidColorBrush(_pieColors[3]),
+ 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[1]),
+ DataLabels = true,
+ ToolTip = "",
+ LabelPoint = labelPoint,
+
+ };
+ PieJobRunStatus.SeriesCollection.Add(series);
+
+ series = new PieSeries()
+ {
+ Title = "Completed",
+ Values = new ChartValues<int>() { completedCount },
+ Fill = new SolidColorBrush(_pieColors[2]),
+ 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[4]),
+ DataLabels = true,
+ ToolTip = "",
+ LabelPoint = labelPoint
+ };
+ PieGradientSolid.SeriesCollection.Add(series);
+
+ series = new PieSeries()
+ {
+ Title = "Gradient",
+ Values = new ChartValues<int>() { gradientCount },
+ Fill = new SolidColorBrush(_pieColors[3]),
+ DataLabels = true,
+ ToolTip = "",
+ LabelPoint = labelPoint
+
+ };
+
+ PieGradientSolid.SeriesCollection.Add(series);
+
+
+ RaisePropertyChanged("PieGradientSolid");
+ }
+ #endregion
+
+ /// <summary>
+ /// Generates the statistics liquid quantity and TotalLiquidQuantities.
+ /// </summary>
+ public void GenerateStatisticsLiquidQuantity(List<TotalLiquidQuantityModel> liquidQuantities)
+ {
+ LiquidQuantities = liquidQuantities;
+ TotalLiquidQuantities = 0;
+
+ foreach (var item in liquidQuantities)
+ {
+ TotalLiquidQuantities += (ulong)item.Quantity;
+ }
+ }
+
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/TotalLiquidQuantityModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/TotalLiquidQuantityModel.cs
new file mode 100644
index 000000000..b5e2e9fb7
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/TotalLiquidQuantityModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Enumerations;
+
+namespace Tango.MachineStudio.Statistics.Models
+{
+ public class TotalLiquidQuantityModel
+ {
+ public LiquidTypes LiquidType { get; set; }
+ public ulong Quantity { get; set; }
+ }
+}