-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmySD.py
49 lines (42 loc) · 1.3 KB
/
mySD.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
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
class mySDDD:
def __init__(self, WindowSize = 40):
self.WindowSize = WindowSize
self.y = []
self.minSD = 0
self.det_change = 0
self.det_warning = 0
def add_element(self, element):
size_y = len(self.y)
if (size_y == self.WindowSize):
self.y = self.y[1:size_y]
self.y = np.append(self.y, element)
if (size_y == self.WindowSize):
currSD = self.y.std()
if currSD < self.minSD or self.minSD == 0:
self.minSD = currSD
warning_bound = self.minSD *2
if currSD > warning_bound:
self.det_warning = 1
change_bound = self.minSD *3
if currSD > change_bound:
self.det_change = 1
def detected_change(self):
result = False
if self.det_change == 1:
result = True
else:
result = False
return(result)
def detected_warning_zone(self):
result = False
if self.det_warning == 1:
result = True
return (result)
def reset(self):
self.y = []
self.minSD = 0
self.det_change = 0
self.det_warning = 0