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

Interactive plots in report #225

Merged
merged 5 commits into from
Jul 5, 2022
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
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# pyyaml: https://github.com/yaml/pyyaml/blob/master/LICENSE
# jinja2: https://github.com/noirbizarre/jinja2/blob/master/LICENSE
# tqdm: https://github.com/tqdm/tqdm/blob/master/LICENCE
# matplotlib: https://github.com/matplotlib/matplotlib/blob/master/LICENSE/LICENSE
# plotly: https://github.com/plotly/plotly.py/blob/master/LICENSE.txt
# joblib: https://github.com/joblib/joblib/blob/master/LICENSE.txt
# pybase64: https://github.com/mayeut/pybase64/blob/master/LICENSE
# htmlmin: https://github.com/mankyd/htmlmin/blob/master/LICENSE
Expand Down
8 changes: 0 additions & 8 deletions docs/source/popmon.visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ popmon.visualization.alert\_section\_generator module
:undoc-members:
:show-inheritance:

popmon.visualization.backend module
-----------------------------------

.. automodule:: popmon.visualization.backend
:members:
:undoc-members:
:show-inheritance:

popmon.visualization.histogram\_section module
----------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions examples/flight_delays.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Configuration of the monitoring rules and report
settings = Settings(time_axis="DATE", reference_type="self")
settings.report.extended_report = False
settings.report.title += " | Flight Delays Dataset"
settings.monitoring.pull_rules = {"*_pull": [10, 7, -7, -10]}

# generate stability report using automatic binning of all encountered features
Expand Down
10 changes: 8 additions & 2 deletions examples/synthetic_data.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import pandas as pd

import popmon # noqa
from popmon import resources
from popmon import Settings, resources

# open synthetic data
df = pd.read_csv(resources.data("test.csv.gz"), parse_dates=["date"])

# report configuration
settings = Settings(
features=["date:age", "date:gender", "date:isActive", "date:eyeColor"]
)
settings.report.title += " | Synthetic Dataset"

# generate stability report using automatic binning of all encountered features
# (importing popmon automatically adds this functionality to a dataframe)
report = df.pm_stability_report(
time_axis="date",
time_width="2w",
features=["date:age", "date:gender", "date:isActive", "date:eyeColor"],
settings=settings,
)

# or save the report to file
Expand Down
21 changes: 17 additions & 4 deletions popmon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
# (see https://joblib.readthedocs.io/en/latest/generated/joblib.Parallel.html for details)
parallel_args = {"n_jobs": 1}

# Usage the `ing_matplotlib_theme`
themed = True


class SectionModel(BaseModel):
name: str
Expand Down Expand Up @@ -108,7 +105,7 @@ class HistogramSectionModel(SectionModel):
top_n: int = 20
"""plot heatmap for top 'n' categories. default is 20 (optional)"""

cmap: str = "autumn_r"
cmap: str = "ylorrd"
"""colormap for histogram heatmaps"""


Expand Down Expand Up @@ -152,6 +149,9 @@ class Section(BaseModel):
class Report(BaseModel):
"""Report-specific configuration"""

title = "POPMON Report"
"""Report title in browser and navbar. May contain HTML."""

skip_empty_plots: bool = True
"""if false, also show empty plots in report with only nans or zeroes (optional)"""

Expand All @@ -171,6 +171,9 @@ class Report(BaseModel):
"""if True, show all the generated statistics in the report (optional)
if set to False, then smaller show_stats (see below)"""

online_report: bool = True
"""Use a CDN to host resources, or embed them into the report."""

show_stats: List[str] = [
"distinct*",
"filled*",
Expand All @@ -194,6 +197,16 @@ class Report(BaseModel):
]
"""list of statistic name patterns to show in the report. If None, show all (optional)"""

primary_color = "#000080"
"""Primary color used throughout the report"""

tl_colors: Dict[str, str] = {
"green": "#008000",
"yellow": "#FFC800",
"red": "#FF0000",
}
""""Configure line colors in barplots of Comparisons and Profiles section. Need to be hex format (full length)"""

