11import numpy as np
22import pandas as pd
33from mlblocks import MLBlock
4+
45from zephyr_ml .core import DEFAULT_METRICS , Zephyr
56
67
@@ -10,8 +11,10 @@ class TestZephyr:
1011 def base_dfs ():
1112 alarms_df = pd .DataFrame ({
1213 'COD_ELEMENT' : [0 , 0 ],
13- 'DAT_START' : [pd .Timestamp ('2022-01-01 00:00:00' ), pd .Timestamp ('2022-03-01 11:12:13' )],
14- 'DAT_END' : [pd .Timestamp ('2022-01-01 13:00:00' ), pd .Timestamp ('2022-03-02 11:12:13' )],
14+ 'DAT_START' : [pd .Timestamp ('2022-01-01 00:00:00' ),
15+ pd .Timestamp ('2022-03-01 11:12:13' )],
16+ 'DAT_END' : [pd .Timestamp ('2022-01-01 13:00:00' ),
17+ pd .Timestamp ('2022-03-02 11:12:13' )],
1518 'IND_DURATION' : [0.5417 , 1.0 ],
1619 'COD_ALARM' : [12345 , 98754 ],
1720 'COD_ALARM_INT' : [12345 , 98754 ],
@@ -20,8 +23,10 @@ def base_dfs():
2023 })
2124 stoppages_df = pd .DataFrame ({
2225 'COD_ELEMENT' : [0 , 0 ],
23- 'DAT_START' : [pd .Timestamp ('2022-01-01 00:00:00' ), pd .Timestamp ('2022-03-01 11:12:13' )],
24- 'DAT_END' : [pd .Timestamp ('2022-01-08 11:07:17' ), pd .Timestamp ('2022-03-01 17:00:13' )],
26+ 'DAT_START' : [pd .Timestamp ('2022-01-01 00:00:00' ),
27+ pd .Timestamp ('2022-03-01 11:12:13' )],
28+ 'DAT_END' : [pd .Timestamp ('2022-01-08 11:07:17' ),
29+ pd .Timestamp ('2022-03-01 17:00:13' )],
2530 'DES_WO_NAME' : ['stoppage name 1' , 'stoppage name 2' ],
2631 'DES_COMMENTS' : ['description of stoppage 1' , 'description of stoppage 2' ],
2732 'COD_WO' : [12345 , 67890 ],
@@ -40,12 +45,15 @@ def base_dfs():
4045 'COD_ORDER' : [12345 , 67890 ],
4146 'IND_QUANTITY' : [1 , - 20 ],
4247 'COD_MATERIAL_SAP' : [36052411 , 67890 ],
43- 'DAT_POSTING' : [pd .Timestamp ('2022-01-01 00:00:00' ), pd .Timestamp ('2022-03-01 00:00:00' )],
48+ 'DAT_POSTING' : [pd .Timestamp ('2022-01-01 00:00:00' ),
49+ pd .Timestamp ('2022-03-01 00:00:00' )],
4450 'COD_MAT_DOC' : [77889900 , 12345690 ],
4551 'DES_MEDIUM' : ['Description of notification 1' , 'Description of notification 2' ],
4652 'COD_NOTIF' : [567890123 , 32109877 ],
47- 'DAT_MALF_START' : [pd .Timestamp ('2021-12-25 18:07:10' ), pd .Timestamp ('2022-02-28 06:04:00' )],
48- 'DAT_MALF_END' : [pd .Timestamp ('2022-01-08 11:07:17' ), pd .Timestamp ('2022-03-01 17:00:13' )],
53+ 'DAT_MALF_START' : [pd .Timestamp ('2021-12-25 18:07:10' ),
54+ pd .Timestamp ('2022-02-28 06:04:00' )],
55+ 'DAT_MALF_END' : [pd .Timestamp ('2022-01-08 11:07:17' ),
56+ pd .Timestamp ('2022-03-01 17:00:13' )],
4957 'IND_BREAKDOWN_DUR' : [14.1378 , 2.4792 ],
5058 'FUNCT_LOC_DES' : ['location description 1' , 'location description 2' ],
5159 'COD_ALARM' : [12345 , 12345 ],
@@ -54,15 +62,19 @@ def base_dfs():
5462 work_orders_df = pd .DataFrame ({
5563 'COD_ELEMENT' : [0 , 0 ],
5664 'COD_ORDER' : [12345 , 67890 ],
57- 'DAT_BASIC_START' : [pd .Timestamp ('2022-01-01 00:00:00' ), pd .Timestamp ('2022-03-01 00:00:00' )],
58- 'DAT_BASIC_END' : [pd .Timestamp ('2022-01-09 00:00:00' ), pd .Timestamp ('2022-03-02 00:00:00' )],
65+ 'DAT_BASIC_START' : [pd .Timestamp ('2022-01-01 00:00:00' ),
66+ pd .Timestamp ('2022-03-01 00:00:00' )],
67+ 'DAT_BASIC_END' : [pd .Timestamp ('2022-01-09 00:00:00' ),
68+ pd .Timestamp ('2022-03-02 00:00:00' )],
5969 'COD_EQUIPMENT' : [98765 , 98765 ],
6070 'COD_MAINT_PLANT' : ['ABC' , 'ABC' ],
6171 'COD_MAINT_ACT_TYPE' : ['XYZ' , 'XYZ' ],
6272 'COD_CREATED_BY' : ['A1234' , 'B6789' ],
6373 'COD_ORDER_TYPE' : ['A' , 'B' ],
64- 'DAT_REFERENCE' : [pd .Timestamp ('2022-01-01 00:00:00' ), pd .Timestamp ('2022-03-01 00:00:00' )],
65- 'DAT_CREATED_ON' : [pd .Timestamp ('2022-03-01 00:00:00' ), pd .Timestamp ('2022-04-18 00:00:00' )],
74+ 'DAT_REFERENCE' : [pd .Timestamp ('2022-01-01 00:00:00' ),
75+ pd .Timestamp ('2022-03-01 00:00:00' )],
76+ 'DAT_CREATED_ON' : [pd .Timestamp ('2022-03-01 00:00:00' ),
77+ pd .Timestamp ('2022-04-18 00:00:00' )],
6678 'DAT_VALID_END' : [pd .NaT , pd .NaT ],
6779 'DAT_VALID_START' : [pd .NaT , pd .NaT ],
6880 'COD_SYSTEM_STAT' : ['ABC XYZ' , 'LMN OPQ' ],
@@ -86,7 +98,8 @@ def base_dfs():
8698 'PI_LOCAL_SITE_NAME' : ['LOC0' ]
8799 })
88100 pidata_df = pd .DataFrame ({
89- 'time' : [pd .Timestamp ('2022-01-02 13:21:01' ), pd .Timestamp ('2022-03-08 13:21:01' )],
101+ 'time' : [pd .Timestamp ('2022-01-02 13:21:01' ),
102+ pd .Timestamp ('2022-03-08 13:21:01' )],
90103 'COD_ELEMENT' : [0 , 0 ],
91104 'val1' : [9872.0 , 559.0 ],
92105 'val2' : [10.0 , - 7.0 ]
@@ -153,40 +166,47 @@ def setup_class(cls):
153166
154167 def test_initialize_class (self ):
155168 _ = Zephyr ()
156-
157169
158170 def test_generate_entityset (self ):
159171 zephyr = Zephyr ()
160- zephyr .generate_entityset (** self .__class__ .kwargs ["generate_entityset" ])
172+ zephyr .generate_entityset (
173+ ** self .__class__ .kwargs ["generate_entityset" ])
161174 es = zephyr .get_entityset ()
162175 assert es is not None
163176 assert es .id == 'pidata'
164177
165178 def test_generate_label_times (self ):
166179 zephyr = Zephyr ()
167- zephyr .generate_entityset (** self .__class__ .kwargs ["generate_entityset" ])
168- zephyr .generate_label_times (** self .__class__ .kwargs ["generate_label_times" ])
180+ zephyr .generate_entityset (
181+ ** self .__class__ .kwargs ["generate_entityset" ])
182+ zephyr .generate_label_times (
183+ ** self .__class__ .kwargs ["generate_label_times" ])
169184 label_times = zephyr .get_label_times (visualize = False )
170185 assert label_times is not None
171186
172187 def test_generate_feature_matrix_and_labels (self ):
173188 zephyr = Zephyr ()
174- zephyr .generate_entityset (** self .__class__ .kwargs ["generate_entityset" ])
175- zephyr .generate_label_times (** self .__class__ .kwargs ["generate_label_times" ])
189+ zephyr .generate_entityset (
190+ ** self .__class__ .kwargs ["generate_entityset" ])
191+ zephyr .generate_label_times (
192+ ** self .__class__ .kwargs ["generate_label_times" ])
176193 zephyr .generate_feature_matrix (
177194 ** self .__class__ .kwargs ["generate_feature_matrix" ])
178- feature_matrix , label_col_name , features = zephyr .get_feature_matrix ()
195+ feature_matrix , label_col_name , features = zephyr .get_feature_matrix ()
179196 assert feature_matrix is not None
180197 assert label_col_name in feature_matrix .columns
181198 assert features is not None
182199
183200 def test_generate_train_test_split (self ):
184201 zephyr = Zephyr ()
185- zephyr .generate_entityset (** self .__class__ .kwargs ["generate_entityset" ])
186- zephyr .generate_label_times (** self .__class__ .kwargs ["generate_label_times" ])
202+ zephyr .generate_entityset (
203+ ** self .__class__ .kwargs ["generate_entityset" ])
204+ zephyr .generate_label_times (
205+ ** self .__class__ .kwargs ["generate_label_times" ])
187206 zephyr .generate_feature_matrix (
188207 ** self .__class__ .kwargs ["generate_feature_matrix" ])
189- zephyr .generate_train_test_split (** self .__class__ .kwargs ["generate_train_test_split" ])
208+ zephyr .generate_train_test_split (
209+ ** self .__class__ .kwargs ["generate_train_test_split" ])
190210 train_test_split = zephyr .get_train_test_split ()
191211 assert train_test_split is not None
192212 X_train , X_test , y_train , y_test = train_test_split
@@ -217,7 +237,8 @@ def test_fit_pipeline_no_visual(self):
217237 def test_fit_pipeline_visual (self ):
218238 zephyr = Zephyr ()
219239 zephyr .set_train_test_split (* self .base_train_test_split ())
220- output = zephyr .fit_pipeline (visual = True , ** self .__class__ .kwargs ["fit_pipeline" ])
240+ output = zephyr .fit_pipeline (
241+ visual = True , ** self .__class__ .kwargs ["fit_pipeline" ])
221242 assert isinstance (output , dict )
222243 assert list (output .keys ()) == ['threshold' , 'scores' ]
223244 pipeline = zephyr .get_fitted_pipeline ()
0 commit comments