11#!/usr/bin/env python
22# -*- coding: utf-8 -*--
33
4- # Copyright (c) 2023 Oracle and/or its affiliates.
4+ # Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66
77import os
@@ -57,7 +57,7 @@ def __init__(self, config: AnomalyOperatorConfig, datasets: AnomalyDatasets):
5757
5858 def generate_report (self ):
5959 """Generates the report."""
60- import datapane as dp
60+ import report_creator as rc
6161 import matplotlib .pyplot as plt
6262
6363 start_time = time .time ()
@@ -79,12 +79,10 @@ def generate_report(self):
7979 anomaly_output , test_data , elapsed_time
8080 )
8181 table_blocks = [
82- dp .DataTable (df , label = col )
82+ rc .DataTable (df , label = col , index = True )
8383 for col , df in self .datasets .full_data_dict .items ()
8484 ]
85- data_table = (
86- dp .Select (blocks = table_blocks ) if len (table_blocks ) > 1 else table_blocks [0 ]
87- )
85+ data_table = rc .Select (blocks = table_blocks )
8886 date_column = self .spec .datetime_column .name
8987
9088 blocks = []
@@ -106,44 +104,42 @@ def generate_report(self):
106104 plt .xlabel (date_column )
107105 plt .ylabel (col )
108106 plt .title (f"`{ col } ` with reference to anomalies" )
109- figure_blocks .append (ax )
110- blocks .append (dp .Group (blocks = figure_blocks , label = target ))
111- plots = dp .Select (blocks = blocks ) if len ( blocks ) > 1 else blocks [ 0 ]
107+ figure_blocks .append (rc . Widget ( ax ) )
108+ blocks .append (rc .Group (* figure_blocks , label = target ))
109+ plots = rc .Select (blocks )
112110
113111 report_sections = []
114- title_text = dp .Text ("# Anomaly Detection Report" )
115-
116- yaml_appendix_title = dp .Text (f"## Reference: YAML File" )
117- yaml_appendix = dp .Code (code = self .config .to_yaml (), language = "yaml" )
118- summary = dp .Blocks (
119- blocks = [
120- dp .Group (
121- dp .Text (f"You selected the **`{ self .spec .model } `** model." ),
122- dp .Text (
123- "Based on your dataset, you could have also selected "
124- f"any of the models: `{ '`, `' .join (SupportedModels .keys ())} `."
125- ),
126- dp .BigNumber (
127- heading = "Analysis was completed in " ,
128- value = human_time_friendly (elapsed_time ),
129- ),
130- label = "Summary" ,
131- )
132- ]
112+ title_text = rc .Heading ("Anomaly Detection Report" , level = 1 )
113+
114+ yaml_appendix_title = rc .Heading ("Reference: YAML File" , level = 2 )
115+ yaml_appendix = rc .Yaml (self .config .to_dict ())
116+ summary = rc .Block (
117+ rc .Group (
118+ rc .Text (f"You selected the **`{ self .spec .model } `** model." ),
119+ rc .Text (
120+ "Based on your dataset, you could have also selected "
121+ f"any of the models: `{ '`, `' .join (SupportedModels .keys ())} `."
122+ ),
123+ rc .Metric (
124+ heading = "Analysis was completed in " ,
125+ value = human_time_friendly (elapsed_time ),
126+ ),
127+ label = "Summary" ,
128+ )
133129 )
134- sec_text = dp . Text ( f"## Train Evaluation Metrics" )
135- sec = dp .DataTable (self ._evaluation_metrics (anomaly_output ))
130+ sec_text = rc . Heading ( " Train Evaluation Metrics", level = 2 )
131+ sec = rc .DataTable (self ._evaluation_metrics (anomaly_output ), index = True )
136132 evaluation_metrics_sec = [sec_text , sec ]
137133
138134 test_metrics_sections = []
139135 if total_metrics is not None and not total_metrics .empty :
140- sec_text = dp . Text ( f"## Test Data Evaluation Metrics" )
141- sec = dp .DataTable (total_metrics )
136+ sec_text = rc . Heading ( " Test Data Evaluation Metrics", level = 2 )
137+ sec = rc .DataTable (total_metrics , index = True )
142138 test_metrics_sections = test_metrics_sections + [sec_text , sec ]
143139
144140 if summary_metrics is not None and not summary_metrics .empty :
145- sec_text = dp . Text ( f"## Test Data Summary Metrics" )
146- sec = dp .DataTable (summary_metrics )
141+ sec_text = rc . Heading ( " Test Data Summary Metrics", level = 2 )
142+ sec = rc .DataTable (summary_metrics , index = True )
147143 test_metrics_sections = test_metrics_sections + [sec_text , sec ]
148144
149145 report_sections = (
@@ -248,7 +244,7 @@ def _save_report(
248244 test_metrics : pd .DataFrame ,
249245 ):
250246 """Saves resulting reports to the given folder."""
251- import datapane as dp
247+ import report_creator as rc
252248
253249 unique_output_dir = find_output_dirname (self .spec .output_directory )
254250
@@ -257,11 +253,12 @@ def _save_report(
257253 else :
258254 storage_options = dict ()
259255
260- # datapane html report
256+ # report-creator html report
261257 with tempfile .TemporaryDirectory () as temp_dir :
262258 report_local_path = os .path .join (temp_dir , "___report.html" )
263259 disable_print ()
264- dp .save_report (report_sections , report_local_path )
260+ with rc .ReportCreator ("My Report" ) as report :
261+ report .save (rc .Block (* report_sections ), report_local_path )
265262 enable_print ()
266263 with open (report_local_path ) as f1 :
267264 with fsspec .open (
0 commit comments