section: Section = Section()
"""Configuration for the individual sections"""

Expand Down
12 changes: 10 additions & 2 deletions popmon/notebooks/popmon_tutorial_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,11 @@
" store_key=\"report_sections\",\n",
" settings=report_settings,\n",
" ),\n",
" ReportGenerator(read_key=\"report_sections\", store_key=\"html_report\"),\n",
" ReportGenerator(\n",
" read_key=\"report_sections\",\n",
" store_key=\"html_report\",\n",
" settings=report_settings,\n",
" ),\n",
" ]\n",
" super().__init__(modules)\n",
"\n",
Expand Down Expand Up @@ -525,7 +529,11 @@
" store_key=\"report_sections\",\n",
" settings=report_settings,\n",
" ),\n",
" ReportGenerator(read_key=\"report_sections\", store_key=\"html_report\"),\n",
" ReportGenerator(\n",
" read_key=\"report_sections\",\n",
" store_key=\"html_report\",\n",
" settings=report_settings,\n",
" ),\n",
" ]\n",
" super().__init__(modules)\n",
"\n",
Expand Down
4 changes: 3 additions & 1 deletion popmon/pipeline/report_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ def __init__(
settings=settings,
),
# generate report
ReportGenerator(read_key=sections_key, store_key=store_key),
ReportGenerator(
read_key=sections_key, store_key=store_key, settings=settings
),
]
if (
isinstance(settings.report_filepath, (str, Path))
Expand Down
27 changes: 26 additions & 1 deletion popmon/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


# Resources lookup file for popmon

import json
import pathlib

from jinja2 import Environment, FileSystemLoader
Expand Down Expand Up @@ -53,6 +53,31 @@
_TEMPLATES_ENV.filters["fmt_metric"] = lambda x: x.replace("_", " ")


def js_list(encoder, data):
pairs = [js_val(encoder, v) for v in data]
return "[" + ", ".join(pairs) + "]"


def js_dict(encoder, data):
pairs = [k + ": " + js_val(encoder, v) for k, v in data.items()]
return "{" + ", ".join(pairs) + "}"


def js_val(encoder, data):
if isinstance(data, dict):
val = js_dict(encoder, data)
elif isinstance(data, list):
val = js_list(encoder, data)
else:
val = encoder.encode(data)
return val


_TEMPLATES_ENV.filters["json_plot"] = lambda x: js_val(
json.JSONEncoder(ensure_ascii=False), x
)


def _resource(resource_type, name: str) -> str:
"""Return the full path filename of a resource.

Expand Down
7 changes: 0 additions & 7 deletions popmon/visualization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
TrafficLightSectionGenerator,
)

# set matplotlib backend to batch mode when running in shell
# need to do this *before* matplotlib.pyplot gets imported
from ..visualization.backend import set_matplotlib_backend

set_matplotlib_backend()


__all__ = [
"SectionGenerator",
"HistogramSection",
Expand Down
8 changes: 7 additions & 1 deletion popmon/visualization/alert_section_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(
self.section_name = settings.section.alerts.name
self.description = settings.section.alerts.description
self.descriptions = settings.section.alerts.descriptions
self.tl_colors = settings.tl_colors

def get_description(self):
return self.section_name
Expand Down Expand Up @@ -141,6 +142,7 @@ def transform(
0,
0,
0,
self.tl_colors,
style="alerts",
)
]
Expand All @@ -150,7 +152,11 @@ def transform(
plots = [e for e in plots if len(e["plot"])]

features_w_metrics.append(
{"name": feature, "plots": sorted(plots, key=lambda plot: plot["name"])}
{
"name": feature,
"plot_type_layouts": {"traffic_lights": ""},
"plots": sorted(plots, key=lambda plot: plot["name"]),
}
)

sections.append(
Expand Down
152 changes: 0 additions & 152 deletions popmon/visualization/backend.py

This file was deleted.

Loading