74 lines
3.6 KiB
C#
74 lines
3.6 KiB
C#
using DTS.Common.Interface;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DTS.Common.Utils
|
|
{
|
|
//FB 29410 POCO class to be used as parameter for MinUnixTime method
|
|
public class TestModuleTimeStamp
|
|
{
|
|
public int TriggerTimestampSec { get; set; }
|
|
public int TriggerTimestampNanoSec { get; set; }
|
|
}
|
|
public static class TestUtils
|
|
{
|
|
// FB15333: Add PTP/RTC timestamp column for CSV exports
|
|
//FB 29410 refactor the orginal method to use IEnumerable<TestModuleTimeStamp> basemodules as input parameter to be able to use this method in different projects
|
|
public static Tuple<double, double> MinUnixTime(IEnumerable<TestModuleTimeStamp> basemodules)
|
|
{
|
|
if (null != basemodules && basemodules.Count() > 0)
|
|
{
|
|
var utcAverage = basemodules.Average(module => (double)(module.TriggerTimestampSec + module.TriggerTimestampNanoSec / Common.Constants.NANOS_PER_SECOND));
|
|
var utcStandardDeviation = basemodules.Select(module => (double)(module.TriggerTimestampSec + module.TriggerTimestampNanoSec / Common.Constants.NANOS_PER_SECOND)).StandardDeviation();
|
|
utcStandardDeviation = utcStandardDeviation > Common.Constants.TEN_MILLIS_IN_SEC ? Common.Constants.TEN_MILLIS_IN_SEC : utcStandardDeviation; // select min within standard dev or 10ms, whichever is smaller
|
|
|
|
var minUnixTime = new Tuple<double, double>(basemodules.First().TriggerTimestampSec, basemodules.First().TriggerTimestampNanoSec);
|
|
foreach (var module in basemodules)
|
|
{
|
|
var moduleTime = (double)(module.TriggerTimestampSec + module.TriggerTimestampNanoSec / Common.Constants.NANOS_PER_SECOND);
|
|
if (module.TriggerTimestampSec <= minUnixTime.Item1 && module.TriggerTimestampNanoSec < minUnixTime.Item2 &&
|
|
moduleTime > utcAverage - utcStandardDeviation)
|
|
{
|
|
minUnixTime = new Tuple<double, double>(module.TriggerTimestampSec, module.TriggerTimestampNanoSec);
|
|
}
|
|
}
|
|
|
|
return minUnixTime;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static string ParseROISuffix(string test)
|
|
{
|
|
var testitems = new string[] { };
|
|
if (test.Length > 0 && (testitems = test.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).Length > 3)
|
|
{
|
|
return testitems.Last();
|
|
}
|
|
//FB 18312 Get the ROI of particular event
|
|
if (test.Length > 0)
|
|
{
|
|
var segments = test.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
var segmentWithEvent = segments.FirstOrDefault(p => p.Contains(DTS.Common.Constants.EventNumber));
|
|
if (!string.IsNullOrWhiteSpace(segmentWithEvent))
|
|
{
|
|
var testSegments = segmentWithEvent.Split('_');
|
|
if (testSegments.Any(p => p.Contains(DTS.Common.Constants.EventNumber.Replace("_", ""))))
|
|
{
|
|
//found an roi suffix
|
|
if (!testSegments.Last().Contains(DTS.Common.Constants.EventNumber.Replace("_", "")))
|
|
{
|
|
return "_" + testSegments.Last();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
}
|
|
}
|