Skip to content

Commit

Permalink
refactor: pass settings object to report
Browse files Browse the repository at this point in the history
Co-authored-by: Pradyot Patil <pradyotpatil@gmail.com>
  • Loading branch information
sbrugman and pradyot-09 committed Sep 1, 2022
1 parent 559f0eb commit 29b9e73
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 52 deletions.
26 changes: 13 additions & 13 deletions popmon/notebooks/popmon_tutorial_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,18 @@
"metadata": {},
"outputs": [],
"source": [
"report_settings = Report()\n",
"report_settings.last_n = 0\n",
"report_settings.skip_first_n = 0\n",
"report_settings.skip_last_n = 0\n",
"report_settings.section.histograms.plot_hist_n = 2\n",
"report_settings.skip_empty_plots = True\n",
"report_settings.report_filepath = None\n",
"report_settings = Settings()\n",
"report_settings.report.last_n = 0\n",
"report_settings.report.skip_first_n = 0\n",
"report_settings.report.skip_last_n = 0\n",
"report_settings.report.section.histograms.plot_hist_n = 2\n",
"report_settings.report.skip_empty_plots = True\n",
"report_settings.report.report_filepath = None\n",
"\n",
"report.regenerate(\n",
" store_key=\"html_report\",\n",
" sections_key=\"report_sections\",\n",
" report_settings=report_settings,\n",
" settings=report_settings,\n",
")"
]
},
Expand Down Expand Up @@ -465,12 +465,12 @@
" section_name=\"Profiles\",\n",
" read_key=\"profiles\",\n",
" store_key=\"report_sections\",\n",
" settings=report_settings,\n",
" settings=report_settings.report,\n",
" ),\n",
" ReportGenerator(\n",
" read_key=\"report_sections\",\n",
" store_key=\"html_report\",\n",
" settings=report_settings,\n",
" settings=report_settings.report,\n",
" ),\n",
" ]\n",
" super().__init__(modules)\n",
Expand Down Expand Up @@ -521,18 +521,18 @@
" section_name=\"Profiles\",\n",
" read_key=\"profiles\",\n",
" store_key=\"report_sections\",\n",
" settings=report_settings,\n",
" settings=report_settings.report,\n",
" ),\n",
" SectionGenerator(\n",
" section_name=\"Comparisons\",\n",
" read_key=\"comparisons\",\n",
" store_key=\"report_sections\",\n",
" settings=report_settings,\n",
" settings=report_settings.report,\n",
" ),\n",
" ReportGenerator(\n",
" read_key=\"report_sections\",\n",
" store_key=\"html_report\",\n",
" settings=report_settings,\n",
" settings=report_settings.report,\n",
" ),\n",
" ]\n",
" super().__init__(modules)\n",
Expand Down
10 changes: 5 additions & 5 deletions popmon/notebooks/popmon_tutorial_basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"\n",
"import popmon\n",
"from popmon import resources\n",
"from popmon.config import Report"
"from popmon.config import Settings"
]
},
{
Expand Down Expand Up @@ -151,11 +151,11 @@
},
"outputs": [],
"source": [
"report_settings = Report()\n",
"report_settings.extended_report = False\n",
"report_settings.section.histograms.plot_hist_n = 6\n",
"report_settings = Settings()\n",
"report_settings.report.extended_report = False\n",
"report_settings.report.section.histograms.plot_hist_n = 6\n",
"\n",
"report.regenerate(report_settings=report_settings)"
"report.regenerate(settings=report_settings)"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions popmon/pipeline/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from histogrammar.dfinterface.make_histograms import get_bin_specs, make_histograms

from ..config import Report, Settings
from ..config import Settings
from ..pipeline.dataset_splitter import split_dataset
from ..pipeline.report_pipelines import ReportPipe, get_report_pipeline_class
from ..resources import templates_env
Expand Down Expand Up @@ -277,12 +277,12 @@ def regenerate(
self,
store_key: str = "html_report",
sections_key: str = "report_sections",
report_settings: Report = None,
settings: Settings = None,
):
"""Regenerate HTML report with different plot settings
:param str sections_key: key to store sections data in the datastore. default is 'report_sections'.
:param str store_key: key to store the HTML report data in the datastore. default is 'html_report'
:param Report report_settings: configuration to regenerate the report
:param Settings settings: configuration to regenerate the report
:return HTML: HTML report in an iframe
"""
# basic checks
Expand All @@ -295,12 +295,12 @@ def regenerate(
del self.datastore[sections_key]
if store_key in self.datastore:
del self.datastore[store_key]
if report_settings is None:
report_settings = Report()
if settings is None:
settings = Settings()

pipeline = ReportPipe(
sections_key=sections_key,
settings=report_settings,
settings=settings,
)
result = pipeline.transform(self.datastore)

Expand Down
44 changes: 24 additions & 20 deletions popmon/pipeline/report_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing_extensions import Literal

from ..base import Pipeline
from ..config import Report, Settings
from ..config import Settings
from ..io import FileWriter
from ..pipeline.metrics_pipelines import (
ExpandingReferenceMetricsPipeline,
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(
ReportPipe(
sections_key="report_sections",
store_key="html_report",
settings=settings.report,
settings=settings,
),
]

Expand Down Expand Up @@ -110,7 +110,7 @@ def __init__(
ReportPipe(
sections_key="report_sections",
store_key="html_report",
settings=settings.report,
settings=settings,
),
]

Expand All @@ -136,7 +136,7 @@ def __init__(
ReportPipe(
sections_key="report_sections",
store_key="html_report",
settings=settings.report,
settings=settings,
),
]

Expand All @@ -162,7 +162,7 @@ def __init__(
ReportPipe(
sections_key="report_sections",
store_key="html_report",
settings=settings.report,
settings=settings,
),
]

Expand All @@ -174,12 +174,13 @@ class ReportPipe(Pipeline):

def __init__(
self,
settings: Report,
settings: Settings,
sections_key: str = "report_sections",
store_key: str = "html_report",
):
"""Initialize an instance of Report.
:param Settings settings: the configuration object
:param str sections_key: key to store sections data in the datastore
:param str store_key: key to store the HTML report data in the datastore
"""
Expand All @@ -189,59 +190,62 @@ def __init__(
OverviewSectionGenerator(
read_key="traffic_lights",
store_key=sections_key,
settings=settings,
settings=settings.report,
),
# generate section with histogram
HistogramSection(
read_key="split_hists",
store_key=sections_key,
hist_name_starts_with="histogram",
settings=settings.section.histograms,
reference_type=settings.reference_type,
settings=settings.report.section.histograms,
),
# section showing all traffic light alerts of monitored statistics
TrafficLightSectionGenerator(
read_key="traffic_lights",
store_key=sections_key,
settings=settings,
settings=settings.report,
),
# section with a summary of traffic light alerts
AlertSectionGenerator(
read_key="alerts",
store_key=sections_key,
settings=settings,
settings=settings.report,
),
# section of histogram and pull comparison statistics
SectionGenerator(
dynamic_bounds="dynamic_bounds_comparisons",
static_bounds="static_bounds_comparisons",
section_name=settings.section.comparisons.name,
section_name=settings.report.section.comparisons.name,
ignore_stat_endswith=["_mean", "_std", "_pull"],
read_key="comparisons",
description=settings.section.comparisons.description,
description=settings.report.section.comparisons.description,
store_key=sections_key,
settings=settings,
settings=settings.report,
),
# section of profiled statistics with dynamic or static traffic light bounds
SectionGenerator(
dynamic_bounds="dynamic_bounds",
section_name=settings.section.profiles.name,
section_name=settings.report.section.profiles.name,
static_bounds="static_bounds",
ignore_stat_endswith=["_mean", "_std", "_pull"],
read_key="profiles",
description=settings.section.profiles.description,
description=settings.report.section.profiles.description,
store_key=sections_key,
settings=settings,
settings=settings.report,
),
# generate report
ReportGenerator(
read_key=sections_key, store_key=store_key, settings=settings
read_key=sections_key, store_key=store_key, settings=settings.report
),
]
if (
isinstance(settings.report_filepath, (str, Path))
and len(settings.report_filepath) > 0
isinstance(settings.report.report_filepath, (str, Path))
and len(settings.report.report_filepath) > 0
):
modules.append(FileWriter(store_key, file_path=settings.report_filepath))
modules.append(
FileWriter(store_key, file_path=settings.report.report_filepath)
)

super().__init__(modules=modules)

Expand Down
2 changes: 2 additions & 0 deletions popmon/visualization/histogram_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
self,
read_key,
store_key,
reference_type: str,
settings: HistogramSectionModel,
features=None,
ignore_features=None,
Expand All @@ -64,6 +65,7 @@ def __init__(
super().__init__()
self.read_key = read_key
self.store_key = store_key
self.reference_type = reference_type

self.features = features or []
self.ignore_features = ignore_features or []
Expand Down
16 changes: 8 additions & 8 deletions tests/popmon/pipeline/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from popmon import resources
from popmon.base import Pipeline
from popmon.config import Report, Settings
from popmon.config import Settings
from popmon.hist.filling import get_bin_specs
from popmon.io import JsonReader
from popmon.pipeline.report import df_stability_report, stability_report
Expand Down Expand Up @@ -55,17 +55,17 @@ def test_df_stability_report():
bin_specs=bin_specs,
)

settings = Report()
settings.last_n = 4
settings = Settings()
settings.report.last_n = 4

# regenerate report, changing the plot window settings
rep.regenerate(report_settings=settings)
rep.regenerate(settings=settings)

settings.last_n = 0
settings.skip_first_n = 1
settings.skip_last_n = 1
settings.report.last_n = 0
settings.report.skip_first_n = 1
settings.report.skip_last_n = 1

rep.regenerate(report_settings=settings)
rep.regenerate(settings=settings)


def test_df_stability_report_self():
Expand Down

0 comments on commit 29b9e73

Please sign in to comment.