-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstableValue3.py
69 lines (58 loc) · 2.26 KB
/
stableValue3.py
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
import matplotlib.pyplot as plt
import statistics
import numpy as np
def stableSmallest(values, stablePercent):
stablepoint = 2
stablepoints = []
countregression = 0
countstability = 0
upperlimit = []
lowerlimit = []
stabpts = []
regressions = []
plt.style.use('seaborn-whitegrid')
plt.axis([0, 20, 0, 6])
# plt.figure()
for i in range(0, len(values)):
print(f'------------------------------------\nVALUES: {values[i]}')
upperlimit.append(stablepoint+1)
lowerlimit.append(stablepoint-1)
stabpts.append(stablepoint)
print(f'UpperLimit: {upperlimit[-1]}\nLowerLimit: {lowerlimit[-1]}')
if values[i]<=upperlimit[-1] and values[i]>=lowerlimit[-1]:
stablepoints.append(values[i])
countstability += 1
countregression = 0
else:
print(stablepoints)
countregression += 1
countstability = 0
stablepoints.clear()
if values[i] >= upperlimit[-1]:
regressions.append(values[i])
plt.plot(i, values[i], 'ro')
# plt.legend(['Spikes'])
if countstability >= 3:
print(f'Regression At {values[i-countstability]}')
plt.plot(i-countstability, values[i-countstability], 'X', color='red')
elif countregression >= 3:
print(f'Regression At {values[i-countregression]}')
plt.plot(i-countregression, values[i-countregression], 'X', color='red')
if values[i] <= stablepoint:
if countstability >= 3:
print(f'stable values: {stablepoints}')
if len(stablepoints) > 0:
stablepoint = statistics.mean(stablepoints)
print(f'NEW KPI {stablepoint}')
plt.plot(values, color='blue')
plt.plot(lowerlimit, color='green')
plt.plot(upperlimit, color='green')
plt.plot(stabpts, color='red')
# plt.scatter(regressions, 'ro')
# plt.legend(['Values','Lower Limit','Upper Limit','KPI'])
# plt.show()
if __name__ == "__main__":
stablePercent = 10
values = [2, 2, 2, 2.1, 2.5, 2.5, 2.5, 2.6, 2.8, 5, 5.5, 5.6, 5.8, 5.9, 1, 1, 1, 0.3, 0.3, 0.2, 0.1]
stableSmallest(values, stablePercent)
plt.show()