From adeeb0ee759b886f902ace9bb68998e1ecf320a7 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Thu, 12 Mar 2020 17:45:30 +0200 Subject: Implement statistic values in Job runs View. Related Work Items: #2509 --- .../Tango.MachineStudio.Statistics/App.config | 20 +- .../Converters/JobLengthConverter.cs | 35 +++ .../MidTankLevelToElementHeightConverter.cs | 2 +- .../Converters/NanoLiterToLiterFormatConverter.cs | 30 +++ .../Models/JobRunModel.cs | 2 + .../Models/StatisticsValueCollection.cs | 269 ++++++++++++++++++++ .../Tango.MachineStudio.Statistics.csproj | 10 + .../ViewModels/ChartsViewVM.cs | 101 ++++++-- .../ViewModels/JobRunsViewVM.cs | 103 +++++++- .../ViewModels/MainViewVM.cs | 1 - .../Views/ChartsView.xaml | 27 +- .../Views/JobRunsView.xaml | 281 +++++++++++++++++---- .../Views/JobRunsView.xaml.cs | 5 +- .../Tango.MachineStudio.Statistics/packages.config | 1 + 14 files changed, 792 insertions(+), 95 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config index ed4582d5b..75b63289d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config @@ -22,7 +22,7 @@ - + @@ -30,27 +30,27 @@ - + - + - + - + - + - + @@ -74,7 +74,7 @@ - + @@ -92,6 +92,10 @@ + + + + \ No newline at end of file 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..b730d7881 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs @@ -0,0 +1,35 @@ +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]; + return Math.Round((endPoint / length) * width, MidpointRounding.AwayFromZero); + } + } + 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/MidTankLevelToElementHeightConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs index 4ea46336f..de002046e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs @@ -22,7 +22,7 @@ namespace Tango.MachineStudio.Statistics.Converters double midTankLevel = (double)Math.Min(quantity, MAX_QUANTITY); double delta = ((midTankLevel / MAX_QUANTITY) * parentActualHeight); - if (midTankLevel < (MAX_QUANTITY/10))// if quantity < 10|% set 2 pixel + if (quantity > 0 && midTankLevel < (MAX_QUANTITY/10))// if quantity < 10|% set 2 pixel delta = 2.0; var test = delta; return parentActualHeight - delta; 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..3c25bfe4f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs @@ -0,0 +1,30 @@ +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 + { + double val =(double) ((int)value) / 1000000; + return val.ToString("N2", CultureInfo.InvariantCulture); + } + 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/JobRunModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs index 28d51ab47..83897ca16 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs @@ -32,6 +32,8 @@ namespace Tango.MachineStudio.Statistics.Models { HeatingDuration = JobRun.ActualStartDate - JobRun.HeatingStartDate; } + + } } } 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..2a298777b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs @@ -0,0 +1,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 _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); + } + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj index 1300d7dba..adac4bb9f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj @@ -38,6 +38,9 @@ ..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + + ..\..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + ..\..\..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll @@ -75,14 +78,17 @@ + + + PieChartTooltipControl.xaml @@ -169,6 +175,10 @@ {bc932dbd-7cdb-488c-99e4-f02cf441f55e} Tango.Logging + + {e4927038-348d-4295-aaf4-861c58cb3943} + Tango.PMR + {22f87980-e990-4686-be81-be63d562c4d5} Tango.Serialization diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs index b06261306..38c1cc24a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs @@ -12,13 +12,14 @@ using Tango.SharedUI; using Tango.BL; using Tango.MachineStudio.Common.Notifications; using System.Threading.Tasks; +using Tango.Core.Commands; namespace Tango.MachineStudio.Statistics.ViewModels { public class ChartsViewVM : ViewModel { private INotificationProvider _notification; - private ObservablesContext _context; + //private ObservablesContext _context; private List _job_runs; private bool _loaded; @@ -48,14 +49,14 @@ namespace Tango.MachineStudio.Statistics.ViewModels public DateTime StartDate { get { return _startDate; } - set { _startDate = value; RaisePropertyChangedAuto(); OnDateRangeChanged(); } + set { _startDate = value; RaisePropertyChangedAuto();} } private DateTime _endDate; public DateTime EndDate { get { return _endDate; } - set { _endDate = value; RaisePropertyChangedAuto(); OnDateRangeChanged(); } + set { _endDate = value; RaisePropertyChangedAuto();} } private DateTime _minDate; @@ -71,6 +72,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels get { return _maxDate; } set { _maxDate = value; RaisePropertyChangedAuto(); } } + + public RelayCommand LoadJobRunsCommand { get; set; } #endregion public ChartsViewVM(INotificationProvider notificationProvider) @@ -78,45 +81,93 @@ namespace Tango.MachineStudio.Statistics.ViewModels _notification = notificationProvider; StartDate = DateTime.Now.AddMonths(-1); EndDate = DateTime.Now; + LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), () => IsFree); } #region Generate Charts - public async void Init() + //public async void Init() + //{ + //using (_notification.PushTaskItem("Loading statistics...")) + //{ + // IsFree = false; + + // await Task.Factory.StartNew(() => + // { + // _context = ObservablesContext.CreateDefault(); + // //_job_runs = _context.JobRuns.OrderBy(x => x.StartDate).ToList().Select(x => new JobRunStatisticsModel(x)).ToList(); + // //foreach (var run in _job_runs) + // //{ + // // run.LoadMachine(_context).GetAwaiter().GetResult(); + // //} + // }); + + // if (_job_runs.Count > 0) + // { + // MinDate = _job_runs.Min(x => x.StartDate); + // MaxDate = _job_runs.Max(x => x.StartDate); + // } + + // InvokeUIOnIdle(() => + // { + // if (_loaded) + // { + // OnDateRangeChanged(); + // } + // }); + + // _loaded = true; + // IsFree = true; + //} + //} + private async Task LoadJobRuns() { using (_notification.PushTaskItem("Loading statistics...")) { - IsFree = false; - - await Task.Factory.StartNew(() => + try { - _context = ObservablesContext.CreateDefault(); - _job_runs = _context.JobRuns.OrderBy(x => x.StartDate).ToList().Select(x => new JobRunStatisticsModel(x)).ToList(); - foreach (var run in _job_runs) + IsFree = false; + + await Task.Factory.StartNew(() => + { + using (var db = ObservablesContext.CreateDefault()) + { + _job_runs = db.JobRuns.OrderBy(x => x.StartDate).ToList().Select(x => new JobRunStatisticsModel(x)).ToList(); + foreach (var run in _job_runs) + { + run.LoadMachine(db).GetAwaiter().GetResult(); + } + + } + }); + if (_job_runs.Count > 0) { - run.LoadMachine(_context).GetAwaiter().GetResult(); + MinDate = _job_runs.Min(x => x.StartDate); + MaxDate = _job_runs.Max(x => x.StartDate); } - }); - if (_job_runs.Count > 0) + InvokeUIOnIdle(() => + { + if (_loaded) + { + OnDateRangeChanged(); + } + }); + + _loaded = true; + } + catch (Exception ex) { - MinDate = _job_runs.Min(x => x.StartDate); - MaxDate = _job_runs.Max(x => x.StartDate); + LogManager.Log(ex, "Error loading statistics."); } - - InvokeUIOnIdle(() => + finally { - if (_loaded) - { - OnDateRangeChanged(); - } - }); - - _loaded = true; - IsFree = true; + IsFree = true; + } } } + private List GetJobRunsByDateRange(DateTime startDate, DateTime endTime, JobRunStatus? status = null) { return _job_runs.Where(x => x.StartDate.ToLocalTime() >= startDate && x.StartDate.ToLocalTime() <= endTime && (status == null || x.JobRunStatus == status)).ToList(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index a51d18909..d57a1c96c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -16,6 +16,10 @@ using Tango.MachineStudio.Statistics.Models; using Tango.SharedUI; using Tango.SharedUI.Components; using Tango.AutoComplete.Editors; +using System.Windows.Media; +using LiveCharts.Wpf; +using LiveCharts; +using Tango.BL.ValueObjects; namespace Tango.MachineStudio.Statistics.ViewModels { @@ -184,6 +188,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels RaisePropertyChangedAuto(); } } + + public StatisticsValueCollection StatisticsValueCollection { get; set; } #endregion @@ -261,7 +267,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels return null; } }); - + + StatisticsValueCollection = new StatisticsValueCollection(); } /// @@ -322,19 +329,21 @@ namespace Tango.MachineStudio.Statistics.ViewModels .Query(y => y.Where(x => ( String.IsNullOrEmpty(jobName) || x.JobName.ToLower().StartsWith(jobName.ToLower())) && (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))) .BuildListAsync(); - var modelList = runs.Select(x => new JobRunModel() { JobRun = x, Machine = _allMachines.FirstOrDefault(y => y.Guid == x.MachineGuid), User = _allUsers.SingleOrDefault(y => y.Guid == x.UserGuid), - Rml = _rmlsModels.SingleOrDefault(y => y.Guid == x.RmlGuid) + Rml = _rmlsModels.SingleOrDefault(y => y.Guid == x.RmlGuid), }).OrderByDescending(x => x.JobRun.StartDate).ToList(); modelList.ForEach(x => x.Init()); JobRuns = modelList.ToObservableCollection(); + GenerateStatistics(); } + + } catch (Exception ex) { @@ -347,5 +356,93 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } + protected void GenerateStatistics() + { + StatisticsValueCollection.Clean(); + GenerateTotalRunsLength(); + GenerateRunsDuration(); + GenerateUploadDuration(); + GenerateHeatingDuration(); + GenerateTotalThreadConsumption(); + + GeneratePieCharts(); + CreateThreadConsumptionPerThread(); + GenerateAllLiquidQuantities(); + } + + protected void GenerateTotalRunsLength() + { + double val = JobRuns.Where(z => z.JobRun.EndPosition > 0).Sum(x => x.JobRun.JobLength); + StatisticsValueCollection.AddStatisticsValue("Total Runs Length", val, " m"); + } + + protected void GenerateRunsDuration() + { + var selection = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null); + double val = selection.Sum(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); + StatisticsValueCollection.AddStatisticsValue("Total Runs Duration", val, " hours"); + double average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); + StatisticsValueCollection.AddStatisticsValue("Average Runs Duration", average, " hours"); + } + + protected void GenerateUploadDuration() + { + var val = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.Ticks); + TimeSpan ts = new TimeSpan(Convert.ToInt64(val)); + StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(ts.TotalMinutes, 0), " minutes"); + } + + protected void GenerateHeatingDuration() + { + var val = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.HeatingDuration != null).Average(x => x.HeatingDuration.Value.Ticks); + TimeSpan ts = new TimeSpan(Convert.ToInt64(val)); + StatisticsValueCollection.AddStatisticsValue("Average Heating Duration", Math.Max(ts.TotalMinutes, 0), " minutes"); + } + + protected void GenerateTotalThreadConsumption() + { + double val = JobRuns.Where(z => z.JobRun.EndPosition > 0).Sum(x => x.JobRun.EndPosition); + StatisticsValueCollection.AddStatisticsValue("Total Thread Consumption", val, " m"); + } + + protected void GeneratePieCharts() + { + int PPCCount = JobRuns.Count(x => x.JobRun.Source == JobSource.Local); + int MSCount = JobRuns.Count(x => x.JobRun.Source == JobSource.Remote); + StatisticsValueCollection.GeneratePieJobSource(PPCCount, MSCount); + + int failedCount = JobRuns.Count(x => x.JobRun.JobRunStatus == JobRunStatus.Failed); + int abortedCount = JobRuns.Count(x => x.JobRun.JobRunStatus == JobRunStatus.Aborted); + int completedCount = JobRuns.Count(x => x.JobRun.JobRunStatus == JobRunStatus.Completed); + StatisticsValueCollection.GeneratePieJobRunStatus(failedCount, abortedCount, completedCount); + + int gradientCount = JobRuns.Count(x => x.JobRun.IsGradient == true); + int solidCount = JobRuns.Count(x => x.JobRun.IsGradient == false); + StatisticsValueCollection.GeneratePieGradientSolid(gradientCount, solidCount); + + } + + protected void CreateThreadConsumptionPerThread() + { + var temp = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null).GroupBy(x => x.Rml.Name); + List result = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null && !String.IsNullOrEmpty(z.Rml.Name)).GroupBy(x => x.Rml.Name).Select(y => new StatisticsValue { Name = y.Key, Value = y.Sum(x => x.JobRun.EndPosition), Unit="m" }).ToList(); + StatisticsValueCollection.CreateThreadConsumptionPerThread(result); + } + + protected void GenerateAllLiquidQuantities() + { + var db_liquidQuantities = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).Select(y=> y.JobRun.LiquidQuantities).ToList(); + List allLiquidQuantities = new List(); + + foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) + { + var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.SingleOrDefault(y => y.LiquidType == ltype)).Where(x=>x!=null); + var count = liquidQuantityByTypeList != null ? liquidQuantityByTypeList.Sum(x => x.Quantity) : 0; + JobRunLiquidQuantity lq = new JobRunLiquidQuantity() { LiquidType = ltype, Quantity = count }; + allLiquidQuantities.Add(lq); + } + StatisticsValueCollection.GenerateStatisticsLiquidQuantity(allLiquidQuantities); + } + } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs index 4a75a41c8..e7e2013c5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs @@ -50,7 +50,6 @@ namespace Tango.MachineStudio.Statistics.ViewModels public override void OnNavigatedTo() { base.OnNavigatedTo(); - ChartsViewVM.Init(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml index ecd7e01ed..ae4bf1d46 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml @@ -17,23 +17,26 @@ - - - Start Date: - - + + + + Start Date: + + - - End Date: - - + + End Date: + + + + - + @@ -59,7 +62,7 @@ - + + + + @@ -68,34 +84,6 @@ - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -475,11 +537,142 @@ - - - TOTALS: - Cyan: - + + + + + + + + + + + + + + + + + + + + + + + + Total Thread Consumption per thread: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs index c460e2a9b..2b3ed79ca 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs @@ -1,4 +1,6 @@ -using System; +using LiveCharts; +using LiveCharts.Wpf; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -79,5 +81,6 @@ namespace Tango.MachineStudio.Statistics.Views } } } + } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/packages.config index 31c5f029f..6938c8a4b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/packages.config @@ -1,6 +1,7 @@  + -- cgit v1.3.1 From b188d7bfd91062f65474bd139bb8a434694f117b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 15 Mar 2020 15:46:03 +0200 Subject: Fixed issue with job run start date. Fixed issue with ActionLogs busy indication. --- .../ViewModels/MainViewVM.cs | 71 ++++++++++++---------- .../Views/MainView.xaml | 2 +- .../ViewModels/JobRunsViewVM.cs | 23 ++++--- .../JobRuns/BasicJobRunsLogger.cs | 4 +- .../Tango.Integration/Operation/MachineOperator.cs | 9 +++ .../Operation/PrintingEventArgs.cs | 1 + 6 files changed, 63 insertions(+), 47 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index 534bb364f..df2643d88 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -16,12 +16,15 @@ using Tango.BL.ValueObjects; using Tango.Core.Commands; using Tango.Core.ExtensionMethods; using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Notifications; using Tango.SharedUI.Components; namespace Tango.MachineStudio.ActionLogs.ViewModels { public class MainViewVM : StudioViewModel { + private INotificationProvider _notification; + #region Properties private DateTime _startSelectedDate; @@ -83,30 +86,23 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels set { _differenceObject = value; RaisePropertyChangedAuto(); } } - - private bool _isRunning; - public bool IsRunning - { - get { return _isRunning; } - set { _isRunning = value; } - } - #endregion public RelayCommand SearchCommand { get; set; } public RelayCommand CopyToClipBoardCommand { get; set; } public RelayCommand CopyRelateObjectIDCommand { get; set; } - public MainViewVM() + public MainViewVM(INotificationProvider notification) { + _notification = notification; + ActionLogs = new ObservableCollection(); - SearchCommand = new RelayCommand(GetActionLogs, () => !IsRunning); + SearchCommand = new RelayCommand(GetActionLogs, () => IsFree); CopyRelateObjectIDCommand = new RelayCommand(CopyRelateObjectID); CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard, () => SelectedActionLog != null && SelectedActionLog.DifferenceObject != null); DateTime now = DateTime.Now; StartSelectedDate = now.AddMonths(-1); EndSelectedDate = now; - _isRunning = false; var source = Enum.GetValues(typeof(ActionLogType)).Cast().ToObservableCollection(); var syncedSource = Enum.GetValues(typeof(ActionLogType)).Cast().ToObservableCollection(); @@ -139,27 +135,40 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels if (String.IsNullOrWhiteSpace(filter)) filter = null; - using (ObservablesContext db = ObservablesContext.CreateDefault()) + try + { + IsFree = false; + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + + DateTime startUtc = new DateTime(StartSelectedDate.Date.Ticks, DateTimeKind.Utc); + TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(24, 0, 0); + DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); + + Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); + + ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) + .WithUsers() + .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) + .Query(y => y.Where + (x => filter == null || + (x.ID.ToString().ToLower().StartsWith(filter) + || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) + || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) + || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) + .BuildAsync(); + } + } + catch (Exception ex) + { + IsFree = true; + LogManager.Log(ex, "Error getting action logs."); + _notification.ShowError($"Error occurred while trying to retrieve the action logs.\n{ex.Message}"); + } + finally { - - DateTime startUtc = new DateTime(StartSelectedDate.Date.Ticks, DateTimeKind.Utc); - TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(24, 0, 0); - DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); - - Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); - - IsRunning = true; - ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) - .WithUsers() - .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) - .Query(y => y.Where - (x => filter == null || - (x.ID.ToString().ToLower().StartsWith(filter) - || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) - || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) - || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) - .BuildAsync(); - IsRunning = false; + IsFree = true; } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml index 3a7eaa802..fd640bae5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml @@ -207,7 +207,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index d57a1c96c..9bf69137d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -188,7 +188,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels RaisePropertyChangedAuto(); } } - + public StatisticsValueCollection StatisticsValueCollection { get; set; } #endregion @@ -253,7 +253,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - return db.Jobs.Where(x => x.Name!= null && x.Name.ToLower().Contains(filter.ToLower())).ToList(); + return db.Jobs.Where(x => x.Name != null && x.Name.ToLower().Contains(filter.ToLower())).ToList(); } } else @@ -267,7 +267,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels return null; } }); - + StatisticsValueCollection = new StatisticsValueCollection(); } @@ -326,7 +326,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels .WithJobStatus(JobRunSelectedStatuses.SynchedSource) .WithGradient(IsGradientSelection.SynchedSource) .WithRmls(SelectedThreads.SynchedSource.Select(x => x.Guid).ToList()) - .Query(y => y.Where(x => ( String.IsNullOrEmpty(jobName) || x.JobName.ToLower().StartsWith(jobName.ToLower())) + .Query(y => y.Where(x => (String.IsNullOrEmpty(jobName) || x.JobName.ToLower().StartsWith(jobName.ToLower())) && (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))) .BuildListAsync(); @@ -343,7 +343,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels GenerateStatistics(); } - + } catch (Exception ex) { @@ -387,9 +387,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void GenerateUploadDuration() { - var val = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.Ticks); - TimeSpan ts = new TimeSpan(Convert.ToInt64(val)); - StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(ts.TotalMinutes, 0), " minutes"); + var val = (long)JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.TotalMilliseconds); + StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(TimeSpan.FromMilliseconds(val).TotalMinutes, 0), " minutes"); } protected void GenerateHeatingDuration() @@ -425,18 +424,18 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void CreateThreadConsumptionPerThread() { var temp = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null).GroupBy(x => x.Rml.Name); - List result = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null && !String.IsNullOrEmpty(z.Rml.Name)).GroupBy(x => x.Rml.Name).Select(y => new StatisticsValue { Name = y.Key, Value = y.Sum(x => x.JobRun.EndPosition), Unit="m" }).ToList(); + List result = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null && !String.IsNullOrEmpty(z.Rml.Name)).GroupBy(x => x.Rml.Name).Select(y => new StatisticsValue { Name = y.Key, Value = y.Sum(x => x.JobRun.EndPosition), Unit = "m" }).ToList(); StatisticsValueCollection.CreateThreadConsumptionPerThread(result); } protected void GenerateAllLiquidQuantities() { - var db_liquidQuantities = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).Select(y=> y.JobRun.LiquidQuantities).ToList(); + var db_liquidQuantities = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).Select(y => y.JobRun.LiquidQuantities).ToList(); List allLiquidQuantities = new List(); - + foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) { - var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.SingleOrDefault(y => y.LiquidType == ltype)).Where(x=>x!=null); + var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.SingleOrDefault(y => y.LiquidType == ltype)).Where(x => x != null); var count = liquidQuantityByTypeList != null ? liquidQuantityByTypeList.Sum(x => x.Quantity) : 0; JobRunLiquidQuantity lq = new JobRunLiquidQuantity() { LiquidType = ltype, Quantity = count }; allLiquidQuantities.Add(lq); diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs index f2fb2f16e..0fadd1baa 100644 --- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs @@ -17,7 +17,6 @@ namespace Tango.Integration.JobRuns /// public class BasicJobRunsLogger : ExtendedObject, IJobRunsLogger { - private DateTime _start_date; private Job _job; #region Properties @@ -96,7 +95,7 @@ namespace Tango.Integration.JobRuns JobRun run = new JobRun(); run.UserGuid = _job.UserGuid; - run.StartDate = _start_date; + run.StartDate = e.StartDate; run.UploadingStartDate = e.UploadingStartTime; run.HeatingStartDate = e.HeatingStartTime; run.ActualStartDate = e.ActualStartTime; @@ -187,7 +186,6 @@ namespace Tango.Integration.JobRuns private void Machine_PrintingStarted(object sender, PrintingEventArgs e) { _job = e.Job; - _start_date = DateTime.UtcNow; } #endregion diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 9768498c6..b17321942 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -75,6 +75,8 @@ namespace Tango.Integration.Operation private List _currentJobLiquidQuantities; private DateTime _diagnosticsTime; private MachineStatus _machineStatusBeforeJobStart; + + private DateTime _jobStartDate; private DateTime? _jobUploadingStartDate; private DateTime? _jobHeatingStartDate; private DateTime? _jobActualStartDate; @@ -1050,6 +1052,7 @@ namespace Tango.Integration.Operation PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, job) { LiquidQuantities = _currentJobLiquidQuantities.ToList(), + StartDate = _jobStartDate, }); } @@ -1063,6 +1066,7 @@ namespace Tango.Integration.Operation PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, job) { LiquidQuantities = _currentJobLiquidQuantities.ToList(), + StartDate = _jobStartDate, UploadingStartTime = _jobUploadingStartDate, HeatingStartTime = _jobHeatingStartDate, ActualStartTime = _jobActualStartDate, @@ -1082,6 +1086,7 @@ namespace Tango.Integration.Operation PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, job, exception) { LiquidQuantities = _currentJobLiquidQuantities.ToList(), + StartDate = _jobStartDate, UploadingStartTime = _jobUploadingStartDate, HeatingStartTime = _jobHeatingStartDate, ActualStartTime = _jobActualStartDate, @@ -1099,6 +1104,7 @@ namespace Tango.Integration.Operation PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, job) { LiquidQuantities = _currentJobLiquidQuantities.ToList(), + StartDate = _jobStartDate, UploadingStartTime = _jobUploadingStartDate, HeatingStartTime = _jobHeatingStartDate, ActualStartTime = _jobActualStartDate, @@ -1116,6 +1122,7 @@ namespace Tango.Integration.Operation PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, job) { LiquidQuantities = _currentJobLiquidQuantities.ToList(), + StartDate = _jobStartDate, UploadingStartTime = _jobUploadingStartDate, HeatingStartTime = _jobHeatingStartDate, ActualStartTime = _jobActualStartDate, @@ -2159,6 +2166,8 @@ namespace Tango.Integration.Operation throw new InvalidOperationException("Could not print while status = " + Status); } + _jobStartDate = DateTime.UtcNow; + LogManager.Log($"Executing job '{job.Name}'..."); _currentJobLiquidQuantities = new List(); diff --git a/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs index f68204127..b088b9046 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs @@ -13,6 +13,7 @@ namespace Tango.Integration.Operation public JobHandler JobHandler { get; private set; } public Job Job { get; private set; } public List LiquidQuantities { get; set; } + public DateTime StartDate { get; set; } public DateTime? UploadingStartTime { get; set; } public DateTime? HeatingStartTime { get; set; } public DateTime? ActualStartTime { get; set; } -- cgit v1.3.1 From 56678ae530fe45b0880053793ab46f47051e4dc6 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 15 Mar 2020 16:12:26 +0200 Subject: MS Statistics Job Runs page. Added comments. --- .../Converters/NanoLiterToLiterFormatConverter.cs | 2 +- .../Models/StatisticsValueCollection.cs | 49 ++++++++++++++++-- .../ViewModels/JobRunsViewVM.cs | 59 +++++++++++++++++----- .../Views/JobRunsView.xaml | 25 ++++++++- 4 files changed, 113 insertions(+), 22 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') 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 index 3c25bfe4f..23d7564e8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/NanoLiterToLiterFormatConverter.cs @@ -14,7 +14,7 @@ namespace Tango.MachineStudio.Statistics.Converters { try { - double val =(double) ((int)value) / 1000000; + double val =(double) ((int)value) / 1000000000; return val.ToString("N2", CultureInfo.InvariantCulture); } catch{ } 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 index 2a298777b..2ad165d79 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs @@ -35,6 +35,9 @@ namespace Tango.MachineStudio.Statistics.Models private ObservableCollection _statisticsCollection; + /// + /// Gets or sets the statistics collection of StatisticsValue object. + /// public ObservableCollection StatisticsCollection { get { return _statisticsCollection; } @@ -44,16 +47,25 @@ namespace Tango.MachineStudio.Statistics.Models } private List _threadConsumptionPerThread; - + /// + /// Gets or sets the thread consumption per thread list. + /// public List ThreadConsumptionPerThread { get { return _threadConsumptionPerThread; } set { _threadConsumptionPerThread = value; RaisePropertyChangedAuto(); } } + /// + /// Gets or sets the thread consumption per thread collection. + /// public CompositeCollection ThreadConsumptionPerThreadCollection { get; set; } private LabeledSeriesCollection _pieJobSource; + + /// + /// Gets or sets the pie job source. + /// public LabeledSeriesCollection PieJobSource { get { return _pieJobSource; } @@ -61,6 +73,10 @@ namespace Tango.MachineStudio.Statistics.Models } private LabeledSeriesCollection _pieJobRunStatus; + + /// + /// Gets or sets the pie job run status. + /// public LabeledSeriesCollection PieJobRunStatus { get { return _pieJobRunStatus; } @@ -68,6 +84,10 @@ namespace Tango.MachineStudio.Statistics.Models } private LabeledSeriesCollection _pieGradientSolid; + + /// + /// Gets or sets the pie gradient solid. + /// public LabeledSeriesCollection PieGradientSolid { get { return _pieGradientSolid; } @@ -75,6 +95,10 @@ namespace Tango.MachineStudio.Statistics.Models } private List _liquidQuantities; + + /// + /// Gets or sets the liquid quantities. + /// public List LiquidQuantities { get @@ -91,6 +115,9 @@ namespace Tango.MachineStudio.Statistics.Models private int _totalLiquidQuantities; + /// + /// Gets or sets the total liquid quantities. + /// public int TotalLiquidQuantities { get { return _totalLiquidQuantities; } @@ -128,6 +155,9 @@ namespace Tango.MachineStudio.Statistics.Models }; } + /// + /// Cleans all values. + /// public void Clean() { StatisticsCollection.Clear(); @@ -138,21 +168,27 @@ namespace Tango.MachineStudio.Statistics.Models PieGradientSolid.SeriesCollection.Clear(); } - public void AddStatisticsValue( string name, double value, string unit) + /// + /// Adds the statistics value. + /// + public void AddStatisticsValue(string name, double value, string unit) { - StatisticsCollection.Add(new StatisticsValue() { Name = name, Value=value, Unit = unit }); + StatisticsCollection.Add(new StatisticsValue() { Name = name, Value = value, Unit = unit }); RaisePropertyChanged("StatisticsCollection"); } + /// + /// Creates the thread consumption per thread. + /// 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 ..." } } }); + ThreadConsumptionPerThreadCollection.Add(new CollectionContainer() { Collection = new List() { new MoreValue() { Text = "More threads ..." } } }); ThreadConsumptionPerThread = threads.Skip(2).ToList(); } - + RaisePropertyChanged("ThreadConsumptionPerThreadCollection"); } @@ -259,6 +295,9 @@ namespace Tango.MachineStudio.Statistics.Models } #endregion + /// + /// Generates the statistics liquid quantity and TotalLiquidQuantities. + /// public void GenerateStatisticsLiquidQuantity(List liquidQuantities) { LiquidQuantities = liquidQuantities; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index d57a1c96c..ed52c2352 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -177,7 +177,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels private Job _selectedJob; /// - /// Gets or sets the job. Used as Sele + /// Gets or sets the job. /// public Job SelectedJob { @@ -188,7 +188,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels RaisePropertyChangedAuto(); } } - + + /// + /// Gets or sets the statistics value collection. Class - container included calculated statistic values. + /// public StatisticsValueCollection StatisticsValueCollection { get; set; } #endregion @@ -356,26 +359,37 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } + #region GenerateS_StatisticsValueCollection + + /// + /// Generates the statistics. + /// protected void GenerateStatistics() { StatisticsValueCollection.Clean(); GenerateTotalRunsLength(); GenerateRunsDuration(); - GenerateUploadDuration(); - GenerateHeatingDuration(); + GenerateAverageUploadDuration(); + GenerateAverageHeatingDuration(); GenerateTotalThreadConsumption(); GeneratePieCharts(); CreateThreadConsumptionPerThread(); GenerateAllLiquidQuantities(); } - + + /// + /// Generates the total length of the job runs. + /// protected void GenerateTotalRunsLength() { double val = JobRuns.Where(z => z.JobRun.EndPosition > 0).Sum(x => x.JobRun.JobLength); StatisticsValueCollection.AddStatisticsValue("Total Runs Length", val, " m"); } + /// + /// Generates the duration and average of the job runs. + /// protected void GenerateRunsDuration() { var selection = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null); @@ -385,26 +399,36 @@ namespace Tango.MachineStudio.Statistics.ViewModels StatisticsValueCollection.AddStatisticsValue("Average Runs Duration", average, " hours"); } - protected void GenerateUploadDuration() + /// + /// Generates the average upload duration of the job runs. + /// + protected void GenerateAverageUploadDuration() { - var val = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.Ticks); - TimeSpan ts = new TimeSpan(Convert.ToInt64(val)); - StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(ts.TotalMinutes, 0), " minutes"); + var average = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null && z.UploadDuration.Value.Ticks > 0).Average(x => x.UploadDuration.Value.TotalMinutes); + StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(average, 0), " minutes"); } - protected void GenerateHeatingDuration() + /// + /// Generates the average duration heating of the job runs. + /// + protected void GenerateAverageHeatingDuration() { - var val = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.HeatingDuration != null).Average(x => x.HeatingDuration.Value.Ticks); - TimeSpan ts = new TimeSpan(Convert.ToInt64(val)); - StatisticsValueCollection.AddStatisticsValue("Average Heating Duration", Math.Max(ts.TotalMinutes, 0), " minutes"); + var average = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.HeatingDuration != null && z.HeatingDuration.Value.Ticks > 0).Average(x => x.HeatingDuration.Value.TotalMinutes); + StatisticsValueCollection.AddStatisticsValue("Average Heating Duration", Math.Max(average, 0), " minutes"); } + /// + /// Generates the total thread consumption by EndPosition. + /// protected void GenerateTotalThreadConsumption() { double val = JobRuns.Where(z => z.JobRun.EndPosition > 0).Sum(x => x.JobRun.EndPosition); StatisticsValueCollection.AddStatisticsValue("Total Thread Consumption", val, " m"); } + /// + /// Generates the pie charts in percentage: JobSource, JobRunStatus, Gradient. + /// protected void GeneratePieCharts() { int PPCCount = JobRuns.Count(x => x.JobRun.Source == JobSource.Local); @@ -422,6 +446,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } + /// + /// Creates the thread consumption per thread. + /// protected void CreateThreadConsumptionPerThread() { var temp = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null).GroupBy(x => x.Rml.Name); @@ -429,6 +456,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels StatisticsValueCollection.CreateThreadConsumptionPerThread(result); } + /// + /// Generates all liquid quantities. + /// protected void GenerateAllLiquidQuantities() { var db_liquidQuantities = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).Select(y=> y.JobRun.LiquidQuantities).ToList(); @@ -436,13 +466,14 @@ namespace Tango.MachineStudio.Statistics.ViewModels foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) { - var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.SingleOrDefault(y => y.LiquidType == ltype)).Where(x=>x!=null); + var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.FirstOrDefault(y => y.LiquidType == ltype)).Where(x=>x!=null); var count = liquidQuantityByTypeList != null ? liquidQuantityByTypeList.Sum(x => x.Quantity) : 0; JobRunLiquidQuantity lq = new JobRunLiquidQuantity() { LiquidType = ltype, Quantity = count }; allLiquidQuantities.Add(lq); } StatisticsValueCollection.GenerateStatisticsLiquidQuantity(allLiquidQuantities); } + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml index 4790402d5..58d94aca1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml @@ -554,13 +554,24 @@ - + - Total Thread Consumption per thread: + + + + + @@ -669,6 +680,16 @@ + + + -- cgit v1.3.1 From 1e563685f9c74fc7cfc204b714a1401002eba5fd Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 15 Mar 2020 17:11:16 +0200 Subject: Machine Studio. Statistics Job Runs page, change colors of pies, a little changes in GUI. --- .../Models/StatisticsValueCollection.cs | 20 ++++++++++++-------- .../ViewModels/JobRunsViewVM.cs | 18 +++++++++--------- .../Views/JobRunsView.xaml | 12 ++++++------ 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') 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 index 2ad165d79..287e09009 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs @@ -11,6 +11,8 @@ 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 { @@ -133,8 +135,10 @@ namespace Tango.MachineStudio.Statistics.Models ThreadConsumptionPerThreadCollection = new CompositeCollection(); _pieColors = new List(); - _pieColors.Add(Color.FromRgb(239, 131, 43));//green - _pieColors.Add(Color.FromRgb(144, 233, 144));//orange + _pieColors.Add(((SolidColorBrush)Application.Current.Resources["RedBrush100"]).Color); + _pieColors.Add(((SolidColorBrush)Application.Current.Resources["OrangeBrush300"]).Color); + _pieColors.Add(((SolidColorBrush)Application.Current.Resources["GreenBrush300"]).Color); + _pieColors.Add(((SolidColorBrush)Application.Current.Resources["BlueBrush100"]).Color); _pieColors.Add(Color.FromRgb(100, 184, 236));//blue @@ -202,7 +206,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "PPC", Values = new ChartValues() { PPCCount }, - Fill = new SolidColorBrush(_pieColors[0]), + Fill = new SolidColorBrush(_pieColors[2]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint @@ -215,7 +219,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "MS", Values = new ChartValues() { MSCount }, - Fill = new SolidColorBrush(_pieColors[2]), + Fill = new SolidColorBrush(_pieColors[3]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint @@ -242,7 +246,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "Aborted", Values = new ChartValues() { abortedCount }, - Fill = new SolidColorBrush(_pieColors[2]), + Fill = new SolidColorBrush(_pieColors[1]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint, @@ -254,7 +258,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "Completed", Values = new ChartValues() { completedCount }, - Fill = new SolidColorBrush(_pieColors[1]), + Fill = new SolidColorBrush(_pieColors[2]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint @@ -270,7 +274,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "Solid", Values = new ChartValues() { solidCount }, - Fill = new SolidColorBrush(_pieColors[0]), + Fill = new SolidColorBrush(_pieColors[2]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint @@ -281,7 +285,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "Gradient", Values = new ChartValues() { gradientCount }, - Fill = new SolidColorBrush(_pieColors[2]), + Fill = new SolidColorBrush(_pieColors[3]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index ed7bbec56..ca40273f9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -368,10 +368,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels { StatisticsValueCollection.Clean(); GenerateTotalRunsLength(); + GenerateTotalThreadConsumption(); GenerateRunsDuration(); GenerateAverageUploadDuration(); GenerateAverageHeatingDuration(); - GenerateTotalThreadConsumption(); GeneratePieCharts(); CreateThreadConsumptionPerThread(); @@ -395,8 +395,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels var selection = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null); double val = selection.Sum(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); StatisticsValueCollection.AddStatisticsValue("Total Runs Duration", val, " hours"); - double average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); - StatisticsValueCollection.AddStatisticsValue("Average Runs Duration", average, " hours"); + double average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalMilliseconds); + StatisticsValueCollection.AddStatisticsValue("Average Runs Duration", Math.Max(TimeSpan.FromMilliseconds(average).TotalHours, 0), " hours"); } /// @@ -404,8 +404,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// protected void GenerateAverageUploadDuration() { - var val = (long)JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.TotalMilliseconds); - StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(TimeSpan.FromMilliseconds(val).TotalMinutes, 0), " minutes"); + var average = (long)JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.TotalMilliseconds); + StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(TimeSpan.FromMilliseconds(average).TotalMinutes, 0), " minutes"); } /// @@ -413,8 +413,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// protected void GenerateAverageHeatingDuration() { - var average = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.HeatingDuration != null && z.HeatingDuration.Value.Ticks > 0).Average(x => x.HeatingDuration.Value.TotalMinutes); - StatisticsValueCollection.AddStatisticsValue("Average Heating Duration", Math.Max(average, 0), " minutes"); + var average = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.HeatingDuration != null && z.HeatingDuration.Value.Ticks > 0).Average(x => x.HeatingDuration.Value.TotalMilliseconds); + StatisticsValueCollection.AddStatisticsValue("Average Heating Duration", Math.Max(TimeSpan.FromMilliseconds(average).TotalMinutes, 0), " minutes"); } /// @@ -423,7 +423,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void GenerateTotalThreadConsumption() { double val = JobRuns.Where(z => z.JobRun.EndPosition > 0).Sum(x => x.JobRun.EndPosition); - StatisticsValueCollection.AddStatisticsValue("Total Thread Consumption", val, " m"); + StatisticsValueCollection.AddStatisticsValue("Actual Total Runs Length", val, " m"); } /// @@ -466,7 +466,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) { - var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.SingleOrDefault(y => y.LiquidType == ltype)).Where(x => x != null); + var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.FirstOrDefault(y => y.LiquidType == ltype)).Where(x => x != null); var count = liquidQuantityByTypeList != null ? liquidQuantityByTypeList.Sum(x => x.Quantity) : 0; JobRunLiquidQuantity lq = new JobRunLiquidQuantity() { LiquidType = ltype, Quantity = count }; allLiquidQuantities.Add(lq); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml index 58d94aca1..057647858 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml @@ -552,7 +552,7 @@ - + @@ -560,7 +560,7 @@ - + - + -- cgit v1.3.1 From ab31d366a5d9e5c6f8e9ce1bcb4e76e9ab46d526 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Mon, 16 Mar 2020 16:12:49 +0200 Subject: MS. Statistic Job Runs page. Add "Total Runs: Integer". --- .../Models/StatisticsValueCollection.cs | 10 +++++----- .../Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | 9 ++++++++- .../Tango.MachineStudio.Statistics/Views/JobRunsView.xaml | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') 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 index eab4eecde..ef5527406 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/StatisticsValueCollection.cs @@ -20,7 +20,7 @@ namespace Tango.MachineStudio.Statistics.Models { public string Name { get; set; } - public double Value { get; set; } + public object Value { get; set; } public string Unit { get; set; } } @@ -139,7 +139,7 @@ namespace Tango.MachineStudio.Statistics.Models _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(100, 184, 236));//blue + _pieColors.Add(Colors.Yellow); PieJobSource = new LabeledSeriesCollection() @@ -175,7 +175,7 @@ namespace Tango.MachineStudio.Statistics.Models /// /// Adds the statistics value. /// - public void AddStatisticsValue(string name, double value, string unit) + public void AddStatisticsValue(string name, object value, string unit) { StatisticsCollection.Add(new StatisticsValue() { Name = name, Value = value, Unit = unit }); RaisePropertyChanged("StatisticsCollection"); @@ -206,7 +206,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "PPC", Values = new ChartValues() { PPCCount }, - Fill = new SolidColorBrush(_pieColors[2]), + Fill = new SolidColorBrush(_pieColors[4]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint @@ -274,7 +274,7 @@ namespace Tango.MachineStudio.Statistics.Models { Title = "Solid", Values = new ChartValues() { solidCount }, - Fill = new SolidColorBrush(_pieColors[2]), + Fill = new SolidColorBrush(_pieColors[4]), DataLabels = true, ToolTip = "", LabelPoint = labelPoint diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index ca40273f9..94d06a178 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -367,6 +367,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void GenerateStatistics() { StatisticsValueCollection.Clean(); + GenerateTotalRunsCount(); GenerateTotalRunsLength(); GenerateTotalThreadConsumption(); GenerateRunsDuration(); @@ -377,7 +378,13 @@ namespace Tango.MachineStudio.Statistics.ViewModels CreateThreadConsumptionPerThread(); GenerateAllLiquidQuantities(); } - + + protected void GenerateTotalRunsCount() + {//Total Runs: + int val =JobRuns.Where(z => z.JobRun.EndPosition > 0).Count(); + StatisticsValueCollection.AddStatisticsValue("Total Runs ", val, " "); + } + /// /// Generates the total length of the job runs. /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml index ecc846903..af363b32a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml @@ -554,7 +554,7 @@ - + -- cgit v1.3.1 From 23e661dfbb74dc67ea097ae331cadd2446997b31 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 18 Mar 2020 11:19:40 +0200 Subject: Machine Studio. Changes in Statistics Job Runs and Action log. Improving data creation performance. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Tango.MachineStudio.ActionLogs.csproj | 3 + .../ViewModels/MainViewVM.cs | 123 ++++++++++++++++-- .../Views/MainView.xaml | 9 +- .../Converters/NanoLiterToLiterFormatConverter.cs | 15 +-- .../Models/StatisticsValueCollection.cs | 19 +-- .../Models/TotalLiquidQuantityModel.cs | 15 +++ .../Tango.MachineStudio.Statistics.csproj | 1 + .../ViewModels/JobRunsViewVM.cs | 138 ++++++++++++++++++--- .../Visual_Studio/Tango.BL/Entities/ActionLog.cs | 22 ++-- 13 files changed, 289 insertions(+), 56 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/TotalLiquidQuantityModel.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index fc06677b0..2324ac49b 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 0eedec06a..7f09eb239 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 332a33b03..0e9e45341 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index ab1f7fc1b..99b7995e4 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj index 280356aa8..de4783237 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj @@ -156,5 +156,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index df2643d88..c1bf63ce4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -24,6 +24,7 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels public class MainViewVM : StudioViewModel { private INotificationProvider _notification; + private List _allUsers; #region Properties @@ -86,6 +87,17 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels set { _differenceObject = value; RaisePropertyChangedAuto(); } } + private bool _isLoading; + + public bool IsLoading + { + get { return _isLoading; } + set { _isLoading = value; RaisePropertyChangedAuto(); } + } + + + + #endregion public RelayCommand SearchCommand { get; set; } @@ -96,6 +108,7 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels { _notification = notification; + IsLoading = false; ActionLogs = new ObservableCollection(); SearchCommand = new RelayCommand(GetActionLogs, () => IsFree); CopyRelateObjectIDCommand = new RelayCommand(CopyRelateObjectID); @@ -111,7 +124,28 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels public override void OnApplicationReady() { + InitUsers(); + } + public async void InitUsers() + { + try + { + IsFree = false; + + using (var db = ObservablesContext.CreateDefault()) + { + _allUsers = await db.Users.Include(x => x.Contact).ToListAsync(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading users."); + } + finally + { + IsFree = true; + } } private void CopyToClipBoard() @@ -129,8 +163,9 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels /// /// New Database Query with search parameters. Initialization ActionLogs property. /// - private async void GetActionLogs() + private void GetActionLogs() { + IsLoading = true; string filter = SearchFilter?.ToLower(); if (String.IsNullOrWhiteSpace(filter)) filter = null; @@ -147,17 +182,48 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); + + var db_ActionLogs = db.ActionLogs.Where(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) + .Select(x => new + { + x.ID,x.Guid,x.UserGuid, x.LastUpdated,x.Type,x.RelatedObjectName, x.RelatedObjectGuid,x.Message + }); + int[] actionTypes = SelectedActionLogTypes.SynchedSource.ToArray().Select(x => (int)x).ToArray(); + if(actionTypes.Length > 0) + { + db_ActionLogs = db_ActionLogs.Where(x => actionTypes.Contains(x.Type)); + } - ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) - .WithUsers() - .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) - .Query(y => y.Where - (x => filter == null || - (x.ID.ToString().ToLower().StartsWith(filter) - || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) + var runs = db_ActionLogs.ToList() + .Select(x => new ActionLog() + { + ID = x.ID,Guid = x.Guid, + UserGuid = x.UserGuid, + LastUpdated = x.LastUpdated, + Type = x.Type, + RelatedObjectName = x.RelatedObjectName, + RelatedObjectGuid = x.RelatedObjectGuid, + Message = x.Message, + User = _allUsers.SingleOrDefault(y => y.Guid == x.UserGuid) + }); + if (!String.IsNullOrEmpty(filter)) + { + runs = runs.Where(x => x.ID.ToString().ToLower().StartsWith(filter) || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) - || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) - .BuildAsync(); + || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))); + } + ActionLogs = runs.ToObservableCollection(); + + //ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) + // .WithUsers() + // .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) + // .Query(y => y.Where + // (x => filter == null || + // (x.ID.ToString().ToLower().StartsWith(filter) + // || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) + // || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) + // || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) + // .BuildAsync(); } } catch (Exception ex) @@ -169,14 +235,49 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels finally { IsFree = true; + IsLoading = false; } } + /// + /// Update DifferenceObject on Selected item changed + /// private void SelectedItemChanged() { - if (SelectedActionLog == null || SelectedActionLog.DifferenceObject == null) + if (SelectedActionLog == null) return; + if(SelectedActionLog.Difference==null) + { + InitSelectedActionLogDifference(); + } DifferenceObject = SelectedActionLog.DifferenceObject; } + + /// + /// Initializes the selected action log difference. + /// + public void InitSelectedActionLogDifference() + { + IsLoading = true; + try + { + using (var db = ObservablesContext.CreateDefault()) + { + var difference = db.ActionLogs.SingleOrDefault(x => x.Guid.Equals(SelectedActionLog.Guid)); + if (difference != null) + { + SelectedActionLog.DifferenceObject = difference.DifferenceObject; + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading difference of the selected action log."); + } + finally + { + IsLoading = false; + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml index fd640bae5..05aad0574 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml @@ -149,13 +149,13 @@ - + - - - + + + -- cgit v1.3.1 From 46fac8b6ce7c0223f005c79281a8d7a65f560a4e Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 22 Mar 2020 16:33:28 +0200 Subject: JobRuns and Action Log - correct date selections. --- .../ViewModels/MainViewVM.cs | 9 ++++----- .../ViewModels/JobRunsViewVM.cs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index c091f1221..069435307 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -185,14 +185,13 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels using (ObservablesContext db = ObservablesContext.CreateDefault()) { - - DateTime startUtc = new DateTime(StartSelectedDate.Date.Ticks, DateTimeKind.Utc); - TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(24, 0, 0); - DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); + DateTime startUtc = StartSelectedDate.ToUniversalTime(); + TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); + DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); - var db_ActionLogs = db.ActionLogs.Where(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) + var db_ActionLogs = db.ActionLogs.Where(x => x.LastUpdated <= endUtc && x.LastUpdated >= startUtc.Date) .Select(x => new { x.ID, diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index 6be0948a9..254dcd6e1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -82,7 +82,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels public DateTime StartSelectedDate { get { return _startSelectedDate; } - set { _startSelectedDate = value; RaisePropertyChangedAuto(); } + set { _startSelectedDate = value; + RaisePropertyChangedAuto(); } } private DateTime _endSelectedDate; @@ -322,11 +323,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels DateTime startUtc = StartSelectedDate.ToUniversalTime(); TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; - string jobName = SelectedJob == null ? "" : SelectedJob.Name; - - - var db_JobRuns = db.JobRuns.Where(x => x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date)) + string jobName = SelectedJob == null ? "" : SelectedJob.Name; + + var db_JobRuns = db.JobRuns.Where(x => (x.StartDate <= endUtc && x.StartDate >= startUtc.Date)) .Select(x => new { x.ID, @@ -355,8 +355,6 @@ namespace Tango.MachineStudio.Statistics.ViewModels x.LubricantQuantity, x.CleanerQuantity }); - - var machineIDs = new HashSet(SelectedMachines.SynchedSource.ToList().Select(p => p.Guid)); if (machineIDs.Count > 0) { @@ -419,7 +417,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels LubricantQuantity = x.LubricantQuantity, CleanerQuantity = x.CleanerQuantity }).ToList(); - + var modelList = runs.Select(x => new JobRunModel() { JobRun = x, @@ -454,6 +452,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void GenerateStatistics() { StatisticsValueCollection.Clean(); + if (JobRuns.Count() == 0) + return; GenerateTotalRunsCount(); GenerateTotalRunsLength(); GenerateTotalThreadConsumption(); -- cgit v1.3.1 From ff15e093dd28bd1c02e00c14853aa8c24153995c Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Mon, 23 Mar 2020 12:54:59 +0200 Subject: Job Runs and Action logs. Changed start time. Related Work Items: #2574 --- .../Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs | 6 +++--- .../Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index 069435307..3e5c59fee 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -185,13 +185,13 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels using (ObservablesContext db = ObservablesContext.CreateDefault()) { - DateTime startUtc = StartSelectedDate.ToUniversalTime(); + DateTime startUtc = new DateTime(StartSelectedDate.Year, StartSelectedDate.Month, StartSelectedDate.Day, 0, 0, 0).ToUniversalTime(); TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; - Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); + Debug.Write($"TEST TIME {startUtc} to {endUtc} "+ System.Environment.NewLine); - var db_ActionLogs = db.ActionLogs.Where(x => x.LastUpdated <= endUtc && x.LastUpdated >= startUtc.Date) + var db_ActionLogs = db.ActionLogs.Where(x => x.LastUpdated <= endUtc && x.LastUpdated >= startUtc) .Select(x => new { x.ID, diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index 254dcd6e1..800346ff9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -320,13 +320,13 @@ namespace Tango.MachineStudio.Statistics.ViewModels using (var db = ObservablesContext.CreateDefault()) { - DateTime startUtc = StartSelectedDate.ToUniversalTime(); + DateTime startUtc = new DateTime(StartSelectedDate.Year, StartSelectedDate.Month, StartSelectedDate.Day, 0, 0, 0).ToUniversalTime(); TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; string jobName = SelectedJob == null ? "" : SelectedJob.Name; - var db_JobRuns = db.JobRuns.Where(x => (x.StartDate <= endUtc && x.StartDate >= startUtc.Date)) + var db_JobRuns = db.JobRuns.Where(x => (x.StartDate <= endUtc && x.StartDate >= startUtc)) .Select(x => new { x.ID, -- cgit v1.3.1