-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analyse continuous measured data (#573)
* Create draft PR for #572 * +Evaluator of continious measurement (find extrems ,change states(triggers)) +tests - not finished yet * +measurement evaluator tests *change search with plain data Co-authored-by: peterbarancek <[email protected]> Co-authored-by: Peter Barancek <[email protected]>
- Loading branch information
1 parent
e292043
commit 525553d
Showing
13 changed files
with
1,926 additions
and
7 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/TcoUtilities/src/TcoUtilitiesConnector/TcoEvaluateMeasurement/FindExtremsHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
| ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
|
||
|
||
namespace TcoUtilities | ||
{ | ||
public static class FindExtremsHelper | ||
{ | ||
|
||
|
||
public static IEnumerable<float> ElementsAt(IEnumerable<float> source, params int[] indices) | ||
{ | ||
return indices.Join(source.Select((Item, Index) => (Item, Index)), | ||
i => i, p => p.Index, (_, p) => p.Item); | ||
} | ||
|
||
|
||
|
||
public static IList<int> FindPeaks(IList<float> values, bool negative, int rangeOfPeaks, float noise) | ||
{ | ||
List<int> peaks = new List<int>(); | ||
double current; | ||
IEnumerable<float> range; | ||
|
||
int checksOnEachSide = rangeOfPeaks / 2; | ||
for (int i = 0; i < values.Count; i++) | ||
{ | ||
current = values[i]; | ||
range = values; | ||
|
||
if (i > checksOnEachSide) | ||
{ | ||
range = range.Skip(i - checksOnEachSide); | ||
} | ||
|
||
range = range.Take(rangeOfPeaks); | ||
if (!negative) | ||
if ((range.Count() > 0) && (current > System.Math.Abs(noise)) && (current == range.Max())) | ||
{ | ||
peaks.Add(i); | ||
} | ||
if (negative) | ||
if ((range.Count() > 0) && (current > System.Math.Abs(noise)) && (current == range.Min())) | ||
{ | ||
peaks.Add(i); | ||
} | ||
} | ||
|
||
return peaks; | ||
} | ||
|
||
public static IList<int> FindTrigger(IList<float> values, float noise) | ||
{ | ||
List<int> triggers = new List<int>(); | ||
float current; | ||
|
||
float lastValue = 0; | ||
|
||
for (int i = 0; i < values.Count; i++) | ||
{ | ||
current = values[i]; | ||
|
||
if (current != lastValue) | ||
{ | ||
lastValue = current; | ||
triggers.Add(i); | ||
} | ||
} | ||
|
||
return triggers; | ||
} | ||
|
||
|
||
public static IList<float> FilterByMovingAverage(IList<float> list, int smoothFactor) | ||
{ | ||
|
||
return Enumerable | ||
.Range(0, list.Count - smoothFactor) | ||
.Select(n => list.Skip(n).Take(smoothFactor).Average()) | ||
.ToList(); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.