Skip to content

Commit

Permalink
Updated RemoveInvalidDataPoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandbanks committed Aug 5, 2024
1 parent f11f027 commit a6ac0e4
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions LogicMonitor.Api/Extensions/GraphDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public static class GraphDataExtensions
/// </summary>
/// <param name="graphData">The GraphData</param>
/// <returns>A list of timestamp indexes</returns>
private static List<(long Timestamp, int Index)> GetTimestampToRemove(this GraphData graphData)
private static List<int> GetTimestampToRemove(this GraphData graphData)
{
var timestampToRemove = new List<(long, int)>();
var timestampToRemove = new List<int>();
for (var index = 0; index < graphData.TimeStamps.Count; index++)
{
if (index == 0)
Expand All @@ -24,7 +24,7 @@ public static class GraphDataExtensions

if (graphData.TimeStamps[index - 1] >= (graphData.TimeStamps[index] - timeThreshold))
{
timestampToRemove.Add((graphData.TimeStamps[index - 1], index - 1));
timestampToRemove.Add(index - 1);
}
}

Expand All @@ -38,16 +38,13 @@ public static class GraphDataExtensions
public static void RemoveInvalidDataPoints(this GraphData graphData)
{
// Get invalid timestamps
var timestampsAndIndexes = graphData.GetTimestampToRemove();
timestampsAndIndexes.Reverse();
var timestampIndexes = graphData.GetTimestampToRemove();
timestampIndexes.Reverse();

// Remove timestamps from the data
foreach (var (Timestamp, Index) in timestampsAndIndexes)
foreach (var index in timestampIndexes)
{
if (graphData.TimeStamps[Index] == Timestamp) // Should be the case as already calculated
{
graphData.TimeStamps.RemoveAt(Index);
}
graphData.TimeStamps.RemoveAt(index);
}

//NO: what can happen is that some timestamps are duplicated (crazy, right?) and this could remove e.g. 2 but
Expand All @@ -58,11 +55,11 @@ public static void RemoveInvalidDataPoints(this GraphData graphData)
foreach (var line in graphData.Lines)
{
var lineData = line.Data.ToList();
foreach (var (_, Index) in timestampsAndIndexes)
foreach (var index in timestampIndexes)
{
if (lineData.Count > Index)
if (lineData.Count > index)
{
lineData.RemoveAt(Index);
lineData.RemoveAt(index);
}
}
// Copy the data back
Expand Down

0 comments on commit a6ac0e4

Please sign in to comment.