@@ -55,6 +55,7 @@ def __init__(self, config: AnomalyOperatorConfig, datasets: AnomalyDatasets):
55
55
def generate_report (self ):
56
56
"""Generates the report."""
57
57
import matplotlib .pyplot as plt
58
+ plt .rcParams .update ({'figure.max_open_warning' : 0 })
58
59
import report_creator as rc
59
60
60
61
start_time = time .time ()
@@ -87,43 +88,57 @@ def generate_report(self):
87
88
self .spec .datetime_column .name if self .spec .datetime_column else "index"
88
89
)
89
90
91
+ (
92
+ model_description ,
93
+ other_sections ,
94
+ ) = self ._generate_report ()
95
+
90
96
blocks = []
91
97
for target , df in self .datasets .full_data_dict .items ():
92
- figure_blocks = []
93
- time_col = df [date_column ].reset_index (drop = True )
94
- anomaly_col = anomaly_output .get_anomalies_by_cat (category = target )[
95
- OutputColumns .ANOMALY_COL
96
- ]
97
- anomaly_indices = [i for i , index in enumerate (anomaly_col ) if index == 1 ]
98
- downsampled_time_col = time_col
99
- selected_indices = list (range (len (time_col )))
100
- if self .spec .subsample_report_data :
101
- non_anomaly_indices = [i for i in range (len (time_col )) if i not in anomaly_indices ]
102
- # Downsample non-anomalous data if it exceeds the threshold (1000)
103
- if len (non_anomaly_indices ) > SUBSAMPLE_THRESHOLD :
104
- downsampled_non_anomaly_indices = non_anomaly_indices [::len (non_anomaly_indices )// SUBSAMPLE_THRESHOLD ]
105
- selected_indices = anomaly_indices + downsampled_non_anomaly_indices
106
- selected_indices .sort ()
107
- downsampled_time_col = time_col [selected_indices ]
108
-
109
- columns = set (df .columns ).difference ({date_column })
110
- for col in columns :
111
- y = df [col ].reset_index (drop = True )
112
-
113
- downsampled_y = y [selected_indices ]
114
-
115
- fig , ax = plt .subplots (figsize = (8 , 3 ), layout = "constrained" )
116
- ax .grid ()
117
- ax .plot (downsampled_time_col , downsampled_y , color = "black" )
118
- # Plot anomalies
119
- for i in anomaly_indices :
120
- ax .scatter (time_col [i ], y [i ], color = "red" , marker = "o" )
121
- plt .xlabel (date_column )
122
- plt .ylabel (col )
123
- plt .title (f"`{ col } ` with reference to anomalies" )
124
- figure_blocks .append (rc .Widget (ax ))
125
-
126
- blocks .append (rc .Group (* figure_blocks , label = target ))
98
+ if target in anomaly_output .list_categories ():
99
+ figure_blocks = []
100
+ time_col = df [date_column ].reset_index (drop = True )
101
+ anomaly_col = anomaly_output .get_anomalies_by_cat (category = target )[
102
+ OutputColumns .ANOMALY_COL
103
+ ]
104
+ anomaly_indices = [
105
+ i for i , index in enumerate (anomaly_col ) if index == 1
106
+ ]
107
+ downsampled_time_col = time_col
108
+ selected_indices = list (range (len (time_col )))
109
+ if self .spec .subsample_report_data :
110
+ non_anomaly_indices = [
111
+ i for i in range (len (time_col )) if i not in anomaly_indices
112
+ ]
113
+ # Downsample non-anomalous data if it exceeds the threshold (1000)
114
+ if len (non_anomaly_indices ) > SUBSAMPLE_THRESHOLD :
115
+ downsampled_non_anomaly_indices = non_anomaly_indices [
116
+ :: len (non_anomaly_indices ) // SUBSAMPLE_THRESHOLD
117
+ ]
118
+ selected_indices = (
119
+ anomaly_indices + downsampled_non_anomaly_indices
120
+ )
121
+ selected_indices .sort ()
122
+ downsampled_time_col = time_col [selected_indices ]
123
+
124
+ columns = set (df .columns ).difference ({date_column })
125
+ for col in columns :
126
+ y = df [col ].reset_index (drop = True )
127
+
128
+ downsampled_y = y [selected_indices ]
129
+
130
+ fig , ax = plt .subplots (figsize = (8 , 3 ), layout = "constrained" )
131
+ ax .grid ()
132
+ ax .plot (downsampled_time_col , downsampled_y , color = "black" )
133
+ # Plot anomalies
134
+ for i in anomaly_indices :
135
+ ax .scatter (time_col [i ], y [i ], color = "red" , marker = "o" )
136
+ plt .xlabel (date_column )
137
+ plt .ylabel (col )
138
+ plt .title (f"`{ col } ` with reference to anomalies" )
139
+ figure_blocks .append (rc .Widget (ax ))
140
+
141
+ blocks .append (rc .Group (* figure_blocks , label = target ))
127
142
plots = rc .Select (blocks )
128
143
129
144
report_sections = []
@@ -133,7 +148,7 @@ def generate_report(self):
133
148
yaml_appendix = rc .Yaml (self .config .to_dict ())
134
149
summary = rc .Block (
135
150
rc .Group (
136
- rc .Text (f"You selected the **`{ self .spec .model } `** model." ),
151
+ rc .Text (f"You selected the **`{ self .spec .model } `** model.\n { model_description . text } \n " ),
137
152
rc .Text (
138
153
"Based on your dataset, you could have also selected "
139
154
f"any of the models: `{ '`, `' .join (SupportedModels .keys () if self .spec .datetime_column else NonTimeADSupportedModels .keys ())} `."
0 commit comments