pdstools.adm.Reports¶
Classes¶
Module Contents¶
- class Reports(datamart: pdstools.adm.ADMDatamart.ADMDatamart)¶
Bases:
pdstools.utils.namespaces.LazyNamespace- Parameters:
datamart (pdstools.adm.ADMDatamart.ADMDatamart)
- dependencies = ['yaml']¶
- dependency_group = 'healthcheck'¶
- datamart¶
- model_reports(model_ids: str | List[str], *, name: str | None = None, title: str = 'ADM Model Report', disclaimer: str = '', subtitle: str = '', output_dir: os.PathLike | None = None, only_active_predictors: bool = True, output_type: str = 'html', keep_temp_files: bool = False, verbose: bool = False, progress_callback: Callable[[int, int], None] | None = None, model_file_path: os.PathLike | None = None, predictor_file_path: os.PathLike | None = None, qmd_file: os.PathLike | None = None, remove_duplicate_html_scripts: bool = True) pathlib.Path¶
Generates model reports for Naive Bayes ADM models.
- Parameters:
model_ids (Union[str,List[str]]) – The model ID (or list of model IDs) to generate reports for.
name (str, optional) – The (base) file name of the report.
title (str, optional) – Title to put in the report, uses a default string if not given.
subtitle (str, optional) – Subtitle to put in the report, empty if not given.
disclaimer (str, optional) – Disclaimer blub to put in the report, empty if not given.
output_dir (Union[str, Path, None], optional) – The directory for the output. If None, uses current working directory.
only_active_predictors (bool, default=True) – Whether to only include active predictor details.
output_type (str, default='html') – The type of the output file (e.g., “html”, “pdf”).
keep_temp_files (bool, optional) – If True, the temporary directory with temp files will not be deleted after report generation.
verbose (bool, optional) – If True, prints detailed logs during execution.
progress_callback (Callable[[int, int], None], optional) – A callback function to report progress. Used only in the Streamlit app. The function should accept two integers: the current progress and the total.
model_file_path (Union[str, Path, None], optional) – Optional name of the actual model data file, so it does not get copied
predictor_file_path (Union[str, Path, None], optional) – Optional name of the actual predictor data file, so it does not get copied
qmd_file (Union[str, Path, None], optional) – Optional path to the Quarto file to use for the model report. If None, defaults to “ModelReport.qmd”.
remove_duplicate_html_scripts (bool, default=True) – Whether to remove duplicate script tags from the HTML output to reduce file size. Specifically targets large JavaScript libraries (like Plotly.js) that get embedded multiple times. Only affects HTML output types.
- Returns:
The path to the generated report file.
- Return type:
Path
- Raises:
ValueError – If there’s an error in report generation or invalid parameters.
FileNotFoundError – If required files are not found.
subprocess.SubprocessError – If there’s an error in running external commands.
- health_check(name: str | None = None, title: str = 'ADM Model Overview', subtitle: str = '', disclaimer: str = '', output_dir: os.PathLike | None = None, *, query: pdstools.utils.types.QUERY | None = None, output_type: str = 'html', keep_temp_files: bool = False, verbose: bool = False, prediction=None, model_file_path: os.PathLike | None = None, predictor_file_path: os.PathLike | None = None, prediction_file_path: os.PathLike | None = None, qmd_file: os.PathLike | None = None, remove_duplicate_html_scripts: bool = True) pathlib.Path¶
Generates Health Check report for ADM models, optionally including predictor and prediction sections.
- Parameters:
name (str, optional) – The (base) file name of the report.
title (str, optional) – Title to put in the report, uses a default string if not given.
subtitle (str, optional) – Subtitle to put in the report, empty if not given.
disclaimer (str, optional) – Disclaimer blub to put in the report, empty if not given.
query (QUERY, optional) – Optional extra filter on the datamart data
output_dir (Union[str, Path, None], optional) – The directory for the output. If None, uses current working directory.
output_type (str, default='html') – The type of the output file (e.g., “html”, “pdf”).
keep_temp_files (bool, optional) – If True, the temporary directory with temp files will not be deleted after report generation.
verbose (bool, optional) – If True, prints detailed logs during execution.
prediction (Prediction, optional) – Optional Prediction object to include in the health check. If provided without prediction_file_path, the prediction data will be automatically cached to a temporary file.
model_file_path (Union[str, Path, None], optional) – Optional name of the actual model data file, so it does not get copied
predictor_file_path (Union[str, Path, None], optional) – Optional name of the actual predictor data file, so it does not get copied
prediction_file_path (Union[str, Path, None], optional) – Optional name of the actual predictions data file. If not provided but prediction object is given, the data will be automatically cached from the prediction object.
qmd_file (Union[str, Path, None], optional) – Optional path to the Quarto file to use for the health check report. If None, defaults to “HealthCheck.qmd”.
remove_duplicate_html_scripts (bool, default=True) – Whether to remove duplicate script tags from the HTML output to reduce file size. Specifically targets large JavaScript libraries (like Plotly.js) that get embedded multiple times. Only affects HTML output types.
- Returns:
The path to the generated report file.
- Return type:
Path
- Raises:
ValueError – If there’s an error in report generation or invalid parameters.
FileNotFoundError – If required files are not found.
subprocess.SubprocessError – If there’s an error in running external commands.
- excel_report(name: pathlib.Path | str = Path('Tables.xlsx'), predictor_binning: bool = False) tuple[pathlib.Path | None, list[str]]¶
Export raw data to an Excel file.
This method exports the last snapshots of model_data, predictor summary, and optionally predictor_binning data to separate sheets in an Excel file.
If a specific table is not available or too large, it will be skipped without causing the export to fail.
- Parameters:
- Returns:
A tuple containing: - The path to the created Excel file if the export was successful, None if no data was available - A list of warning messages (empty if no warnings)
- Return type: