@@ -79,7 +79,7 @@ def generate_report(self):
79
79
anomaly_output , test_data , elapsed_time
80
80
)
81
81
table_blocks = [
82
- rc .DataTable (df , label = col , index = True )
82
+ rc .DataTable (df . head ( 1000 ) if self . spec . optimize_report and len ( df ) > 1000 else df , label = col , index = True )
83
83
for col , df in self .datasets .full_data_dict .items ()
84
84
]
85
85
data_table = rc .Select (blocks = table_blocks )
@@ -94,20 +94,35 @@ def generate_report(self):
94
94
anomaly_col = anomaly_output .get_anomalies_by_cat (category = target )[
95
95
OutputColumns .ANOMALY_COL
96
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 .optimize_report :
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 ) > 1000 :
104
+ downsampled_non_anomaly_indices = non_anomaly_indices [::len (non_anomaly_indices )// 1000 ]
105
+ selected_indices = sorted (anomaly_indices + downsampled_non_anomaly_indices )
106
+ downsampled_time_col = time_col [selected_indices ]
107
+
97
108
columns = set (df .columns ).difference ({date_column })
98
109
for col in columns :
99
110
y = df [col ].reset_index (drop = True )
111
+
112
+ downsampled_y = y [selected_indices ]
113
+
100
114
fig , ax = plt .subplots (figsize = (8 , 3 ), layout = "constrained" )
101
115
ax .grid ()
102
- ax .plot (time_col , y , color = "black" )
103
- for i , index in enumerate ( anomaly_col ):
104
- if index == 1 :
105
- ax .scatter (time_col [i ], y [i ], color = "red" , marker = "o" )
116
+ ax .plot (downsampled_time_col , downsampled_y , color = "black" )
117
+ # Plot anomalies
118
+ for i in anomaly_indices :
119
+ ax .scatter (time_col [i ], y [i ], color = "red" , marker = "o" )
106
120
plt .xlabel (date_column )
107
121
plt .ylabel (col )
108
122
plt .title (f"`{ col } ` with reference to anomalies" )
109
123
figure_blocks .append (rc .Widget (ax ))
110
- blocks .append (rc .Group (* figure_blocks , label = target ))
124
+
125
+ blocks .append (rc .Group (* figure_blocks , label = target ))
111
126
plots = rc .Select (blocks )
112
127
113
128
report_sections = []
0 commit comments