-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.cs
71 lines (60 loc) · 1.91 KB
/
Util.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StabilityTest
{
internal static class Util
{
public static long Median(List<long> list)
{
list.Sort();
return list[list.Count / 2];
}
public static (int count, List<long> filtered) FilterZeros(long[] array)
{
List<long> filtered = new List<long>();
int count = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] != 0)
{
filtered.Add(array[i]);
}
else
count++;
}
return (count, filtered);
}
public static (int count, double avg, double avggap) ProcessSpikes(List<long> list, int WaitTime)
{
long median = Median(list);
int spikes = 0;
List<long> spikelist = new List<long>();
List<double> spikegaps = new List<double>();
int gap = 0;
for (int i = 0; i < list.Count; i++)
{
if ((median < 50 && list[i] > 70) || (median >= 50 && list[i] > (median * 1.5f)))
{
spikes++;
spikelist.Add(list[i]);
spikegaps.Add(gap * WaitTime);
gap = 0;
}
else
{
gap++;
}
}
double avgspike, avggap;
if (spikelist.Any()) avgspike = spikelist.Average();
else avgspike = 0;
if (spikegaps.Any()) avggap = spikegaps.Average();
else avggap = 0;
return (spikes, avgspike, avggap);
}
}
}