Skip to content

Commit

Permalink
Merge pull request #300 from pegasystems/decision_analyzer
Browse files Browse the repository at this point in the history
Update Experimental Charts for Compatibility with New DA Version
  • Loading branch information
yusufuyanik1 authored Dec 16, 2024
2 parents 4431274 + 6279aed commit d875019
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
import polars as pl
import streamlit as st

from da_streamlit_utils import get_current_scope_index, st_value_distribution
from utils import NBADScope_Mapping, ensure_data

# TODO Finish up to show effect on proposition distribution (side to side)

"# Business Value Analysis"

"""
A closer look at the values associated with actions.
* Is my value distribution very skewed? Are there actions with significantly different values than the others?
* What's the range of the values?
"""
ensure_data()
st.warning(
"Current sample data action values are artificial so the analysis is just an example."
)

st.session_state["sidebar"] = st.sidebar

scope_options = st.session_state.decision_data.getPossibleScopeValues()
if "scope" not in st.session_state:
st.session_state.scope = scope_options[0]

valueData = st.session_state.decision_data.getValueDistributionData()

with st.container(border=True):
st.plotly_chart(
st_value_distribution(valueData, st.session_state.scope),
use_container_width=True,
)

scope_index = get_current_scope_index(scope_options)
st.selectbox(
"Granularity:",
options=scope_options,
format_func=lambda option: NBADScope_Mapping[option],
index=scope_index,
key="scope",
)

"Actions having different values:"

st.dataframe(
valueData.filter(pl.col("Value_min") != pl.col("Value_max")).collect(),
hide_index=True,
column_config=NBADScope_Mapping,
"In maintenance!!, please see: https://streamlit-dev.dsmcloud.io/Business%20Value%20Analysis for the older version. If the link doesn't work, contact Yusuf Uyanik."
)
# import polars as pl
# import streamlit as st

# from da_streamlit_utils import (
# get_current_scope_index,
# st_value_distribution,
# ensure_data,
# )
# from pdstools.decision_analyzer.utils import NBADScope_Mapping

# # TODO Finish up to show effect on proposition distribution (side to side)

# "# Business Value Analysis"

# """
# A closer look at the values associated with actions.

# * Is my value distribution very skewed? Are there actions with significantly different values than the others?
# * What's the range of the values?

# """
# ensure_data()
# st.warning(
# "Current sample data action values are artificial so the analysis is just an example."
# )

# st.session_state["sidebar"] = st.sidebar

# scope_options = st.session_state.decision_data.getPossibleScopeValues()
# if "scope" not in st.session_state:
# st.session_state.scope = scope_options[0]

# valueData = st.session_state.decision_data.getValueDistributionData()

# with st.container(border=True):
# st.plotly_chart(
# st_value_distribution(valueData, st.session_state.scope),
# use_container_width=True,
# )

# scope_index = get_current_scope_index(scope_options)
# st.selectbox(
# "Granularity:",
# options=scope_options,
# format_func=lambda option: NBADScope_Mapping[option],
# index=scope_index,
# key="scope",
# )

# "Actions having different values:"

# st.dataframe(
# valueData.filter(pl.col("Value_min") != pl.col("Value_max")).collect(),
# hide_index=True,
# column_config=NBADScope_Mapping,
# )
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import polars as pl
import streamlit as st

from utils import ensure_data, find_lever_value
from da_streamlit_utils import (
ensure_data,
)
from pdstools.decision_analyzer.utils import find_lever_value

# TODO not so sure what to do with this tool - maybe generalize to work across a selection not just a single action and figure out a multiplier
# TODO but do show the effect of levering right away (distributions side to side) just like we should do in the thresholding analysis (share code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
st.session_state["sidebar"] = st.sidebar
if "local_filters" in st.session_state:
del st.session_state["local_filters"]

with st.session_state["sidebar"]:
scope_options = st.session_state.decision_data.getPossibleScopeValues()
stage_options = st.session_state.decision_data.getPossibleStageValues()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import streamlit as st

