Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robyn one pager end to end flow for tutorial 1 #1160

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions python/src/robyn/reporting/onepager_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down
32 changes: 18 additions & 14 deletions python/src/robyn/robyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
46 changes: 28 additions & 18 deletions python/src/robyn/tutorials/tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down