Skip to content

Commit

Permalink
Quick fix for standard GT reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
operdeck committed Dec 8, 2024
1 parent 716f28c commit 9fa2777
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions python/pdstools/adm/CDH_Guidelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"Engagement Lift": [0.0, 0.2, 2.0, None],
"Responses": [1.0, 200, None, None],
"Positive Responses": [1.0, 200, None, None],
"Engagement Lift": [0.0, 1.0, None, None],
}

_pega_cloud_limits = pl.DataFrame(data=_data).transpose(include_header=True)
Expand Down
7 changes: 2 additions & 5 deletions python/pdstools/reports/HealthCheck.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ except Exception as e:
report_utils.quarto_plot_exception("Prediction Trend Charts", e)
```

:::

# Overview of the Actions
Expand Down Expand Up @@ -1057,8 +1056,7 @@ This analysis looks at the predictors that are driving the models.
However, Predictor Data is **not available**. Predictor analysis is not available.
:::

::: {.content-hidden unless-meta="analysis.predictors"}

::::::: {.content-hidden unless-meta="analysis.predictors"}
```{python}
# | output: asis
# | echo: false
Expand Down Expand Up @@ -1488,8 +1486,7 @@ else:
report_utils.quarto_callout_no_predictor_data_warning()
```

:::
:::::::

# Responses

Expand Down
39 changes: 24 additions & 15 deletions python/pdstools/utils/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from ..utils.show_versions import show_versions
from ..adm.Reports import Reports
import polars as pl
import re
import subprocess
import datetime


Expand Down Expand Up @@ -36,7 +34,8 @@ def quarto_callout_important(info):
% info
)

def quarto_plot_exception(plot_name:str, e:Exception):

def quarto_plot_exception(plot_name: str, e: Exception):
quarto_print(
"""
::: {.callout-important collapse="true"}
Expand All @@ -48,12 +47,15 @@ def quarto_plot_exception(plot_name:str, e:Exception):
% (plot_name, e, traceback.format_exc())
)


def quarto_callout_no_prediction_data_warning(extra=""):
quarto_callout_important(f"Prediction Data is not available. {extra}")


def quarto_callout_no_predictor_data_warning(extra=""):
quarto_callout_important(f"Predictor Data is not available. {extra}")


def polars_col_exists(df, col):
return col in df.collect_schema().names() and df.schema[col] != pl.Null

Expand All @@ -69,9 +71,11 @@ def table_standard_formatting(
rowname_col=None,
groupname_col=None,
cdh_guidelines=CDHGuidelines(),
# TODO generalize highlight_lims so the dict can als be List[str] to str
highlight_limits: Dict[str, str] = {},
highlight_lists: Dict[str, List[str]] = {},
highlight_configurations: List[str] = [],
color_styler=style.fill
):
def apply_metric_style(gt, col_name, metric):
if col_name in source_table.collect_schema().names():
Expand All @@ -84,26 +88,30 @@ def apply_metric_style(gt, col_name, metric):
bad_rows = [
i
for i, v in enumerate(values)
if v < min_val or (max_val is not None and v > max_val)
if (v is not None and min_val is not None and v < min_val)
or (v is not None and max_val is not None and v > max_val)
]
warning_rows = [
i
for i, v in enumerate(values)
if (v >= min_val and v < best_practice_min)
if (v is not None and v >= min_val and v < best_practice_min)
or (
best_practice_max is not None
and max_val is not None
and v is not None
and v > best_practice_max
and v <= max_val
)
]
# TODO consider that bad / warning rows are exclusive
# TODO consider adding an optional "good" color

gt = gt.tab_style(
style=style.fill(color="orangered"),
style=color_styler(color="orangered"),
locations=loc.body(columns=col_name, rows=bad_rows),
)
gt = gt.tab_style(
style=style.fill(color="orange"),
style=color_styler(color="orange"),
locations=loc.body(columns=col_name, rows=warning_rows),
)
return gt
Expand All @@ -115,7 +123,7 @@ def apply_standard_name_style(gt, col_name, standard_list):
i for i, v in enumerate(values) if v not in standard_list
]
gt = gt.tab_style(
style=style.fill(color="yellow"),
style=color_styler(color="yellow"),
locations=loc.body(columns=col_name, rows=non_standard_rows),
)
return gt
Expand All @@ -125,7 +133,7 @@ def apply_configuration_style(gt, col_name):
values = source_table[col_name].to_list()
multiple_config_rows = [i for i, v in enumerate(values) if v.count(",") > 1]
gt = gt.tab_style(
style=style.fill(color="yellow"),
style=color_styler(color="yellow"),
locations=loc.body(columns=col_name, rows=multiple_config_rows),
)
return gt
Expand All @@ -152,16 +160,16 @@ def apply_configuration_style(gt, col_name):
return gt


def table_style_predictor_count(gt: GT, flds, cdh_guidelines=CDHGuidelines()):
def table_style_predictor_count(gt: GT, flds, cdh_guidelines=CDHGuidelines(), color_styler=style.fill):
for col in flds:
gt = gt.tab_style(
style=style.fill(color="orange"),
style=color_styler(color="orange"),
locations=loc.body(
columns=col,
rows=(pl.col(col) < 200) | (pl.col(col) > 700) & (pl.col(col) > 0),
),
).tab_style(
style=style.fill(color="orangered"),
style=color_styler(color="orangered"),
locations=loc.body(
columns=col,
rows=(pl.col(col) == 0),
Expand Down Expand Up @@ -237,6 +245,7 @@ def sample_values(dm, all_dm_cols, fld, n=6):
.to_list()[:n]
)


def show_credits(quarto_source: str):
_, quarto_version = Reports.get_quarto_with_version(verbose=False)
_, pandoc_version = Reports.get_pandoc_with_version(verbose=False)
Expand All @@ -260,6 +269,6 @@ def show_credits(quarto_source: str):

show_versions()

quarto_print("For more information please see the [Pega Data Scientist Tools](https://github.com/pegasystems/pega-datascientist-tools).")


quarto_print(
"For more information please see the [Pega Data Scientist Tools](https://github.com/pegasystems/pega-datascientist-tools)."
)

0 comments on commit 9fa2777

Please sign in to comment.