From 334ecf334ea1d69c948e793c06f6182f2b2415b3 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 19 Aug 2020 04:27:28 +0300 Subject: Implemented insights machine statuses. --- .../Modules/Tango.FSE.Insights/Images/dyeing.png | Bin 0 -> 1281 bytes .../Modules/Tango.FSE.Insights/Images/error.png | Bin 0 -> 810 bytes .../Tango.FSE.Insights/Images/getting_ready.png | Bin 0 -> 586 bytes .../Tango.FSE.Insights/Images/machine_off.png | Bin 0 -> 861 bytes .../Tango.FSE.Insights/Images/ready_to_dye.png | Bin 0 -> 891 bytes .../Modules/Tango.FSE.Insights/Images/service.png | Bin 0 -> 844 bytes .../Tango.FSE.Insights/Images/shutting_down.png | Bin 0 -> 1190 bytes .../Modules/Tango.FSE.Insights/Images/stand_by.png | Bin 0 -> 2250 bytes .../Tango.FSE.Insights/Tango.FSE.Insights.csproj | 12 +++++ .../Modules/Tango.FSE.Insights/Themes/Generic.xaml | 56 ++++++++++++++++++--- .../ViewModels/InsightsViewVM.cs | 32 ++++++++---- .../Tango.FSE.Common/Insights/InsightReadyBase.cs | 13 +++++ .../Tango.FSE.Common/Insights/InsightsPackage.cs | 2 + .../Insights/InsightsReadyEvent.cs | 9 +++- .../Insights/InsightsReadyStatus.cs | 14 ++++++ .../FSE/Tango.FSE.Common/Tango.FSE.Common.csproj | 2 + .../Insights/DefaultInsightsProvider.cs | 12 ++++- .../Insights/DefaultInsightsService.cs | 2 +- .../Visual_Studio/Tango.Insights/InsightsEvent.cs | 1 + .../Visual_Studio/Tango.Insights/InsightsFile.cs | 3 ++ .../Tango.Insights/InsightsListener.cs | 26 +++++++++- .../Tango.Insights/InsightsManager.cs | 39 +++++++++++--- .../Visual_Studio/Tango.Insights/InsightsStatus.cs | 20 ++++++++ .../Tango.Insights/Tango.Insights.csproj | 1 + 24 files changed, 214 insertions(+), 30 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/dyeing.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/error.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/getting_ready.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/machine_off.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/ready_to_dye.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/service.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/shutting_down.png create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/stand_by.png create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightReadyBase.cs create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyStatus.cs create mode 100644 Software/Visual_Studio/Tango.Insights/InsightsStatus.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/dyeing.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/dyeing.png new file mode 100644 index 000000000..fbace4fa5 Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/dyeing.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/error.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/error.png new file mode 100644 index 000000000..b4b50e4ac Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/error.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/getting_ready.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/getting_ready.png new file mode 100644 index 000000000..a0dc77f92 Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/getting_ready.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/machine_off.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/machine_off.png new file mode 100644 index 000000000..6dc569e35 Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/machine_off.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/ready_to_dye.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/ready_to_dye.png new file mode 100644 index 000000000..7edf624be Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/ready_to_dye.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/service.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/service.png new file mode 100644 index 000000000..ba351ee66 Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/service.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/shutting_down.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/shutting_down.png new file mode 100644 index 000000000..9aa8e2db6 Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/shutting_down.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/stand_by.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/stand_by.png new file mode 100644 index 000000000..ab4115527 Binary files /dev/null and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/stand_by.png differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Tango.FSE.Insights.csproj b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Tango.FSE.Insights.csproj index 623783f98..64390a713 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Tango.FSE.Insights.csproj +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Tango.FSE.Insights.csproj @@ -223,6 +223,18 @@ + + + + + + + + + + + + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml index 4c8731fa1..129dbb052 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml @@ -3,18 +3,24 @@ xmlns:commonControls="clr-namespace:Tango.FSE.Common.Controls;assembly=Tango.FSE.Common" xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:commonInsights="clr-namespace:Tango.FSE.Common.Insights;assembly=Tango.FSE.Common" xmlns:local="clr-namespace:Tango.FSE.Diagnostics.Themes"> - + - # + # - + + + Error + + + @@ -33,19 +39,19 @@ - + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs index e5d09c282..557035f20 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs @@ -376,7 +376,7 @@ namespace Tango.FSE.Insights.ViewModels } } - PlotInsightsEvents(package); + PlotAnnotations(package); InsightsPackage = package; View.ZoomExtents(); }); @@ -399,19 +399,29 @@ namespace Tango.FSE.Insights.ViewModels Annotations.Add(line); } - private void PlotInsightsEvents(InsightsPackage package) + private void PlotAnnotations(InsightsPackage package) { - double y = 0.05; + var y = 0.05; - foreach (var ev in package.Events) + foreach (var insight in package.Events.Cast().Concat(package.Statuses).OrderBy(x => x.Time)) { - CustomAnnotation eventBox = new CustomAnnotation(); - eventBox.X1 = ev.Time.ToLocalTime(); - eventBox.Y1 = y; - eventBox.CoordinateMode = AnnotationCoordinateMode.RelativeY; - eventBox.Content = ev.EventType; - eventBox.ContentTemplate = Application.Current.Resources["InsightEventTemplate"] as DataTemplate; - Annotations.Add(eventBox); + CustomAnnotation annotation = new CustomAnnotation(); + annotation.X1 = insight.Time.ToLocalTime(); + annotation.Y1 = y; + annotation.CoordinateMode = AnnotationCoordinateMode.RelativeY; + + if (insight is InsightsReadyEvent ev) + { + annotation.Content = ev; + annotation.ContentTemplate = Application.Current.Resources["InsightEventTemplate"] as DataTemplate; + } + else if (insight is InsightsReadyStatus status) + { + annotation.Content = status; + annotation.ContentTemplate = Application.Current.Resources["InsightStatusTemplate"] as DataTemplate; + } + + Annotations.Add(annotation); y += 0.05; diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightReadyBase.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightReadyBase.cs new file mode 100644 index 000000000..84116ccf2 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightReadyBase.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Common.Insights +{ + public abstract class InsightReadyBase + { + public DateTime Time { get; set; } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs index 96718f6bf..25e375b4c 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs @@ -12,11 +12,13 @@ namespace Tango.FSE.Common.Insights { public List Frames { get; set; } public List Events { get; set; } + public List Statuses { get; set; } public InsightsPackage() { Frames = new List(); Events = new List(); + Statuses = new List(); } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyEvent.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyEvent.cs index 0378e6a5a..8c71c2dbf 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyEvent.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyEvent.cs @@ -7,10 +7,15 @@ using Tango.BL.Entities; namespace Tango.FSE.Common.Insights { - public class InsightsReadyEvent + public class InsightsReadyEvent : InsightReadyBase { - public DateTime Time { get; set; } public EventType EventType { get; set; } + public String Description { get; set; } + + public bool HasDescription + { + get { return Description != null; } + } public override string ToString() { diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyStatus.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyStatus.cs new file mode 100644 index 000000000..72112fc77 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyStatus.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Operation; + +namespace Tango.FSE.Common.Insights +{ + public class InsightsReadyStatus : InsightReadyBase + { + public MachineStatuses Status { get; set; } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj index d2208615b..64a165530 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj @@ -226,12 +226,14 @@ + + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs index 1e9996bd2..0f0531bce 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs @@ -69,7 +69,7 @@ namespace Tango.FSE.UI.Insights int progress = 0; - foreach (var frame in insightsFile.Frames.OrderBy(xx => xx.Time)) + foreach (var frame in insightsFile.Frames) { if (handler.Status == InsightsHandlerStatus.Aborted) { @@ -104,12 +104,22 @@ namespace Tango.FSE.UI.Insights { Time = ev.Time, EventType = eventType, + Description = ev.Description, }); progress++; handler.Progress = new TangoProgress("Composing insights...", false, progress, insightsFile.Events.Count); } + foreach (var machineStatus in insightsFile.Statuses) + { + package.Statuses.Add(new InsightsReadyStatus() + { + Time = machineStatus.Time, + Status = machineStatus.Status + }); + } + handler.RaiseCompleted(package); } catch (Exception ex) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs index 24852d853..c51485f29 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs @@ -76,7 +76,7 @@ namespace Tango.PPC.Common.Insights var frames = InsightsManager.Default.GetFrames(request.StartDateUTC, request.EndDateUTC); insightsFile.Frames = frames; insightsFile.Events = InsightsManager.Default.GetEvents(request.StartDateUTC, request.EndDateUTC); - + insightsFile.Statuses = InsightsManager.Default.GetStatuses(request.StartDateUTC, request.EndDateUTC); insightsFile.ToFile(filePath); }); diff --git a/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs b/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs index b3f73e24b..a947b89b2 100644 --- a/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs +++ b/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs @@ -10,5 +10,6 @@ namespace Tango.Insights { public DateTime Time { get; set; } public int EventCode { get; set; } + public String Description { get; set; } } } diff --git a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs index 8250dfb9d..4eba06035 100644 --- a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs +++ b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs @@ -15,10 +15,13 @@ namespace Tango.Insights public List Events { get; set; } + public List Statuses { get; set; } + public InsightsFile() { Frames = new List(); Events = new List(); + Statuses = new List(); } public Stream ToStream() diff --git a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs index 12d38e846..40d6502f0 100644 --- a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs +++ b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs @@ -43,6 +43,7 @@ namespace Tango.Insights _operator = machineOperator; _operator.DiagnosticsDataAvailable += _operator_DiagnosticsDataAvailable; + _operator.StatusChanged += _operator_StatusChanged; } public InsightsListener(IMachineOperator machineOperator) : this(InsightsManager.Default, machineOperator) @@ -125,6 +126,25 @@ namespace Tango.Insights } } + private void _operator_StatusChanged(object sender, MachineStatuses status) + { + Task.Factory.StartNew(() => + { + try + { + _manager.InsertStatus(new InsightsStatus() + { + Status = status, + Time = DateTime.UtcNow + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error inserting insights machine status."); + } + }); + } + private void _timer_Elapsed(object sender, ElapsedEventArgs e) { if (!IsStarted || _writing) return; @@ -159,8 +179,12 @@ namespace Tango.Insights if (_timerCount >= _deleteTicks) { _timerCount = 0; - int deleted = _manager.DeleteFrames(DateTime.UtcNow.Subtract(MaxStorageDuration)); + var maxDate = DateTime.UtcNow.Subtract(MaxStorageDuration); + int deleted = _manager.DeleteFrames(maxDate); Debug.WriteLine($"{deleted} insights frames deleted."); + + deleted = _manager.DeleteStatuses(maxDate); + Debug.WriteLine($"{deleted} insights machine statuses deleted."); } } catch (Exception ex) diff --git a/Software/Visual_Studio/Tango.Insights/InsightsManager.cs b/Software/Visual_Studio/Tango.Insights/InsightsManager.cs index 65cb2b869..b0c7b78ac 100644 --- a/Software/Visual_Studio/Tango.Insights/InsightsManager.cs +++ b/Software/Visual_Studio/Tango.Insights/InsightsManager.cs @@ -7,12 +7,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL; +using Tango.BL.Enumerations; namespace Tango.Insights { public class InsightsManager : IDisposable { private const string INSIGHTS_COLLECTION = "Insights"; + private const string STATUSES_COLLECTION = "Statuses"; private static InsightsManager _instance; public static InsightsManager Default @@ -57,26 +59,49 @@ namespace Tango.Insights Dispose(); } - private ILiteCollection GetCollection() + private ILiteCollection GetInsightsCollection() { return _database.GetCollection(INSIGHTS_COLLECTION); } + private ILiteCollection GetStatusesCollection() + { + return _database.GetCollection(STATUSES_COLLECTION); + } + public virtual void InsertFrame(InsightsFrame frame) { - var collection = GetCollection(); + var collection = GetInsightsCollection(); collection.Insert(frame); } + public virtual void InsertStatus(InsightsStatus status) + { + var collection = GetStatusesCollection(); + collection.Insert(status); + } + public virtual List GetFrames(DateTime startUTC, DateTime endUTC) { - var collection = GetCollection(); + var collection = GetInsightsCollection(); + return collection.Find(x => x.Time >= startUTC && x.Time <= endUTC).ToList().OrderBy(x => x.Time).ToList(); + } + + public virtual List GetStatuses(DateTime startUTC, DateTime endUTC) + { + var collection = GetStatusesCollection(); return collection.Find(x => x.Time >= startUTC && x.Time <= endUTC).ToList().OrderBy(x => x.Time).ToList(); } public virtual int DeleteFrames(DateTime maxDateUTC) { - var collection = GetCollection(); + var collection = GetInsightsCollection(); + return collection.DeleteMany(x => x.Time < maxDateUTC); + } + + public virtual int DeleteStatuses(DateTime maxDateUTC) + { + var collection = GetStatusesCollection(); return collection.DeleteMany(x => x.Time < maxDateUTC); } @@ -90,13 +115,15 @@ namespace Tango.Insights .Select(x => new InsightsEvent() { Time = x.DateTime, - EventCode = x.EventType.Code + EventCode = x.EventType.Code, + Description = x.Description }) .ToList() .Select(x => new InsightsEvent() { Time = new DateTime(x.Time.Ticks, DateTimeKind.Utc), - EventCode = x.EventCode + EventCode = x.EventCode, + Description = ((EventTypes)x.EventCode == EventTypes.JOB_FAILED ? x.Description : null) }) .OrderBy(x => x.Time) .ToList(); diff --git a/Software/Visual_Studio/Tango.Insights/InsightsStatus.cs b/Software/Visual_Studio/Tango.Insights/InsightsStatus.cs new file mode 100644 index 000000000..0bae23b1f --- /dev/null +++ b/Software/Visual_Studio/Tango.Insights/InsightsStatus.cs @@ -0,0 +1,20 @@ +using LiteDB; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Operation; + +namespace Tango.Insights +{ + public class InsightsStatus + { + [BsonId(true)] + [JsonIgnore] + public int Id { get; set; } + public DateTime Time { get; set; } + public MachineStatuses Status { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj index 9bd24e263..1e440a62c 100644 --- a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj +++ b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj @@ -49,6 +49,7 @@ + -- cgit v1.3.1