Skip to content

Commit

Permalink
fix experimental charts in DA.
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufuyanik1 committed Dec 16, 2024
1 parent d91aa2d commit c4fff59
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 66 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
4 changes: 2 additions & 2 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
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 c4fff59

Please sign in to comment.