from plots import getTrendChart, offer_quality_piecharts
from pdstools.decision_analyzer.plots import getTrendChart, offer_quality_piecharts
from da_streamlit_utils import (
get_current_scope_index,
get_current_stage_index,
ensure_data,
)
from utils import (
from pdstools.decision_analyzer.utils import (
NBADScope_Mapping,
ensure_data,
filtered_action_counts,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import polars as pl
import streamlit as st

from plots import distribution, threshold_deciles
from utils import ensure_data
from da_streamlit_utils import ensure_data

# TODO Interactive Thresholding isn't working properly yet. Also show the total numbers.
# TODO Instead of priority/propensity side to side have a drop-down to select which property to show
Expand Down Expand Up @@ -80,7 +79,9 @@
# st.dataframe(plotData)

st.plotly_chart(
threshold_deciles(threshold_deciles_data, thresholding_mapping[thresholding_on]),
st.session_state.decision_data.plot.threshold_deciles(
thresholding_on, thresholding_mapping[thresholding_on]
),
use_container_width=True,
)

Expand All @@ -98,13 +99,11 @@
), # Hmm, probalby not the right way
# additional_filters=((pl.col(thresholding_on).list.eval(pl.element() > current_threshold)).list.any()),
)
# st.write(xxx.head().collect())
st.write(
distribution(
st.session_state.decision_data.plot.distribution(
xxx,
scope="pyIssue",
breakdown="pyGroup",
title="Effect of Thresholding",
horizontal=True,
)
)
2 changes: 1 addition & 1 deletion python/pdstools/decision_analyzer/decision_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, raw_data: pl.LazyFrame):
"pyIssue",
"pyGroup",
"pyName",
# "pyTreatment", # should be in there dependent on what's in the data
"pyTreatment", # should be in there dependent on what's in the data
"pyChannel",
"pyDirection",
"pxComponentName",
Expand Down
13 changes: 9 additions & 4 deletions python/pdstools/decision_analyzer/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Plot:
def __init__(self, decision_data):
self._decision_data = decision_data

def threshold_deciles(self, thresholding_name, return_df=False):
df = self._decision_data.whatever_preprocessing
def threshold_deciles(self, thresholding_on, thresholding_name, return_df=False):
df = self._decision_data.getThresholdingData(thresholding_on)
if return_df:
return df

Expand Down Expand Up @@ -590,12 +590,17 @@ def offer_quality_piecharts(
"only_irrelevant_actions",
"has_no_offers",
]
df = (
all_frames = (
df.group_by("pxEngagementStage")
.agg(pl.sum(value_finder_names))
.collect()
.partition_by("pxEngagementStage", as_dict=True)
)
# TODO Temporary solution to fit the pie charts into the screen, pick only first 5 stages
df = {}
NBADStages_FilterView = NBADStages_FilterView[:5]
for stage in NBADStages_FilterView[:5]:
df[(stage,)] = all_frames[(stage,)]
if return_df:
return df

Expand All @@ -608,7 +613,7 @@ def offer_quality_piecharts(
)

for i, stage in enumerate(NBADStages_FilterView):
plotdf = df[stage].drop("pxEngagementStage")
plotdf = df[(stage,)].drop("pxEngagementStage")
fig.add_trace(
go.Pie(
values=list(plotdf.to_numpy())[0],
Expand Down
4 changes: 0 additions & 4 deletions python/pdstools/decision_analyzer/table_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,6 @@ class TableConfig(TypedDict):
"Arbitration.TopSelection",
"TreatmentPlacements",
"Channels.ExtensionPoint",
"Channels.ExtensionPoint",
"Channels.ExtensionPoint",
"Channels.ExtensionPoint",
"Channels.ExtensionPoint",
"ContactPolicies.ChannelLimits",
"ContactPolicies.ExtensionPoint",
"FinalLimitsAndBundlingPostExtensionPoint",
Expand Down

0 comments on commit d875019

Please sign in to comment.