feat: enhance report generation with target name and content injection
- Added target_name parameter to Reports class for improved report context. - Updated inject_content function to ensure proper handling of HTML sections. - Modified DataManagerRepository to join predictions with training and validation data for accurate report generation.
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
||||
from collections.abc import Sequence
|
||||
from typing import Any
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
from evidently.metric_preset import DataDriftPreset
|
||||
from evidently.metrics import (
|
||||
ColumnSummaryMetric,
|
||||
@@ -20,6 +20,7 @@ from evidently.metrics import (
|
||||
from evidently.metrics.base_metric import generate_column_metrics
|
||||
from evidently.options import ColorOptions
|
||||
from evidently.report import Report
|
||||
from evidently.pipeline.column_mapping import ColumnMapping
|
||||
|
||||
COLOR_DISCRETE_SEQUENCE = (
|
||||
'#ed0400',
|
||||
@@ -44,9 +45,14 @@ def load_html_from_file(file_path):
|
||||
def inject_content(main_html, section_id, content):
|
||||
soup = BeautifulSoup(main_html, 'html.parser')
|
||||
section = soup.find(id=section_id)
|
||||
if section:
|
||||
|
||||
# Verifica se a seção foi encontrada E se ela é uma Tag (não uma string)
|
||||
if section and isinstance(section, Tag):
|
||||
section.clear()
|
||||
section.append(BeautifulSoup(content, 'html.parser'))
|
||||
# Converte o conteúdo para um fragmento de BeautifulSoup e anexa
|
||||
new_content = BeautifulSoup(content, 'html.parser')
|
||||
section.append(new_content)
|
||||
|
||||
return str(soup)
|
||||
|
||||
|
||||
@@ -68,7 +74,7 @@ class Reports:
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, reference_data: Any, current_data: Any, base_path: str | None = None
|
||||
self, reference_data: Any, current_data: Any, target_name: str, base_path: str | None = None
|
||||
) -> None:
|
||||
"""
|
||||
Initializes an instance of the AigReport class.
|
||||
@@ -84,6 +90,7 @@ class Reports:
|
||||
self.report: Any = None
|
||||
self.ref_data = reference_data
|
||||
self.cur_data = current_data
|
||||
self.target_name = target_name
|
||||
self.set_color_options(primary_color='#0F4C81', secondary_color='#001E60')
|
||||
self.base_path = base_path
|
||||
|
||||
@@ -145,8 +152,17 @@ class Reports:
|
||||
]
|
||||
self.metrics.extend(metrics)
|
||||
if run:
|
||||
mapping = ColumnMapping()
|
||||
|
||||
mapping.target = self.target_name
|
||||
mapping.prediction = 'prediction'
|
||||
|
||||
report = Report(metrics=metrics, options=self.options)
|
||||
report.run(reference_data=self.ref_data, current_data=self.cur_data)
|
||||
report.run(
|
||||
reference_data=self.ref_data,
|
||||
current_data=self.cur_data,
|
||||
column_mapping=mapping,
|
||||
)
|
||||
self.sections['regression'] = report.as_dict()
|
||||
if self.base_path:
|
||||
# Note: Relies on Evidently's save_html() to properly manage file I/O
|
||||
|
||||
Reference in New Issue
Block a user