diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-19 04:27:28 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-19 04:27:28 +0300 |
| commit | 334ecf334ea1d69c948e793c06f6182f2b2415b3 (patch) | |
| tree | cbd40e9229e3b128b113e59477aab9fdb00c9ef9 /Software/Visual_Studio | |
| parent | 4e216a0ca8ad3608b845fa445b73034e1a67b8af (diff) | |
| download | Tango-334ecf334ea1d69c948e793c06f6182f2b2415b3.tar.gz Tango-334ecf334ea1d69c948e793c06f6182f2b2415b3.zip | |
Implemented insights machine statuses.
Diffstat (limited to 'Software/Visual_Studio')
24 files changed, 214 insertions, 30 deletions
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 Binary files differnew file mode 100644 index 000000000..fbace4fa5 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/dyeing.png 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 Binary files differnew file mode 100644 index 000000000..b4b50e4ac --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/error.png 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 Binary files differnew file mode 100644 index 000000000..a0dc77f92 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/getting_ready.png 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 Binary files differnew file mode 100644 index 000000000..6dc569e35 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/machine_off.png 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 Binary files differnew file mode 100644 index 000000000..7edf624be --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/ready_to_dye.png 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 Binary files differnew file mode 100644 index 000000000..ba351ee66 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/service.png 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 Binary files differnew file mode 100644 index 000000000..9aa8e2db6 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/shutting_down.png 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 Binary files differnew file mode 100644 index 000000000..ab4115527 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Images/stand_by.png 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 @@ <ItemGroup> <Resource Include="Images\time.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\dyeing.png" /> + <Resource Include="Images\error.png" /> + <Resource Include="Images\getting_ready.png" /> + <Resource Include="Images\machine_off.png" /> + <Resource Include="Images\ready_to_dye.png" /> + <Resource Include="Images\service.png" /> + <Resource Include="Images\shutting_down.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\stand_by.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\..\packages\MaterialDesignThemes.3.0.1\build\MaterialDesignThemes.targets" Condition="Exists('..\..\..\packages\MaterialDesignThemes.3.0.1\build\MaterialDesignThemes.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> 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"> - <DataTemplate x:Key="InsightEventTemplate" DataType="{x:Type entities:EventType}"> + <DataTemplate x:Key="InsightEventTemplate" DataType="{x:Type commonInsights:InsightsReadyEvent}"> <Border Padding="10 5" Cursor="Hand" IsHitTestVisible="True" BorderThickness="1" CornerRadius="3" BorderBrush="{StaticResource FSE_PrimaryBackgroundLightBrush}"> <Border.ToolTip> <StackPanel> <TextBlock TextWrapping="Wrap"> - <Run>#</Run><Run Text="{Binding Code}"></Run> + <Run>#</Run><Run Text="{Binding EventType.Code}"></Run> <LineBreak/> - <Run Text="{Binding TechnicalDescription}"></Run> + <Run Text="{Binding EventType.TechnicalDescription}"></Run> </TextBlock> + <StackPanel Margin="0 5 0 0" Visibility="{Binding HasDescription,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock Foreground="{StaticResource FSE_ErrorBrush}">Error</TextBlock> + <Rectangle Margin="0 2 0 0" HorizontalAlignment="Stretch" VerticalAlignment="Top" StrokeThickness="1" Stroke="{StaticResource FSE_PrimaryForegroundBrush}" StrokeDashArray="5" /> + <TextBlock Text="{Binding Description}" TextWrapping="Wrap" MaxWidth="400" Margin="0 5 0 0"></TextBlock> + </StackPanel> </StackPanel> </Border.ToolTip> <Border.Style> @@ -33,19 +39,19 @@ <Style TargetType="material:PackIcon"> <Setter Property="Kind" Value="InfoCircleOutline"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding Category}" Value="Info"> + <DataTrigger Binding="{Binding EventType.Category}" Value="Info"> <Setter Property="Kind" Value="InfoCircleOutline"></Setter> <Setter Property="Foreground" Value="{StaticResource FSE_PrimaryForegroundBrush}"></Setter> </DataTrigger> - <DataTrigger Binding="{Binding Category}" Value="Warning"> + <DataTrigger Binding="{Binding EventType.Category}" Value="Warning"> <Setter Property="Kind" Value="Alert"></Setter> <Setter Property="Foreground" Value="{StaticResource FSE_WarningBrush}"></Setter> </DataTrigger> - <DataTrigger Binding="{Binding Category}" Value="Error"> + <DataTrigger Binding="{Binding EventType.Category}" Value="Error"> <Setter Property="Kind" Value="Alert"></Setter> <Setter Property="Foreground" Value="{StaticResource FSE_ErrorBrush}"></Setter> </DataTrigger> - <DataTrigger Binding="{Binding Category}" Value="Critical"> + <DataTrigger Binding="{Binding EventType.Category}" Value="Critical"> <Setter Property="Kind" Value="BellAlert"></Setter> <Setter Property="Foreground" Value="{StaticResource FSE_ErrorBrush}"></Setter> </DataTrigger> @@ -53,8 +59,42 @@ </Style> </material:PackIcon.Style> </material:PackIcon> - <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" Text="{Binding Name}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"></TextBlock> + <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" Text="{Binding EventType.Name}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"></TextBlock> </DockPanel> </Border> </DataTemplate> + + <DataTemplate x:Key="InsightStatusTemplate" DataType="{x:Type commonInsights:InsightsReadyStatus}"> + <Image Stretch="Uniform" ToolTip="{Binding Status,Converter={StaticResource EnumToDescriptionConverter}}" Width="25" Height="25"> + <Image.Style> + <Style TargetType="Image"> + <Setter Property="Source" Value="../Images/machine_off.png"></Setter> + <Setter Property="Opacity" Value="1"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding Status}" Value="Disconnected"> + <Setter Property="Source" Value="../Images/machine_off.png"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="ReadyToDye"> + <Setter Property="Source" Value="../Images/ready_to_dye.png"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="PowerUp"> + <Setter Property="Source" Value="../Images/getting_ready.png"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="GettingReady"> + <Setter Property="Source" Value="../Images/getting_ready.png"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="Printing"> + <Setter Property="Source" Value="../Images/dyeing.png"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="ShuttingDown"> + <Setter Property="Source" Value="../Images/shutting_down.png"></Setter> + </DataTrigger> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="Opacity" Value="0.8"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </Image.Style> + </Image> + </DataTemplate> </ResourceDictionary>
\ 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<InsightReadyBase>().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<InsightsReadyFrame> Frames { get; set; } public List<InsightsReadyEvent> Events { get; set; } + public List<InsightsReadyStatus> Statuses { get; set; } public InsightsPackage() { Frames = new List<InsightsReadyFrame>(); Events = new List<InsightsReadyEvent>(); + Statuses = new List<InsightsReadyStatus>(); } } } 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 @@ <Compile Include="Helpers\ResourceHelper.cs" /> <Compile Include="INotifyApplicationStarted.cs" /> <Compile Include="INotifyApplicationReady.cs" /> + <Compile Include="Insights\InsightReadyBase.cs" /> <Compile Include="Insights\IInsightsProvider.cs" /> <Compile Include="Insights\InsightsReadyEvent.cs" /> <Compile Include="Insights\InsightsHandler.cs" /> <Compile Include="Insights\InsightsHandlerStatus.cs" /> <Compile Include="Insights\InsightsPackage.cs" /> <Compile Include="Insights\InsightsReadyFrame.cs" /> + <Compile Include="Insights\InsightsReadyStatus.cs" /> <Compile Include="Logging\ILoggingProvider.cs" /> <Compile Include="Logging\RemoteLogFileModel.cs" /> <Compile Include="Logging\RemoteLogFileStatus.cs" /> 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<double>("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<InsightsEvent> Events { get; set; } + public List<InsightsStatus> Statuses { get; set; } + public InsightsFile() { Frames = new List<InsightsFrame>(); Events = new List<InsightsEvent>(); + Statuses = new List<InsightsStatus>(); } 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<InsightsFrame> GetCollection() + private ILiteCollection<InsightsFrame> GetInsightsCollection() { return _database.GetCollection<InsightsFrame>(INSIGHTS_COLLECTION); } + private ILiteCollection<InsightsStatus> GetStatusesCollection() + { + return _database.GetCollection<InsightsStatus>(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<InsightsFrame> 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<InsightsStatus> 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 @@ <Compile Include="InsightsHelper.cs" /> <Compile Include="InsightsFrame.cs" /> <Compile Include="InsightsListener.cs" /> + <Compile Include="InsightsStatus.cs" /> <Compile Include="InsightsManager.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> |
