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. --- .../ViewModels/JobRunsViewVM.cs | 138 ++++++++++++++++++--- 1 file changed, 120 insertions(+), 18 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels') 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 94d06a178..b0c4975ee 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 @@ -20,6 +20,7 @@ using System.Windows.Media; using LiveCharts.Wpf; using LiveCharts; using Tango.BL.ValueObjects; +using System.Diagnostics; namespace Tango.MachineStudio.Statistics.ViewModels { @@ -322,16 +323,86 @@ namespace Tango.MachineStudio.Statistics.ViewModels 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 runs = await new JobRunsCollectionBuilder(db).Set(x => x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date)) - .WithMachines(SelectedMachines.SynchedSource.ToList()) - .WithJobSource(JobRunSelectedSources.SynchedSource) - .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())) - && (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))) - .BuildListAsync(); + var db_JobRuns = db.JobRuns.Where(x=> x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date)) + .Select(x => new + { + x.ID, + x.ActualStartDate, + x.EndDate, + x.EndPosition, + x.GradientResolutionCm, + x.Guid, + x.HeatingStartDate, + x.IsGradient, + x.JobGuid, + x.JobLength, + x.JobName, + x.JobSource, + x.MachineGuid, + x.RmlGuid, + x.StartDate, + x.Status, + x.UploadingStartDate, + x.UserGuid, + x.LiquidQuantityString, + }); + var machineIDs = new HashSet(SelectedMachines.SynchedSource.ToList().Select(p => p.Guid)); + if(machineIDs.Count > 0) + { + db_JobRuns = db_JobRuns.Where(x => machineIDs.Contains(x.MachineGuid)); + } + int[] jobRunSourceArr = JobRunSelectedSources.SynchedSource.Select(x => (int)x).ToArray(); + if(jobRunSourceArr.Length > 0) + { + db_JobRuns = db_JobRuns.Where(x => jobRunSourceArr.Contains(x.JobSource)); + } + int[] jobRunStatusArr = JobRunSelectedStatuses.SynchedSource.Select(x => (int)x).ToArray(); + if(jobRunStatusArr.Length > 0) + { + db_JobRuns = db_JobRuns.Where(x => jobRunStatusArr.Contains(x.Status)); + } + bool[] isGradientArr = IsGradientSelection.SynchedSource.Select(x => (bool)x).ToArray(); + if(isGradientArr.Length > 0) + { + db_JobRuns = db_JobRuns.Where(x => isGradientArr.Contains(x.IsGradient)); + } + List rmlGuids = SelectedThreads.SynchedSource.Select(y => y.Guid).ToList(); + if (rmlGuids != null && rmlGuids.Count > 0) + { + db_JobRuns = db_JobRuns.Where(x => rmlGuids.Contains(x.RmlGuid)); + } + if(!String.IsNullOrEmpty(jobName)) + { + db_JobRuns = db_JobRuns.Where(x => x.JobName.ToLower().StartsWith(jobName.ToLower())); + } + + List runs = db_JobRuns.ToList() + .Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue)) + .Select(x => new JobRun() + { + ID = x.ID, + ActualStartDate = x.ActualStartDate, + EndDate = x.EndDate, + EndPosition = x.EndPosition, + GradientResolutionCm = x.GradientResolutionCm, + Guid = x.Guid, + HeatingStartDate = x.HeatingStartDate, + IsGradient = x.IsGradient, + JobGuid = x.JobGuid, + JobLength = x.JobLength, + JobName = x.JobName, + JobSource = x.JobSource, + MachineGuid = x.MachineGuid, + RmlGuid = x.RmlGuid, + StartDate = x.StartDate, + Status = x.Status, + UploadingStartDate = x.UploadingStartDate, + UserGuid = x.UserGuid, + LiquidQuantityString = x.LiquidQuantityString, + }).ToList(); var modelList = runs.Select(x => new JobRunModel() { @@ -381,7 +452,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void GenerateTotalRunsCount() {//Total Runs: - int val =JobRuns.Where(z => z.JobRun.EndPosition > 0).Count(); + int val = JobRuns.Count(); StatisticsValueCollection.AddStatisticsValue("Total Runs ", val, " "); } @@ -400,9 +471,14 @@ namespace Tango.MachineStudio.Statistics.ViewModels 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); + double val = 0d; + double average = 0d; + if (selection != null && selection.Count() > 0) + { + val = selection.Sum(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); + average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalMilliseconds); + } StatisticsValueCollection.AddStatisticsValue("Total Runs Duration", val, " 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"); } @@ -468,16 +544,42 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// 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(); + var runs = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).ToList(); + + Dictionary total_quantities = new Dictionary(); foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) { - 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); + total_quantities[ltype] = 0; } + + foreach (var run in runs) + { + foreach (var lq in run.JobRun.LiquidQuantities) + { + if (lq.Quantity < 0) + { + Debug.WriteLine($"Warning: JobRun '{run.JobRun.ID}' contains an invalid value '{lq.Quantity}' for {lq.LiquidType} quantity."); + } + + total_quantities[lq.LiquidType] += Convert.ToUInt64(Math.Max(lq.Quantity, 0)); + } + } + + List allLiquidQuantities = total_quantities.Select(x => new TotalLiquidQuantityModel() + { + LiquidType = x.Key, + Quantity = x.Value + }).ToList(); + + + //foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) + //{ + // 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 -- cgit v1.3.1 From 19a6a9d026f3436afd9af7923db7ee6cbd861772 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 18 Mar 2020 16:48:17 +0200 Subject: Job Runs, Action Logs - added async method to loading data. --- .../ViewModels/MainViewVM.cs | 49 ++++++++------- .../Views/MainView.xaml | 5 +- .../ViewModels/JobRunsViewVM.cs | 70 ++++++++++++---------- Software/Visual_Studio/Tango.BL/Entities/JobRun.cs | 25 ++++++++ 4 files changed, 89 insertions(+), 60 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels') 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 c1bf63ce4..50ec7f7a5 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 @@ -110,7 +110,7 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels IsLoading = false; ActionLogs = new ObservableCollection(); - SearchCommand = new RelayCommand(GetActionLogs, () => IsFree); + SearchCommand = new RelayCommand(async () => await GetActionLogs(), () => IsFree); CopyRelateObjectIDCommand = new RelayCommand(CopyRelateObjectID); CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard, () => SelectedActionLog != null && SelectedActionLog.DifferenceObject != null); DateTime now = DateTime.Now; @@ -159,11 +159,11 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels DataObject data = new DataObject(SelectedActionLog.RelatedObjectGuid); System.Windows.Clipboard.SetDataObject(data); } - + /// /// New Database Query with search parameters. Initialization ActionLogs property. /// - private void GetActionLogs() + private async Task GetActionLogs() { IsLoading = true; string filter = SearchFilter?.ToLower(); @@ -182,22 +182,31 @@ 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 + 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) + if (actionTypes.Length > 0) { db_ActionLogs = db_ActionLogs.Where(x => actionTypes.Contains(x.Type)); } - var runs = db_ActionLogs.ToList() - .Select(x => new ActionLog() + var runs_db = await db_ActionLogs.ToListAsync(); + var runs = runs_db.Select(x => new ActionLog() { - ID = x.ID,Guid = x.Guid, + ID = x.ID, + Guid = x.Guid, UserGuid = x.UserGuid, LastUpdated = x.LastUpdated, Type = x.Type, @@ -206,6 +215,7 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels 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)) @@ -213,17 +223,6 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels || (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) @@ -242,13 +241,13 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels /// /// Update DifferenceObject on Selected item changed /// - private void SelectedItemChanged() + private async void SelectedItemChanged() { if (SelectedActionLog == null) return; - if(SelectedActionLog.Difference==null) + if (SelectedActionLog.Difference == null) { - InitSelectedActionLogDifference(); + await InitSelectedActionLogDifference(); } DifferenceObject = SelectedActionLog.DifferenceObject; } @@ -256,14 +255,14 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels /// /// Initializes the selected action log difference. /// - public void InitSelectedActionLogDifference() + public async Task InitSelectedActionLogDifference() { IsLoading = true; try { using (var db = ObservablesContext.CreateDefault()) { - var difference = db.ActionLogs.SingleOrDefault(x => x.Guid.Equals(SelectedActionLog.Guid)); + var difference = await db.ActionLogs.SingleOrDefaultAsync(x => x.Guid.Equals(SelectedActionLog.Guid)); if (difference != null) { SelectedActionLog.DifferenceObject = difference.DifferenceObject; 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 05aad0574..b077f6088 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 @@ -82,8 +82,9 @@ - - + + + 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 b0c4975ee..3aa93cd3e 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 @@ -323,49 +323,51 @@ namespace Tango.MachineStudio.Statistics.ViewModels 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)) + + + var db_JobRuns = db.JobRuns.Where(x => x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date)) .Select(x => new - { - x.ID, - x.ActualStartDate, - x.EndDate, - x.EndPosition, - x.GradientResolutionCm, - x.Guid, - x.HeatingStartDate, - x.IsGradient, - x.JobGuid, - x.JobLength, - x.JobName, - x.JobSource, - x.MachineGuid, - x.RmlGuid, - x.StartDate, - x.Status, - x.UploadingStartDate, - x.UserGuid, - x.LiquidQuantityString, - }); + { + x.ID, + x.ActualStartDate, + x.EndDate, + x.EndPosition, + x.GradientResolutionCm, + x.Guid, + x.HeatingStartDate, + x.IsGradient, + x.JobGuid, + x.JobLength, + x.JobName, + x.JobSource, + x.MachineGuid, + x.RmlGuid, + x.StartDate, + x.Status, + x.UploadingStartDate, + x.UserGuid, + x.LiquidQuantityString, + }); + + var machineIDs = new HashSet(SelectedMachines.SynchedSource.ToList().Select(p => p.Guid)); - if(machineIDs.Count > 0) + if (machineIDs.Count > 0) { db_JobRuns = db_JobRuns.Where(x => machineIDs.Contains(x.MachineGuid)); } int[] jobRunSourceArr = JobRunSelectedSources.SynchedSource.Select(x => (int)x).ToArray(); - if(jobRunSourceArr.Length > 0) + if (jobRunSourceArr.Length > 0) { db_JobRuns = db_JobRuns.Where(x => jobRunSourceArr.Contains(x.JobSource)); } int[] jobRunStatusArr = JobRunSelectedStatuses.SynchedSource.Select(x => (int)x).ToArray(); - if(jobRunStatusArr.Length > 0) + if (jobRunStatusArr.Length > 0) { db_JobRuns = db_JobRuns.Where(x => jobRunStatusArr.Contains(x.Status)); } bool[] isGradientArr = IsGradientSelection.SynchedSource.Select(x => (bool)x).ToArray(); - if(isGradientArr.Length > 0) + if (isGradientArr.Length > 0) { db_JobRuns = db_JobRuns.Where(x => isGradientArr.Contains(x.IsGradient)); } @@ -374,13 +376,15 @@ namespace Tango.MachineStudio.Statistics.ViewModels { db_JobRuns = db_JobRuns.Where(x => rmlGuids.Contains(x.RmlGuid)); } - if(!String.IsNullOrEmpty(jobName)) + if (!String.IsNullOrEmpty(jobName)) { db_JobRuns = db_JobRuns.Where(x => x.JobName.ToLower().StartsWith(jobName.ToLower())); } - - List runs = db_JobRuns.ToList() - .Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue)) + + var runs_db = await db_JobRuns.ToListAsync(); //Execute actual query. + + + List runs = runs_db.Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue)) .Select(x => new JobRun() { ID = x.ID, @@ -473,7 +477,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels var selection = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null); double val = 0d; double average = 0d; - if (selection != null && selection.Count() > 0) + if (selection != null && selection.Count() > 0) { val = selection.Sum(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalMilliseconds); diff --git a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs index 45bfd9840..468af8043 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs @@ -83,6 +83,31 @@ namespace Tango.BL.Entities } } + + private List _liquidQuantitiesFast; + [NotMapped] + [JsonIgnore] + public List LiquidQuantitiesFast + { + get + { + if (_liquidQuantitiesFast == null) + { + _liquidQuantitiesFast = new List(); + + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Cyan, Quantity = CyanQuantity }); + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Magenta, Quantity = MagentaQuantity }); + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Yellow, Quantity = YellowQuantity }); + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Black, Quantity = BlackQuantity }); + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.TransparentInk, Quantity = TransparentQuantity }); + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Lubricant, Quantity = LubricantQuantity }); + _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Cleaner, Quantity = CleanerQuantity }); + } + + return _liquidQuantitiesFast; + } + } + private JobFile _jobFile; [NotMapped] [JsonIgnore] -- cgit v1.3.1 From 97f0f9cf442681560b9ca59b437804b9dc85e981 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 18 Mar 2020 18:17:50 +0200 Subject: Some improvements to job runs. --- .../Converters/JobLengthConverter.cs | 8 ++++++- .../Models/StatisticsValueCollection.cs | 14 +++++++----- .../ViewModels/JobRunsViewVM.cs | 26 ++++++++++++++++------ .../Views/JobRunsView.xaml | 4 ++-- .../Views/MainView.xaml | 6 ++--- 5 files changed, 39 insertions(+), 19 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels') 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 index b730d7881..cd928d9c9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/JobLengthConverter.cs @@ -19,7 +19,13 @@ namespace Tango.MachineStudio.Statistics.Converters double length = (double)values[0]; double endPoint = (double)values[1]; double width = (double)values[2]; - return Math.Round((endPoint / length) * width, MidpointRounding.AwayFromZero); + var v = Math.Round((endPoint / length) * width, MidpointRounding.AwayFromZero); + + if (double.IsInfinity(v)) + { + return 0d; + } + return v; } } 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 acbbde3f2..b5615e4d1 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 @@ -29,7 +29,7 @@ namespace Tango.MachineStudio.Statistics.Models public string Text { get; set; } } - public class StatisticsValueCollection: ExtendedObject + public class StatisticsValueCollection : ExtendedObject { private List _pieColors; @@ -43,7 +43,9 @@ namespace Tango.MachineStudio.Statistics.Models public ObservableCollection StatisticsCollection { get { return _statisticsCollection; } - set { _statisticsCollection = value; + set + { + _statisticsCollection = value; RaisePropertyChangedAuto(); } } @@ -139,7 +141,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(Colors.Yellow); + _pieColors.Add(Color.FromRgb(255, 216, 76)); PieJobSource = new LabeledSeriesCollection() @@ -214,7 +216,7 @@ namespace Tango.MachineStudio.Statistics.Models }; PieJobSource.SeriesCollection.Add(series); - + series = new PieSeries() { Title = "MS", @@ -250,7 +252,7 @@ namespace Tango.MachineStudio.Statistics.Models DataLabels = true, ToolTip = "", LabelPoint = labelPoint, - + }; PieJobRunStatus.SeriesCollection.Add(series); @@ -294,7 +296,7 @@ namespace Tango.MachineStudio.Statistics.Models PieGradientSolid.SeriesCollection.Add(series); - + RaisePropertyChanged("PieGradientSolid"); } #endregion 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 3aa93cd3e..6be0948a9 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 @@ -347,7 +347,13 @@ namespace Tango.MachineStudio.Statistics.ViewModels x.Status, x.UploadingStartDate, x.UserGuid, - x.LiquidQuantityString, + x.CyanQuantity, + x.MagentaQuantity, + x.YellowQuantity, + x.BlackQuantity, + x.TransparentQuantity, + x.LubricantQuantity, + x.CleanerQuantity }); @@ -405,7 +411,13 @@ namespace Tango.MachineStudio.Statistics.ViewModels Status = x.Status, UploadingStartDate = x.UploadingStartDate, UserGuid = x.UserGuid, - LiquidQuantityString = x.LiquidQuantityString, + CyanQuantity = x.CyanQuantity, + MagentaQuantity = x.MagentaQuantity, + YellowQuantity = x.YellowQuantity, + BlackQuantity = x.BlackQuantity, + TransparentQuantity = x.TransparentQuantity, + LubricantQuantity = x.LubricantQuantity, + CleanerQuantity = x.CleanerQuantity }).ToList(); var modelList = runs.Select(x => new JobRunModel() @@ -482,8 +494,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels val = selection.Sum(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours); average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalMilliseconds); } - StatisticsValueCollection.AddStatisticsValue("Total Runs Duration", val, " hours"); - StatisticsValueCollection.AddStatisticsValue("Average Runs Duration", Math.Max(TimeSpan.FromMilliseconds(average).TotalHours, 0), " hours"); + StatisticsValueCollection.AddStatisticsValue("Total Dyeing Time", val, " hours"); + StatisticsValueCollection.AddStatisticsValue("Total Dyeing Time", Math.Max(TimeSpan.FromMilliseconds(average).TotalHours, 0), " hours"); } /// @@ -510,7 +522,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("Actual Total Runs Length", val, " m"); + StatisticsValueCollection.AddStatisticsValue("Total Dyeing Length", val, " m"); } /// @@ -548,7 +560,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// protected void GenerateAllLiquidQuantities() { - var runs = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).ToList(); + var runs = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantitiesFast.Count > 0).ToList(); Dictionary total_quantities = new Dictionary(); @@ -559,7 +571,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels foreach (var run in runs) { - foreach (var lq in run.JobRun.LiquidQuantities) + foreach (var lq in run.JobRun.LiquidQuantitiesFast) { if (lq.Quantity < 0) { 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 af363b32a..6431d72fb 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 @@ -326,7 +326,7 @@ - + @@ -466,7 +466,7 @@ - + - - - + + + -- 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/ViewModels') 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/ViewModels') 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