-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSeriesObject.py
57 lines (51 loc) · 2.02 KB
/
SeriesObject.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
import numpy as np
import scipy.signal as sps
import config
from datetime import datetime, timedelta
import minuter_med_buss as mmb
class SeriesObject():
def __init__(self, r):
series = np.array(r['array'])
peaks, properties = sps.find_peaks(series)
self.series = series
self.duration = len(series)/config.frequency
self.mu = series.mean()
self.abs_mu = abs(series).mean()
self.sigma = series.var()
self.max_a = abs(series).max()
self.rms = np.sqrt(np.mean(np.square(series)))
self.frequency = len(peaks)/len(series)*config.frequency
self.start_index = r['end_index'] - len(series)
self.end_index = r['end_index']
self.df_number = r['df_number']
self.feature = r['feature']
self.ts = r['ts']
strp = self.ts
if strp.date() != datetime(year=2021,month=5,day=4).date():
self.irl_label = 0
else:
corr = strp - timedelta(seconds = 52)
if corr.strftime('%Y-%m-%d %H:%M') in mmb.m:
self.irl_label = 1
else:
self.irl_label = 0
def get_feature_vector(self):
return np.array([self.mu,self.abs_mu,self.sigma,self.max_a,self.rms,self.frequency])
def get_feature_labels(self):
return ['mu', 'absolute_mu', 'sigma', 'max_value','rms','frequency']
def get_feature_vector_sensor(self): # The one used for PCA
return np.array(
[self.duration,self.mu,self.abs_mu,self.sigma,self.max_a,
self.rms,self.frequency])
def get_feature_labels_sensor(self):
return ['Duration', 'mu', 'absolute_mu', 'sigma', 'max_value','rms','frequency','sensor']
def get_feature_dict(self):
return {
'duration' : self.duration,
'mu': self.mu,
'abs_mu' : self.abs_mu,
'sigma' : self.sigma,
'max_a' : self.max_a,
'rms' : self.rms,
'frequency' : self.frequency,
}