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 _pieColors; #region Properties private ObservableCollection _statisticsCollection; public ObservableCollection StatisticsCollection { get { return _statisticsCollection; } set { _statisticsCollection = value; RaisePropertyChangedAuto(); } } private List _threadConsumptionPerThread; public List 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 _liquidQuantities; public List LiquidQuantities { get { if (_liquidQuantities == null) { _liquidQuantities = new List(); } 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(); ThreadConsumptionPerThread = new List(); ThreadConsumptionPerThreadCollection = new CompositeCollection(); _pieColors = new List(); _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 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() { new MoreValue(){ Text="More threads ..." } } }); ThreadConsumptionPerThread = threads.Skip(2).ToList(); } RaisePropertyChanged("ThreadConsumptionPerThreadCollection"); } #region GeneratePieChart Func 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() { PPCCount }, Fill = new SolidColorBrush(_pieColors[0]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint }; PieJobSource.SeriesCollection.Add(series); series = new PieSeries() { Title = "MS", Values = new ChartValues() { 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() { failedCount }, Fill = new SolidColorBrush(_pieColors[0]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint }; PieJobRunStatus.SeriesCollection.Add(series); series = new PieSeries() { Title = "Aborted", Values = new ChartValues() { abortedCount }, Fill = new SolidColorBrush(_pieColors[2]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint, }; PieJobRunStatus.SeriesCollection.Add(series); series = new PieSeries() { Title = "Completed", Values = new ChartValues() { 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() { solidCount }, Fill = new SolidColorBrush(_pieColors[0]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint }; PieGradientSolid.SeriesCollection.Add(series); series = new PieSeries() { Title = "Gradient", Values = new ChartValues() { gradientCount }, Fill = new SolidColorBrush(_pieColors[2]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint }; PieGradientSolid.SeriesCollection.Add(series); RaisePropertyChanged("PieGradientSolid"); } #endregion public void GenerateStatisticsLiquidQuantity(List liquidQuantities) { LiquidQuantities = liquidQuantities; TotalLiquidQuantities = liquidQuantities.Sum(x => x.Quantity); } } }