@@ -63,6 +63,7 @@ def compute_indicator_values(vect, threshold, perc, quant, highest, lowest):
63
63
64
64
### Removing nan
65
65
vect = vect [vect != np .nan ]
66
+ vect = vect .astype (np .float )
66
67
67
68
### Create low demand list names
68
69
list_low_demand = ["zero" , "perc_threshold" ]
@@ -82,7 +83,7 @@ def compute_indicator_values(vect, threshold, perc, quant, highest, lowest):
82
83
nzd = vect [vect > low_demand ]
83
84
k = len (nzd )
84
85
85
- if sum (vect [vect > low_demand ])>= 2 :
86
+ if ( sum (vect [vect > low_demand ])>= 2 ) & ( k > 1 ) :
86
87
x = np .append ([nzd [0 ]], [nzd [1 :k ] - nzd [0 :(k - 1 )]])
87
88
88
89
cv2 = Intermittent .cv2 (nzd , highest , lowest )
@@ -97,7 +98,7 @@ def compute_indicator_values(vect, threshold, perc, quant, highest, lowest):
97
98
98
99
return res
99
100
100
- def enh_compute_indicator_values (vect , threshold , perc , quant , highest , lowest ):
101
+ def enhanced_compute_indicator_values (vect , threshold , perc , quant , highest , lowest ):
101
102
''' Computes indicator values (enhanced)
102
103
:params: vect as numpy array, threshold as numeric, perc as numeric, quant as numeric, highest and lowest as scalars 0<=x<=1 as winsorization percentages
103
104
:return: a dictionary
@@ -113,8 +114,9 @@ def enh_compute_indicator_values(vect, threshold, perc, quant, highest, lowest):
113
114
vect = vect [1 :len (vect )]
114
115
print ('Threshold:' , threshold )
115
116
116
- ### Removing nan
117
- vect = vect [vect != np .nan ]
117
+ ### Removing nan and selecting float
118
+ vect = vect [(vect != np .nan )]
119
+ vect = vect .astype (np .float )
118
120
119
121
### Z function
120
122
def Z (quant ):
@@ -136,7 +138,7 @@ def Z(quant):
136
138
nzd = vect [vect > low_demand ]
137
139
k = len (nzd )
138
140
139
- if sum (vect [vect > low_demand ])>= 2 :
141
+ if ( sum (vect [vect > low_demand ])>= 2 ) & ( k > 1 ) :
140
142
x = np .array ([nzd [0 ]]) + [nzd [1 :k ] - nzd [0 :(k - 1 )]] + np .array ([len (vect )+ 1 - nzd [k - 1 ]])
141
143
142
144
cv2 = Intermittent .cv2 (nzd , highest , lowest )
@@ -196,18 +198,18 @@ def classify_intermittent(df, type, thres_cv2_constant, thres_cv2, thres_adi, th
196
198
except :
197
199
print ('classify_intermittent: no constant ids' )
198
200
199
- # Intermittent
200
- mask_intermittent = (score_no_nan .type == type ) & \
201
+ # Spikes
202
+ mask_spikes = (score_no_nan .type == type ) & \
201
203
(score_no_nan .k > min_time_cons ) & \
202
204
(score_no_nan .cv2 < thres_cv2 ) & \
203
205
(score_no_nan .cv2 >= thres_adi ) & \
204
206
(score_no_nan .cv2 < thres_sddi )
205
- df_intermittent = score_no_nan .loc [mask_intermittent , ]
207
+ df_spikes = score_no_nan .loc [mask_spikes , ]
206
208
try :
207
- df_intermittent .loc [:, 'profile' ] = 'intermittent '
208
- print ('classify_intermittent: intermittent ids' , len (df_intermittent ))
209
+ df_spikes .loc [:, 'profile' ] = 'spikes '
210
+ print ('classify_intermittent: spikes ids' , len (df_spikes ))
209
211
except :
210
- print ('classify_intermittent: no intermittent ids' )
212
+ print ('classify_intermittent: no spikes ids' )
211
213
212
214
# Lumpy
213
215
mask_lumpy = (score_no_nan .type == type ) & \
@@ -260,13 +262,13 @@ def classify_intermittent(df, type, thres_cv2_constant, thres_cv2, thres_adi, th
260
262
print ('classify_intermittent: no unforecastable_quantity ids' )
261
263
262
264
# df_profiling
263
- df_profiling = pd .concat ([df_regular , df_constant_zero , df_constant , df_intermittent , df_lumpy , df_erratic , df_unforecastable_time , df_unforecastable_quantity ], axis = 0 )
265
+ df_profiling = pd .concat ([df_regular , df_constant_zero , df_constant , df_spikes , df_lumpy , df_erratic , df_unforecastable_time , df_unforecastable_quantity ], axis = 0 )
264
266
265
267
return df_profiling
266
268
267
269
def call_intermittent_function (func , * args ):
268
270
from Code .Profiling .Intermittent .intermittent import Intermittent
269
- func_dict = {'enh_compute_indicator_values ' : Intermittent .enh_compute_indicator_values , 'compute_indicator_values' : Intermittent .compute_indicator_values }
271
+ func_dict = {'enhanced_compute_indicator_values ' : Intermittent .enhanced_compute_indicator_values , 'compute_indicator_values' : Intermittent .compute_indicator_values }
270
272
result = func_dict .get (func )(* args )
271
273
return result
272
274
0 commit comments