diff --git a/python/src/robyn/reporting/onepager_reporting.py b/python/src/robyn/reporting/onepager_reporting.py index 01281758b..057fe6915 100644 --- a/python/src/robyn/reporting/onepager_reporting.py +++ b/python/src/robyn/reporting/onepager_reporting.py @@ -219,27 +219,27 @@ def _add_title_and_metrics(self, fig: plt.Figure, solution_id: str) -> None: """Add title and metrics text to the figure.""" try: model_info = self._get_model_info(solution_id) - metrics_text = model_info.get('formatted_text', '') - + metrics_text = model_info.get("formatted_text", "") + # Add title with larger font and bold fig.suptitle( f"MMM Analysis One-Pager for Model: {solution_id}", - fontsize=24, # Increased from 18 + fontsize=24, # Increased from 18 y=0.98, - weight='bold', # Makes the text bold - fontfamily='sans-serif' # Clear font family + weight="bold", # Makes the text bold + fontfamily="sans-serif", # Clear font family ) - + # Add metrics text if available if metrics_text: fig.text( - 0.5, # Center horizontally - 0.955, # Position below title + 0.5, # Center horizontally + 0.955, # Position below title metrics_text, fontsize=16, # Increased from 14 - ha='center', - va='top', - weight='bold' # Also make metrics bold + ha="center", + va="top", + weight="bold", # Also make metrics bold ) except Exception as e: logger.error(f"Error adding title and metrics: {str(e)}") @@ -248,8 +248,8 @@ def _add_title_and_metrics(self, fig: plt.Figure, solution_id: str) -> None: f"MMM Analysis One-Pager for Model: {solution_id}", fontsize=24, y=0.98, - weight='bold', - fontfamily='sans-serif' + weight="bold", + fontfamily="sans-serif", ) def _generate_solution_plots( @@ -387,7 +387,7 @@ def _generate_solution_plots( def generate_one_pager( self, solution_ids: Union[str, List[str]] = "all", - plots: Optional[List[str]] = None, + plots: Optional[List[PlotType]] = None, # Changed from List[str] figsize: tuple = (30, 34), save_path: Optional[str] = None, top_pareto: bool = False, @@ -404,6 +404,13 @@ def generate_one_pager( Returns: List[plt.Figure]: List of generated figures, one per solution """ + # Convert string plot types to PlotType if necessary + if plots and isinstance(plots[0], str): + try: + plots = [PlotType[plot.upper()] for plot in plots] + except KeyError as e: + raise ValueError(f"Invalid plot type: {e}") + # Use default plots if none provided plots = plots or self.default_plots diff --git a/python/src/robyn/robyn.py b/python/src/robyn/robyn.py index 3f8df4d67..cbc9da2d5 100644 --- a/python/src/robyn/robyn.py +++ b/python/src/robyn/robyn.py @@ -5,6 +5,8 @@ from pathlib import Path from typing import Dict, Optional, List import numpy as np +from robyn.modeling.entities.clustering_results import ClusteredResult +from robyn.data.entities.enums import AdstockType, PlotType from robyn.data.entities.mmmdata import MMMData from robyn.data.entities.holidays_data import HolidaysData from robyn.data.entities.hyperparameters import Hyperparameters @@ -398,29 +400,31 @@ def optimize_budget( logger.error("Budget optimization failed: %s", str(e)) raise - @staticmethod - def generate_one_pager( - pareto_result: ParetoResult, - cluster_result: Optional[ClusteringConfig] = None, - mmm_data: Optional[MMMData] = None, - plots: Optional[List[str]] = None, - ) -> None: + def generate_one_pager(self, solution_id: Optional[str] = None) -> None: """ Generate one-page summary report. Args: - pareto_result: Pareto optimization results - cluster_result: Optional clustering results - mmm_data: Optional MMM data for additional context plots: Optional list of specific plots to include + solution_id: Optional specific solution ID to plot """ try: onepager = OnePager( - pareto_result=pareto_result, - clustered_result=cluster_result, - mmm_data=mmm_data, + pareto_result=self.pareto_result, + clustered_result=self.cluster_result, + adstock=self.hyperparameters.adstock, + mmm_data=self.mmm_data, + holidays_data=self.holidays_data, + ) + + # Set top_pareto based on whether solution_id is provided + top_pareto = solution_id is None + + figures = onepager.generate_one_pager( + solution_ids=solution_id if solution_id else "all", + top_pareto=top_pareto, ) - onepager.generate_one_pager(plots=plots) + return figures except Exception as e: logging.error("One-pager generation failed: %s", str(e)) diff --git a/python/src/robyn/tutorials/tutorial1.ipynb b/python/src/robyn/tutorials/tutorial1.ipynb index b568d393f..2b0e73e57 100644 --- a/python/src/robyn/tutorials/tutorial1.ipynb +++ b/python/src/robyn/tutorials/tutorial1.ipynb @@ -272,6 +272,34 @@ "robyn.evaluate_models(cluster_config=configs)" ] }, + { + "cell_type": "markdown", + "id": "7cebb194", + "metadata": {}, + "source": [ + "## Robyn One Pager Report" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0f68f80", + "metadata": {}, + "outputs": [], + "source": [ + "robyn.generate_one_pager()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ed54130", + "metadata": {}, + "outputs": [], + "source": [ + "robyn.generate_one_pager(solution_id=\"1_4_1\")" + ] + }, { "cell_type": "markdown", "id": "8ede6c0d", @@ -342,24 +370,6 @@ "# Display the allocation result\n", "print(allocation_result)" ] - }, - { - "cell_type": "markdown", - "id": "6e68b36c", - "metadata": {}, - "source": [ - "## Robyn One Pager Report" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cf46898f", - "metadata": {}, - "outputs": [], - "source": [ - "# robyn.generate_one_pager()" - ] } ], "metadata": {