aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Insights
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-19 01:45:02 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-19 01:45:02 +0300
commit4e216a0ca8ad3608b845fa445b73034e1a67b8af (patch)
tree67e0ea698cfe5a8320aa81d8c13579e8ae6a6860 /Software/Visual_Studio/Tango.Insights
parentf4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0 (diff)
downloadTango-4e216a0ca8ad3608b845fa445b73034e1a67b8af.tar.gz
Tango-4e216a0ca8ad3608b845fa445b73034e1a67b8af.zip
DB: Changed TechMonitors HeadZone5_6HeaterCurrent => HeadZone56HeaterCurrent
Working on insights and insights annotations. Added insights events. Added insights settings to PPC advanced settings. Added compression support for transport adapters. Implemented compression support on TCP/SignalR/WebRTC. Added Compression flag to ExternalBridge discovery packet. Added compression setting to PPC advanced settings. Refactored transport layer to use Bson instead of Json for Generic Messages. Added all SciChart referenced assemblies. Registered EF Extensions license for FSE. Added support for FSE PushTask notification cancel button.
Diffstat (limited to 'Software/Visual_Studio/Tango.Insights')
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsEvent.cs14
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsFile.cs3
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsFrame.cs4
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsListener.cs95
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsManager.cs29
-rw-r--r--Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj12
6 files changed, 133 insertions, 24 deletions
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs b/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs
new file mode 100644
index 000000000..b3f73e24b
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Insights/InsightsEvent.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Insights
+{
+ public class InsightsEvent
+ {
+ public DateTime Time { get; set; }
+ public int EventCode { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
index 853b23c98..8250dfb9d 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
@@ -13,9 +13,12 @@ namespace Tango.Insights
{
public List<InsightsFrame> Frames { get; set; }
+ public List<InsightsEvent> Events { get; set; }
+
public InsightsFile()
{
Frames = new List<InsightsFrame>();
+ Events = new List<InsightsEvent>();
}
public Stream ToStream()
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsFrame.cs b/Software/Visual_Studio/Tango.Insights/InsightsFrame.cs
index 4ea2a1c13..5212b5471 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsFrame.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsFrame.cs
@@ -40,7 +40,7 @@ namespace Tango.Insights
frame.Time = timeUtc;
byte[] data = insightsMonitors.ToBytes();
- byte[] compressedData = SevenZipHelper.Compress(data);
+ byte[] compressedData = GZipHelper.Compress(data);
frame.MonitorsData = compressedData;
@@ -55,7 +55,7 @@ namespace Tango.Insights
}
else
{
- var uncompressed = SevenZipHelper.Decompress(MonitorsData);
+ var uncompressed = GZipHelper.Decompress(MonitorsData);
var insightsMonitors = InsightsMonitors.Parser.ParseFrom(uncompressed);
return insightsMonitors;
}
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
index e534574fc..12d38e846 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
@@ -1,17 +1,23 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
+using Tango.Core;
using Tango.Integration.Operation;
using Tango.PMR.Diagnostics;
using Tango.PMR.Insights;
namespace Tango.Insights
{
- public class InsightsListener
+ public class InsightsListener : ExtendedObject
{
+ public const int MIN_SAMPLING_INTERVAL_SECONDS = 1;
+ public const int MIN_STORAGE_CLEANUP_MINUTES = 1;
+ public const int MIN_MAX_STORAGE_DURATION_MINUTES = 10;
+
private InsightsManager _manager;
private IMachineOperator _operator;
private Timer _timer;
@@ -41,19 +47,53 @@ namespace Tango.Insights
public InsightsListener(IMachineOperator machineOperator) : this(InsightsManager.Default, machineOperator)
{
-
+
+ }
+
+ private void InsertInsightsGap()
+ {
+ Task.Factory.StartNew(() =>
+ {
+ try
+ {
+ var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow);
+ _manager.InsertFrame(frame);
+ Debug.WriteLine("Insights gap frame inserted.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error inserting insights gap on machine connection/disconnection.");
+ }
+ });
}
public void Start()
{
if (!IsStarted)
{
+ if (SamplingInterval.TotalSeconds < MIN_SAMPLING_INTERVAL_SECONDS)
+ {
+ SamplingInterval = TimeSpan.FromSeconds(MIN_SAMPLING_INTERVAL_SECONDS);
+ }
+
+ if (StorageCleanupInterval.TotalMinutes < MIN_STORAGE_CLEANUP_MINUTES)
+ {
+ StorageCleanupInterval = TimeSpan.FromMinutes(MIN_STORAGE_CLEANUP_MINUTES);
+ }
+
+ if (MaxStorageDuration.TotalMinutes < MIN_MAX_STORAGE_DURATION_MINUTES)
+ {
+ MaxStorageDuration = TimeSpan.FromMinutes(MIN_MAX_STORAGE_DURATION_MINUTES);
+ }
+
if (_timer == null)
{
_timer = new Timer();
_timer.Interval = SamplingInterval.TotalMilliseconds;
}
+ InsertInsightsGap();
+
_writing = false;
_timerCount = 0;
_deleteTicks = (int)(StorageCleanupInterval.TotalMilliseconds / SamplingInterval.TotalMilliseconds);
@@ -62,6 +102,8 @@ namespace Tango.Insights
IsStarted = true;
_timer.Elapsed += _timer_Elapsed;
_timer.Start();
+
+ LogManager.Log("Insights listener started...");
}
}
@@ -71,6 +113,7 @@ namespace Tango.Insights
{
_timer.Stop();
_diagnosticsQueue.Clear();
+ LogManager.Log("Insights listener stopped.");
}
}
@@ -86,33 +129,43 @@ namespace Tango.Insights
{
if (!IsStarted || _writing) return;
- _writing = true;
+ try
+ {
+ _writing = true;
- InsightsFrame frame = null;
+ InsightsFrame frame = null;
- if (_diagnosticsQueue.Count > 0)
- {
- var queue = _diagnosticsQueue.ToList();
- _diagnosticsQueue.Clear();
+ if (_diagnosticsQueue.Count > 0)
+ {
+ var queue = _diagnosticsQueue.ToList();
+ _diagnosticsQueue.Clear();
- InsightsMonitors monitorsAvg = InsightsHelper.AverageMonitors(queue);
- queue.Clear();
+ InsightsMonitors monitorsAvg = InsightsHelper.AverageMonitors(queue);
+ queue.Clear();
- frame = InsightsFrame.FromInsightsMonitors(monitorsAvg, DateTime.UtcNow.Subtract(SamplingInterval));
- }
- else
- {
- frame = InsightsFrame.CreateEmpty(DateTime.UtcNow.Subtract(SamplingInterval));
- }
+ frame = InsightsFrame.FromInsightsMonitors(monitorsAvg, DateTime.UtcNow.Subtract(SamplingInterval));
+ }
+ else
+ {
+ frame = InsightsFrame.CreateEmpty(DateTime.UtcNow.Subtract(SamplingInterval));
+ }
+
+ _manager.InsertFrame(frame);
- _manager.InsertFrame(frame);
+ Debug.WriteLine("Insights frame inserted.");
- _timerCount++;
+ _timerCount++;
- if (_timerCount >= _deleteTicks)
+ if (_timerCount >= _deleteTicks)
+ {
+ _timerCount = 0;
+ int deleted = _manager.DeleteFrames(DateTime.UtcNow.Subtract(MaxStorageDuration));
+ Debug.WriteLine($"{deleted} insights frames deleted.");
+ }
+ }
+ catch (Exception ex)
{
- _timerCount = 0;
- _manager.DeleteFrames(DateTime.UtcNow.Subtract(MaxStorageDuration));
+ LogManager.Log(ex, "Error occurred on insights frame insertion.");
}
_writing = false;
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsManager.cs b/Software/Visual_Studio/Tango.Insights/InsightsManager.cs
index 7597aabf4..65cb2b869 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsManager.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsManager.cs
@@ -1,10 +1,12 @@
using LiteDB;
using System;
using System.Collections.Generic;
+using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL;
namespace Tango.Insights
{
@@ -69,7 +71,7 @@ namespace Tango.Insights
public virtual List<InsightsFrame> GetFrames(DateTime startUTC, DateTime endUTC)
{
var collection = GetCollection();
- return collection.Find(x => x.Time >= startUTC && x.Time <= endUTC).ToList();
+ return collection.Find(x => x.Time >= startUTC && x.Time <= endUTC).ToList().OrderBy(x => x.Time).ToList();
}
public virtual int DeleteFrames(DateTime maxDateUTC)
@@ -77,5 +79,30 @@ namespace Tango.Insights
var collection = GetCollection();
return collection.DeleteMany(x => x.Time < maxDateUTC);
}
+
+ public virtual List<InsightsEvent> GetEvents(DateTime startUTC, DateTime endUTC)
+ {
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ List<InsightsEvent> events = db.MachinesEvents
+ .Where(x => x.DateTime >= startUTC && x.DateTime <= endUTC)
+ .Include(x => x.EventType)
+ .Select(x => new InsightsEvent()
+ {
+ Time = x.DateTime,
+ EventCode = x.EventType.Code
+ })
+ .ToList()
+ .Select(x => new InsightsEvent()
+ {
+ Time = new DateTime(x.Time.Ticks, DateTimeKind.Utc),
+ EventCode = x.EventCode
+ })
+ .OrderBy(x => x.Time)
+ .ToList();
+
+ return events;
+ }
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
index 26b2e8204..9bd24e263 100644
--- a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
+++ b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
@@ -44,6 +44,7 @@
<Compile Include="..\Versioning\GlobalVersionInfo.cs">
<Link>GlobalVersionInfo.cs</Link>
</Compile>
+ <Compile Include="InsightsEvent.cs" />
<Compile Include="InsightsFile.cs" />
<Compile Include="InsightsHelper.cs" />
<Compile Include="InsightsFrame.cs" />
@@ -52,6 +53,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\Tango.BL\Tango.BL.csproj">
+ <Project>{F441FEEE-322A-4943-B566-110E12FD3B72}</Project>
+ <Name>Tango.BL</Name>
+ </ProjectReference>
<ProjectReference Include="..\Tango.Core\Tango.Core.csproj">
<Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
<Name>Tango.Core</Name>
@@ -60,6 +65,10 @@
<Project>{4206ac58-3b57-4699-8835-90bf6db01a61}</Project>
<Name>Tango.Integration</Name>
</ProjectReference>
+ <ProjectReference Include="..\Tango.Logging\Tango.Logging.csproj">
+ <Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project>
+ <Name>Tango.Logging</Name>
+ </ProjectReference>
<ProjectReference Include="..\Tango.PMR\Tango.PMR.csproj">
<Project>{e4927038-348d-4295-aaf4-861c58cb3943}</Project>
<Name>Tango.PMR</Name>
@@ -70,6 +79,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="EntityFramework">
+ <Version>6.2.0</Version>
+ </PackageReference>
<PackageReference Include="Google.Protobuf">
<Version>3.4.1</Version>
</PackageReference>