Skip to content

Commit

Permalink
feat: plotly express
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyot-09 authored and sbrugman committed Jun 27, 2022
1 parent 31e32c3 commit 3aa7c86
Show file tree
Hide file tree
Showing 17 changed files with 326 additions and 375 deletions.
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
15 changes: 13 additions & 2 deletions popmon/pipeline/report_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
show_stats=None,
disable_heatmap=None,
cmap=None,
online_report=None,
**kwargs,
):
"""Example pipeline for comparing test data with itself (full test set)
Expand Down Expand Up @@ -113,6 +114,7 @@ def __init__(
show_stats=show_stats,
disable_heatmap=disable_heatmap,
cmap=cmap,
online_report=online_report,
),
]

Expand All @@ -137,6 +139,7 @@ def __init__(
show_stats=None,
disable_heatmap=None,
cmap=None,
online_report=None,
**kwargs,
):
"""Example pipeline for comparing test data with other (full) external reference set
Expand Down Expand Up @@ -180,6 +183,7 @@ def __init__(
show_stats=show_stats,
disable_heatmap=disable_heatmap,
cmap=cmap,
online_report=online_report,
),
]

Expand All @@ -204,6 +208,7 @@ def __init__(
show_stats=None,
disable_heatmap=None,
cmap=None,
online_report=None,
**kwargs,
):
"""Example pipeline for comparing test data with itself (rolling test set)
Expand Down Expand Up @@ -247,6 +252,7 @@ def __init__(
show_stats=show_stats,
disable_heatmap=disable_heatmap,
cmap=cmap,
online_report=online_report,
),
]

Expand All @@ -270,7 +276,8 @@ def __init__(
report_filepath=None,
show_stats=None,
disable_heatmap=None,
cmap="autumn_r",
cmap=None,
online_report=None,
**kwargs,
):
"""Example pipeline for comparing test data with itself (expanding test set)
Expand Down Expand Up @@ -314,6 +321,7 @@ def __init__(
show_stats=show_stats,
disable_heatmap=disable_heatmap,
cmap=cmap,
online_report=online_report,
),
]

Expand Down Expand Up @@ -342,6 +350,7 @@ def __init__(
plot_hist_n=6,
disable_heatmap=None,
cmap=None,
online_report=None,
):
"""Initialize an instance of Report.
Expand Down Expand Up @@ -431,7 +440,9 @@ def __init__(
**sg_kws,
),
# generate report
ReportGenerator(read_key=sections_key, store_key=store_key),
ReportGenerator(
read_key=sections_key, store_key=store_key, online_report=online_report
),
]
if isinstance(report_filepath, (str, Path)) and len(report_filepath) > 0:
modules.append(FileWriter(store_key, file_path=report_filepath))
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
15 changes: 13 additions & 2 deletions popmon/visualization/alert_section_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ 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,
"types": ["traffic_lights"],
"plots": sorted(plots, key=lambda plot: plot["name"]),
"layout": [""],
}
)

sections.append(
Expand Down Expand Up @@ -237,4 +242,10 @@ def _plot_metric(
skip_empty=skip_empty,
)

return {"name": metric, "description": get_stat_description(metric), "plot": plot}
return {
"name": metric,
"type": "barplot",
"description": get_stat_description(metric),
"plot": plot["data"],
"layout": plot["layout"],
}
152 changes: 0 additions & 152 deletions popmon/visualization/backend.py

This file was deleted.

42 changes: 33 additions & 9 deletions popmon/visualization/histogram_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
hist_name_starts_with="histogram",
description="",
disable_heatmap=None,
cmap="autumn_r",
cmap=None,
):
"""Initialize an instance of SectionGenerator.
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(
self.description = description
self.disable_heatmap = disable_heatmap or []
if cmap is None:
cmap = "autumn_r"
cmap = "ylorrd"
self.cmap = cmap

def get_description(self):
Expand Down Expand Up @@ -143,19 +143,34 @@ def transform(self, data_obj: dict, sections: Optional[list] = None):
]
plots = parallel(_plot_histograms, args)

layouts = []
plot_types = []
# filter out potential empty plots
plots = [e for e in plots if len(e["plot"])]
plots = sorted(plots, key=lambda plot: plot["name"])

if len(plots) > 0:
layouts.append(plots[0]["layout"])
plot_types.append("histogram")
# filter out potential empty heatmap plots, then prepend them to the sorted histograms
hplots = []
for h in heatmaps:
if isinstance(h, dict):
if len(h["plot"]):
hplots.append(h)
plots = hplots + plots

features_w_metrics.append({"name": feature, "plots": plots})
if len(hplots) > 0:
layouts.append(hplots[0]["layout"])
plot_types.append("heatmap")
plots = hplots + plots
# print(plot_types,layouts)
features_w_metrics.append(
{
"name": feature,
"types": plot_types,
"plots": plots,
"layout": layouts,
}
)

sections.append(
{
Expand All @@ -164,6 +179,7 @@ def transform(self, data_obj: dict, sections: Optional[list] = None):
"features": features_w_metrics,
}
)

return sections


Expand Down Expand Up @@ -240,7 +256,13 @@ def _plot_histograms(feature, date, hc_list, hist_names, top_n, max_nbins=1000):
else:
plot = ""

return {"name": date, "description": get_stat_description(date), "plot": plot}
return {
"name": date,
"type": "histogram",
"description": get_stat_description(date),
"plot": plot["data"],
"layout": plot["layout"],
}


def _plot_heatmap(feature, date, hc_list, top_n, disable_heatmap, cmap):
Expand Down Expand Up @@ -339,13 +361,15 @@ def _plot_heatmap(feature, date, hc_list, top_n, disable_heatmap, cmap):
if isinstance(heatmaps, list):
plot = [hist_lookup(heatmaps, hist_name) for hist_name in hist_names]
elif isinstance(heatmaps, dict):
plot = [heatmaps["plot"]]
plot = [heatmaps]

plots = [
{
"name": hist_names_formatted[hist_name],
"type": "heatmap",
"description": get_stat_description(hist_name),
"plot": pl,
"plot": pl["plot"],
"layout": pl["layout"],
"full_width": True,
}
for pl, hist_name in zip(plot, hist_names)
Expand Down Expand Up @@ -382,4 +406,4 @@ def get_top_categories(entries_list, bins, top_n):
def hist_lookup(plot, hist_name):
for pl in plot:
if pl["name"] == hist_name:
return pl["plot"]
return pl
1 change: 1 addition & 0 deletions popmon/visualization/overview_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def _plot_metrics(

return {
"name": "Alert frequency per Feature",
"type": "alert",
"description": "",
"plot": plot,
"full_width": True,
Expand Down
Loading

0 comments on commit 3aa7c86

Please sign in to comment.