Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 525553d

Browse files
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 <peterbarancek@users.noreply.github.com> Co-authored-by: Peter Barancek <peter.barancek@mts.sk>
1 parent e292043 commit 525553d

File tree

13 files changed

+1926
-7
lines changed

13 files changed

+1926
-7
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+

2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.Linq;
6+
7+
8+
namespace TcoUtilities
9+
{
10+
public static class FindExtremsHelper
11+
{
12+
13+
14+
public static IEnumerable<float> ElementsAt(IEnumerable<float> source, params int[] indices)
15+
{
16+
return indices.Join(source.Select((Item, Index) => (Item, Index)),
17+
i => i, p => p.Index, (_, p) => p.Item);
18+
}
19+
20+
21+
22+
public static IList<int> FindPeaks(IList<float> values, bool negative, int rangeOfPeaks, float noise)
23+
{
24+
List<int> peaks = new List<int>();
25+
double current;
26+
IEnumerable<float> range;
27+
28+
int checksOnEachSide = rangeOfPeaks / 2;
29+
for (int i = 0; i < values.Count; i++)
30+
{
31+
current = values[i];
32+
range = values;
33+
34+
if (i > checksOnEachSide)
35+
{
36+
range = range.Skip(i - checksOnEachSide);
37+
}
38+
39+
range = range.Take(rangeOfPeaks);
40+
if (!negative)
41+
if ((range.Count() > 0) && (current > System.Math.Abs(noise)) && (current == range.Max()))
42+
{
43+
peaks.Add(i);
44+
}
45+
if (negative)
46+
if ((range.Count() > 0) && (current > System.Math.Abs(noise)) && (current == range.Min()))
47+
{
48+
peaks.Add(i);
49+
}
50+
}
51+
52+
return peaks;
53+
}
54+
55+
public static IList<int> FindTrigger(IList<float> values, float noise)
56+
{
57+
List<int> triggers = new List<int>();
58+
float current;
59+
60+
float lastValue = 0;
61+
62+
for (int i = 0; i < values.Count; i++)
63+
{
64+
current = values[i];
65+
66+
if (current != lastValue)
67+
{
68+
lastValue = current;
69+
triggers.Add(i);
70+
}
71+
}
72+
73+
return triggers;
74+
}
75+
76+
77+
public static IList<float> FilterByMovingAverage(IList<float> list, int smoothFactor)
78+
{
79+
80+
return Enumerable
81+
.Range(0, list.Count - smoothFactor)
82+
.Select(n => list.Skip(n).Take(smoothFactor).Average())
83+
.ToList();
84+
85+
}
86+
}
87+
88+
}
89+

0 commit comments

Comments
 (0)