diff --git a/python/pdstools/app/decision_analyzer/pages/10_Business_Value_Analysis.py b/python/pdstools/app/decision_analyzer/pages/10_Business_Value_Analysis.py index 35a85c72..d5f56ecd 100644 --- a/python/pdstools/app/decision_analyzer/pages/10_Business_Value_Analysis.py +++ b/python/pdstools/app/decision_analyzer/pages/10_Business_Value_Analysis.py @@ -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, +# ) diff --git a/python/pdstools/app/decision_analyzer/pages/11_Business_Lever_Analysis.py b/python/pdstools/app/decision_analyzer/pages/11_Business_Lever_Analysis.py index b9523beb..3020e087 100644 --- a/python/pdstools/app/decision_analyzer/pages/11_Business_Lever_Analysis.py +++ b/python/pdstools/app/decision_analyzer/pages/11_Business_Lever_Analysis.py @@ -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) diff --git a/python/pdstools/app/decision_analyzer/pages/4_Action_Funnel.py b/python/pdstools/app/decision_analyzer/pages/4_Action_Funnel.py index 93fde563..92730742 100644 --- a/python/pdstools/app/decision_analyzer/pages/4_Action_Funnel.py +++ b/python/pdstools/app/decision_analyzer/pages/4_Action_Funnel.py @@ -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() diff --git a/python/pdstools/app/decision_analyzer/pages/8_Offer_Quality_Analysis.py b/python/pdstools/app/decision_analyzer/pages/8_Offer_Quality_Analysis.py index 07db5069..5d37cb50 100644 --- a/python/pdstools/app/decision_analyzer/pages/8_Offer_Quality_Analysis.py +++ b/python/pdstools/app/decision_analyzer/pages/8_Offer_Quality_Analysis.py @@ -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, ) diff --git a/python/pdstools/app/decision_analyzer/pages/9_Thresholding_Analysis.py b/python/pdstools/app/decision_analyzer/pages/9_Thresholding_Analysis.py index 6bcd938b..edf87779 100644 --- a/python/pdstools/app/decision_analyzer/pages/9_Thresholding_Analysis.py +++ b/python/pdstools/app/decision_analyzer/pages/9_Thresholding_Analysis.py @@ -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 @@ -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, ) @@ -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, ) ) diff --git a/python/pdstools/decision_analyzer/decision_data.py b/python/pdstools/decision_analyzer/decision_data.py index 71b1a6b9..1664728a 100644 --- a/python/pdstools/decision_analyzer/decision_data.py +++ b/python/pdstools/decision_analyzer/decision_data.py @@ -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", diff --git a/python/pdstools/decision_analyzer/plots.py b/python/pdstools/decision_analyzer/plots.py index 0ba0d41f..50e5c856 100644 --- a/python/pdstools/decision_analyzer/plots.py +++ b/python/pdstools/decision_analyzer/plots.py @@ -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 @@ -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 @@ -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], diff --git a/python/pdstools/decision_analyzer/table_definition.py b/python/pdstools/decision_analyzer/table_definition.py index 57ae6bbb..bd5f30a3 100644 --- a/python/pdstools/decision_analyzer/table_definition.py +++ b/python/pdstools/decision_analyzer/table_definition.py @@ -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",