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/Tango.Insights | |
| parent | 4e216a0ca8ad3608b845fa445b73034e1a67b8af (diff) | |
| download | Tango-334ecf334ea1d69c948e793c06f6182f2b2415b3.tar.gz Tango-334ecf334ea1d69c948e793c06f6182f2b2415b3.zip | |
Implemented insights machine statuses.
Diffstat (limited to 'Software/Visual_Studio/Tango.Insights')
6 files changed, 83 insertions, 7 deletions
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> |
