1616
1717from ads .opctl import logger
1818
19+ from ...common .utils import get_unique_report_dir
1920from ..operator_config import AnomalyOperatorConfig , AnomalyOperatorSpec
2021from .anomaly_dataset import AnomalyDatasets , AnomalyOutput
2122from ..const import OutputColumns , SupportedMetrics
@@ -266,17 +267,9 @@ def _save_report(
266267 """Saves resulting reports to the given folder."""
267268 import datapane as dp
268269
269- if self .spec .output_directory :
270- output_dir = self .spec .output_directory .url
271- else :
272- output_dir = "tmp_operator_result"
273- logger .warn (
274- "Since the output directory was not specified, the output will be saved to {} directory." .format (
275- output_dir
276- )
277- )
270+ unique_output_dir = get_unique_report_dir (self .spec .output_directory )
278271
279- if ObjectStorageDetails .is_oci_path (output_dir ):
272+ if ObjectStorageDetails .is_oci_path (unique_output_dir ):
280273 storage_options = default_signer ()
281274 else :
282275 storage_options = dict ()
@@ -287,7 +280,7 @@ def _save_report(
287280 dp .save_report (report_sections , report_local_path )
288281 with open (report_local_path ) as f1 :
289282 with fsspec .open (
290- os .path .join (output_dir , self .spec .report_file_name ),
283+ os .path .join (unique_output_dir , self .spec .report_file_name ),
291284 "w" ,
292285 ** default_signer (),
293286 ) as f2 :
@@ -297,15 +290,15 @@ def _save_report(
297290 inliers = anomaly_output .get_inliers (self .datasets .data )
298291 write_data (
299292 data = inliers ,
300- filename = os .path .join (output_dir , self .spec .inliers_filename ),
293+ filename = os .path .join (unique_output_dir , self .spec .inliers_filename ),
301294 format = "csv" ,
302295 storage_options = storage_options ,
303296 )
304297
305298 outliers = anomaly_output .get_outliers (self .datasets .data )
306299 write_data (
307300 data = outliers ,
308- filename = os .path .join (output_dir , self .spec .outliers_filename ),
301+ filename = os .path .join (unique_output_dir , self .spec .outliers_filename ),
309302 format = "csv" ,
310303 storage_options = storage_options ,
311304 )
@@ -314,15 +307,15 @@ def _save_report(
314307 write_data (
315308 data = validation_metrics .rename_axis ("metrics" ).reset_index (),
316309 filename = os .path .join (
317- output_dir , self .spec .validation_metrics_filename
310+ unique_output_dir , self .spec .validation_metrics_filename
318311 ),
319312 format = "csv" ,
320313 storage_options = storage_options ,
321314 )
322315
323316 logger .warn (
324317 f"The report has been successfully "
325- f"generated and placed to the: { output_dir } ."
318+ f"generated and placed to the: { unique_output_dir } ."
326319 )
327320
328321 @abstractmethod
0 commit comments