aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Insights
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-17 01:14:07 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-17 01:14:07 +0300
commitf4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0 (patch)
tree6407154a8f42f45e9045b81a54d5f981567faec2 /Software/Visual_Studio/Tango.Insights
parente47e602cd61bcca8eb7fbef40dc4aa8798510ccc (diff)
downloadTango-f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0.tar.gz
Tango-f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0.zip
Working on insights...
Diffstat (limited to 'Software/Visual_Studio/Tango.Insights')
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsFile.cs71
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsHelper.cs2
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsListener.cs22
-rw-r--r--Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj4
4 files changed, 87 insertions, 12 deletions
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
new file mode 100644
index 000000000..853b23c98
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
@@ -0,0 +1,71 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Bson;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Insights
+{
+ public class InsightsFile
+ {
+ public List<InsightsFrame> Frames { get; set; }
+
+ public InsightsFile()
+ {
+ Frames = new List<InsightsFrame>();
+ }
+
+ public Stream ToStream()
+ {
+ return new MemoryStream(ToBytes());
+ }
+
+ public byte[] ToBytes()
+ {
+ using (MemoryStream ms = new MemoryStream())
+ {
+ using (BsonWriter writer = new BsonWriter(ms))
+ {
+ JsonSerializer serializer = new JsonSerializer();
+ serializer.Serialize(writer, this);
+ ms.Position = 0;
+ return ms.ToArray();
+ }
+ }
+ }
+
+ public void ToFile(String filePath)
+ {
+ File.WriteAllBytes(filePath, ToBytes());
+ }
+
+ public static InsightsFile FromStream(Stream stream)
+ {
+ using (BsonReader reader = new BsonReader(stream))
+ {
+ JsonSerializer serializer = new JsonSerializer();
+ return serializer.Deserialize<InsightsFile>(reader);
+ }
+ }
+
+ public static InsightsFile FromBytes(byte[] data)
+ {
+ using (MemoryStream ms = new MemoryStream(data))
+ {
+ ms.Position = 0;
+ return FromStream(ms);
+ }
+ }
+
+ public static InsightsFile FromFile(String filePath)
+ {
+ using (FileStream fs = File.OpenRead(filePath))
+ {
+ return FromStream(fs);
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsHelper.cs b/Software/Visual_Studio/Tango.Insights/InsightsHelper.cs
index 202e2574d..29f761af6 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsHelper.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsHelper.cs
@@ -66,7 +66,7 @@ namespace Tango.Insights
public static InsightsMonitors AverageMonitors(List<DiagnosticsMonitors> diagnosticsMonitorsCollection)
{
- List<InsightsMonitors> insightsMonitorsCollection = diagnosticsMonitorsCollection.ToList().Select(x => InsightsHelper.MapMonitors(x)).ToList();
+ List<InsightsMonitors> insightsMonitorsCollection = diagnosticsMonitorsCollection.ToList().Select(x => MapMonitors(x)).ToList();
return AverageMonitors(insightsMonitorsCollection);
}
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
index 0df5b63a1..e534574fc 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
@@ -21,17 +21,17 @@ namespace Tango.Insights
private bool _writing;
public bool IsStarted { get; private set; }
- public TimeSpan WriteInterval { get; set; }
- public TimeSpan DeleteInterval { get; set; }
- public TimeSpan MaxFramesStorage { get; set; }
+ public TimeSpan SamplingInterval { get; set; }
+ public TimeSpan StorageCleanupInterval { get; set; }
+ public TimeSpan MaxStorageDuration { get; set; }
public InsightsListener(InsightsManager manager, IMachineOperator machineOperator)
{
_diagnosticsQueue = new List<DiagnosticsMonitors>();
- WriteInterval = TimeSpan.FromMinutes(0.1);
- DeleteInterval = TimeSpan.FromMinutes(60);
- MaxFramesStorage = TimeSpan.FromDays(30);
+ SamplingInterval = TimeSpan.FromMinutes(1);
+ StorageCleanupInterval = TimeSpan.FromMinutes(60);
+ MaxStorageDuration = TimeSpan.FromDays(30);
_manager = manager;
_operator = machineOperator;
@@ -51,12 +51,12 @@ namespace Tango.Insights
if (_timer == null)
{
_timer = new Timer();
- _timer.Interval = WriteInterval.TotalMilliseconds;
+ _timer.Interval = SamplingInterval.TotalMilliseconds;
}
_writing = false;
_timerCount = 0;
- _deleteTicks = (int)(DeleteInterval.TotalMilliseconds / WriteInterval.TotalMilliseconds);
+ _deleteTicks = (int)(StorageCleanupInterval.TotalMilliseconds / SamplingInterval.TotalMilliseconds);
_diagnosticsQueue.Clear();
IsStarted = true;
@@ -98,11 +98,11 @@ namespace Tango.Insights
InsightsMonitors monitorsAvg = InsightsHelper.AverageMonitors(queue);
queue.Clear();
- frame = InsightsFrame.FromInsightsMonitors(monitorsAvg, DateTime.UtcNow.Subtract(WriteInterval));
+ frame = InsightsFrame.FromInsightsMonitors(monitorsAvg, DateTime.UtcNow.Subtract(SamplingInterval));
}
else
{
- frame = InsightsFrame.CreateEmpty(DateTime.UtcNow.Subtract(WriteInterval));
+ frame = InsightsFrame.CreateEmpty(DateTime.UtcNow.Subtract(SamplingInterval));
}
_manager.InsertFrame(frame);
@@ -112,7 +112,7 @@ namespace Tango.Insights
if (_timerCount >= _deleteTicks)
{
_timerCount = 0;
- _manager.DeleteFrames(DateTime.UtcNow.Subtract(MaxFramesStorage));
+ _manager.DeleteFrames(DateTime.UtcNow.Subtract(MaxStorageDuration));
}
_writing = false;
diff --git a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
index 0b9ecc641..26b2e8204 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="InsightsFile.cs" />
<Compile Include="InsightsHelper.cs" />
<Compile Include="InsightsFrame.cs" />
<Compile Include="InsightsListener.cs" />
@@ -75,6 +76,9 @@
<PackageReference Include="LiteDB">
<Version>5.0.4</Version>
</PackageReference>
+ <PackageReference Include="Newtonsoft.Json">
+ <Version>9.0.1</Version>
+ </PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> \ No newline at end of file