Skip to content

Commit

Permalink
Improve End to End calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelRDuarte committed Nov 25, 2024
1 parent 5fc70d4 commit 896cbfc
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 361 deletions.
4 changes: 1 addition & 3 deletions MWCore-AdHoc-E2E-Streams.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<DMSScript options="272" xmlns="http://www.skyline.be/automation">
<Name>MWCore_AdHoc-E2E-Streams</Name>
<Description></Description>
<Description>MWCore_AdHoc-E2E-Streams</Description>
<Type>Automation</Type>
<Author>SKYLINE2\FlavioME</Author>
<CheckSets>FALSE</CheckSets>
Expand All @@ -21,8 +21,6 @@
<Value><![CDATA[[Project:MWCore-AdHoc-E2E-Streams_1]]]></Value>
<Param type="preCompile">true</Param>
<Param type="libraryName">MWCoreAdHocE2EStreams</Param>
<!--<Param type="debug">true</Param>-->
<Message></Message>
</Exe>
</Script>
</DMSScript>
76 changes: 44 additions & 32 deletions MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,24 @@ namespace GQIIntegrationSPI
using System.Collections.Generic;
using System.IO;
using System.Linq;

using MWCoreAdHocE2EStreams_1.Misc;

using Skyline.DataMiner.Analytics.GenericInterface;
using Skyline.DataMiner.Net.Messages;

[GQIMetaData(Name = "MWCore E2E Stream")]
public class GQIDataSourceAdHocE2EStreams : IGQIDataSource, IGQIInputArguments, IGQIOnInit
{
private GQIStringArgument _argumentEdgeName = new GQIStringArgument("MWEdge Name") { IsRequired = true };
private GQIStringArgument _argumentElementName = new GQIStringArgument("Element Name") { IsRequired = true };
private GQIStringArgument _argumentStreamName = new GQIStringArgument("Stream Name") { IsRequired = true };
private bool _debug = false;
private readonly GQIStringArgument _argumentEdgeName = new GQIStringArgument("MWEdge Name") { IsRequired = true };
private readonly GQIStringArgument _argumentElementName = new GQIStringArgument("Element Name") { IsRequired = true };
private readonly GQIStringArgument _argumentStreamName = new GQIStringArgument("Stream Name") { IsRequired = true };
private readonly bool _debug = true;
private readonly string file = $"C:\\Users\\SamuelDT\\Downloads\\e2eLog-Parallel-{DateTime.Now.ToOADate()}.txt";

private GQIDMS _dms;
private string _edgeName;
private string _elementName;
private string _streamName;
private string file = $"C:\\Users\\FlavioME\\Downloads\\e2eLog-{DateTime.Now.ToOADate()}.txt";

public GQIColumn[] GetColumns()
{
Expand Down Expand Up @@ -107,28 +109,33 @@ public GQIPage GetNextPage(GetNextPageInputArgs args)
GQIRow[] data2retrieve;
if (_debug)
{
string text = $"--------{DateTime.Now}---------{Environment.NewLine}";
string text = $"--------{DateTime.Now}---------{Environment.NewLine}{_edgeName}/{_streamName}{Environment.NewLine}";
File.WriteAllText(file, text);
}

try
{
var streams = StreamsIO.Instance(_dms, _elementName);
if (_debug)
{
File.AppendAllText(file, $"Time: {DateTime.Now}\nEnded GetInstance!\n");
}

var hops = StreamsIO.GetHops(streams, _edgeName, _streamName);

if (_debug)
{
File.AppendAllText(file, "Ended GetHops loop!\n");
File.AppendAllText(file, $"Time: {DateTime.Now}\nEnded GetHops loop!\n");
}

List<GQIRow> rows = new List<GQIRow>();
foreach (var hop in hops)
{
rows.Add(new GQIRow(new[]
{
{
new GQICell { Value = hop.Id_Src}, // IO ID SRC
new GQICell { Value = hop.Name_Src}, // IO Name SRC
new GQICell { Value = hop.IOType == 0 ? "Source" : "Output" }, // IO Type SRC
new GQICell { Value = hop.IOType == 0 ? "Source" : "Output" }, // IO SRC
new GQICell { Value = hop.Status_Src}, // IO State SRC
new GQICell { Value = hop.Type_Src}, // IO Type SRC
new GQICell { Value = hop.Bitrate_Src}, // Bitrate SRC
Expand All @@ -141,39 +148,38 @@ public GQIPage GetNextPage(GetNextPageInputArgs args)
new GQICell { Value = hop.Bitrate_Dst}, // Bitrate SRC
new GQICell { Value = hop.Stream_Dst}, // Stream Name SRC
new GQICell { Value = hop.MWEdge_Dst}, // Edge Name SRC
new GQICell { Value = hop.Hop_Number == 1 && hop.IOType != 0 ? true : hop.Starting_Point},
new GQICell { Value = (hop.Hop_Number == 1 && hop.IOType != 0) || hop.Starting_Point},
new GQICell { Value = hop.Hop_Number},
new GQICell { Value = hop.IsActive},
}));
}

// adding an extra line to facilitate the node-edge component
//var lastHop = hops.OrderBy(x => x.Hop_Number).Last();
var lastOutputs = hops.Where(x => x.IOType == IOType.Input && x.Hop_Number == hops.Max(y => y.Hop_Number));

foreach (var lastHop in lastOutputs)
{
rows.Add(new GQIRow(new[]
{
new GQICell { Value = lastHop.Id_Dst }, // IO ID SRC
new GQICell { Value = lastHop.Name_Dst }, // IO Name SRC
new GQICell { Value = "Output" }, // IO Type SRC
new GQICell { Value = lastHop.Status_Dst }, // IO State SRC
new GQICell { Value = lastHop.Type_Dst }, // IO Type SRC
new GQICell { Value = lastHop.Bitrate_Dst }, // Bitrate SRC
new GQICell { Value = lastHop.Stream_Dst }, // Stream Name SRC
new GQICell { Value = lastHop.MWEdge_Dst }, // Edge Name SRC
new GQICell { Value = string.Empty }, // IO ID SRC
new GQICell { Value = string.Empty }, // IO Name SRC
new GQICell { Value = string.Empty }, // IO State SRC
new GQICell { Value = string.Empty }, // IO Type SRC
new GQICell { Value = 0d }, // Bitrate SRC
new GQICell { Value = string.Empty }, // Stream Name SRC
new GQICell { Value = string.Empty }, // Edge Name SRC
new GQICell { Value = lastHop.Starting_Point},
new GQICell { Value = lastHop.Hop_Number},
new GQICell { Value = lastHop.IsActive},
}));
{
new GQICell { Value = lastHop.Id_Dst }, // IO ID SRC
new GQICell { Value = lastHop.Name_Dst }, // IO Name SRC
new GQICell { Value = "Output" }, // IO Type SRC
new GQICell { Value = lastHop.Status_Dst }, // IO State SRC
new GQICell { Value = lastHop.Type_Dst }, // IO Type SRC
new GQICell { Value = lastHop.Bitrate_Dst }, // Bitrate SRC
new GQICell { Value = lastHop.Stream_Dst }, // Stream Name SRC
new GQICell { Value = lastHop.MWEdge_Dst }, // Edge Name SRC
new GQICell { Value = string.Empty }, // IO ID SRC
new GQICell { Value = string.Empty }, // IO Name SRC
new GQICell { Value = string.Empty }, // IO State SRC
new GQICell { Value = string.Empty }, // IO Type SRC
new GQICell { Value = 0d }, // Bitrate SRC
new GQICell { Value = string.Empty }, // Stream Name SRC
new GQICell { Value = string.Empty }, // Edge Name SRC
new GQICell { Value = lastHop.Starting_Point},
new GQICell { Value = lastHop.Hop_Number},
new GQICell { Value = lastHop.IsActive},
}));
}

data2retrieve = rows.ToArray();
Expand All @@ -187,6 +193,12 @@ public GQIPage GetNextPage(GetNextPageInputArgs args)

data2retrieve = new GQIRow[0];
}

if (_debug)
{
File.AppendAllText(file, $"End Time: {DateTime.Now}\n");
}

return new GQIPage(data2retrieve)
{
HasNextPage = false,
Expand Down
10 changes: 10 additions & 0 deletions MWCore-AdHoc-E2E-Streams_1/Misc/Enums/IOType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Ignore Spelling: dms

namespace MWCoreAdHocE2EStreams_1.Misc
{
internal enum IOType
{
Input = 0,
Output = 1,
}
}
13 changes: 13 additions & 0 deletions MWCore-AdHoc-E2E-Streams_1/Misc/Enums/MWCorePids.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Ignore Spelling: dms

namespace Misc.Enums
{
internal enum MWCorePids
{
SourcesTablePid = 9600,
SourcesStatisticsTablePid = 11200,
OutputsTablePid = 8900,
OutputsStatisticsTablePid = 11400,
EdgesTablePid = 8500,
}
}
98 changes: 97 additions & 1 deletion MWCore-AdHoc-E2E-Streams_1/Misc/Hop.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace MWCoreAdHocE2EStreams_1.Misc
{
internal class Hop
using System;
using System.Collections.Generic;

internal class Hop : IEquatable<Hop>
{
public double? Bitrate_Dst { get; set; }

Expand Down Expand Up @@ -45,5 +48,98 @@ internal class Hop
public string Type_Dst { get; set; }

public string Type_Src { get; set; } // pull, listener/push

public static bool operator ==(Hop left, Hop right)
{
return EqualityComparer<Hop>.Default.Equals(left, right);
}

public static bool operator !=(Hop left, Hop right)
{
return !(left == right);
}

public static Hop CreateHop(Iotable source, Iotable destination, IOType type, int hopNumber, bool isActive, bool startingPoint = false)
{
if (destination == null)
{
return CreateEndHop(source, type, hopNumber, isActive);
}

return new Hop
{
Bitrate_Dst = destination.Bitrate,
Bitrate_Src = source.Bitrate,
Id_Dst = destination.Id,
Id_Src = source.Id,
IOType = type,
Ip_Dst = destination.Ip,
Ip_Src = source.Ip,
MWEdge_Dst = destination.MWEdge,
MWEdge_Src = source.MWEdge,
Name_Dst = destination.Name,
Name_Src = source.Name,
Port_Dst = destination.Port,
Port_Src = source.Port,
Stream_Dst = destination.Stream,
Stream_Src = source.Stream,
Type_Dst = destination.Type,
Type_Src = source.Type,
Status_Dst = destination.Status,
Status_Src = source.Status,
Starting_Point = startingPoint,
Hop_Number = hopNumber,
IsActive = isActive,
};
}

public override bool Equals(object obj)
{
return Equals(obj as Hop);
}

public bool Equals(Hop other)
{
if (other == null)
return false;

return Id_Dst == other.Id_Dst && Id_Src == other.Id_Src;
}

public override int GetHashCode()
{
int hashCode = -413437643;
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Id_Dst);
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Id_Src);
return hashCode;
}

private static Hop CreateEndHop(Iotable source, IOType type, int hopNumber, bool isActive)
{
return new Hop
{
Bitrate_Dst = 0,
Bitrate_Src = source.Bitrate,
Id_Dst = string.Empty,
Id_Src = source.Id,
IOType = type,
Ip_Dst = string.Empty,
Ip_Src = source.Ip,
MWEdge_Dst = string.Empty,
MWEdge_Src = source.MWEdge,
Name_Dst = string.Empty,
Name_Src = source.Name,
Port_Dst = string.Empty,
Port_Src = source.Port,
Stream_Dst = string.Empty,
Stream_Src = source.Stream,
Type_Dst = string.Empty,
Type_Src = source.Type,
Status_Dst = string.Empty,
Status_Src = source.Status,
Hop_Number = hopNumber,
IsActive = isActive,
};
}
}
}
Loading

0 comments on commit 896cbfc

Please sign in to comment.