Samkeet-Blend360 commited on
Commit ·
ae88a56
1
Parent(s): e8d72c9
Response Curve
Browse files
__pycache__/response_curves_model_quality.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/response_curves_model_quality.cpython-310.pyc and b/__pycache__/response_curves_model_quality.cpython-310.pyc differ
|
|
|
pages/2_Scenario_Planner.py
CHANGED
|
@@ -2028,7 +2028,7 @@ if auth_status == True:
|
|
| 2028 |
st.markdown(
|
| 2029 |
"""<hr class="spends-heading-seperator">""", unsafe_allow_html=True
|
| 2030 |
)
|
| 2031 |
-
_columns = st.columns((
|
| 2032 |
with _columns[0]:
|
| 2033 |
generate_spending_header("Channel")
|
| 2034 |
with _columns[1]:
|
|
@@ -2068,7 +2068,7 @@ if auth_status == True:
|
|
| 2068 |
# st.write(st.session_state["scenario"].channels[channel_name].bounds)
|
| 2069 |
# st.write(st.session_state["scenario"].channels[channel_name].channel_bounds_min)
|
| 2070 |
|
| 2071 |
-
_columns = st.columns((
|
| 2072 |
response_curve_params = pd.read_excel(
|
| 2073 |
"response_curves_parameters.xlsx", index_col="channel"
|
| 2074 |
)
|
|
@@ -2099,7 +2099,7 @@ if auth_status == True:
|
|
| 2099 |
### # # print(st.session_state[channel_name])
|
| 2100 |
# st.write(_channel_class.channel_bounds_min,channel_bounds_min)
|
| 2101 |
# st.write(_channel_class.channel_bounds_max,channel_bounds_max)
|
| 2102 |
-
_columns_min = st.columns(
|
| 2103 |
with _columns_min[0]:
|
| 2104 |
spend_input = st.text_input(
|
| 2105 |
"Absolute",
|
|
@@ -2135,7 +2135,7 @@ if auth_status == True:
|
|
| 2135 |
return float(st.session_state[channel_name_upper_bound])
|
| 2136 |
|
| 2137 |
channel_name_current = f"{channel_name}_change"
|
| 2138 |
-
with _columns_min[
|
| 2139 |
channel_name_upper_bound = f"{channel_name}_upper_bound"
|
| 2140 |
if channel_name_upper_bound not in st.session_state:
|
| 2141 |
st.session_state[channel_name_upper_bound] = str(100)
|
|
@@ -2187,7 +2187,7 @@ if auth_status == True:
|
|
| 2187 |
with _spend_cols[0]:
|
| 2188 |
# st.write("Actual")
|
| 2189 |
st.markdown(
|
| 2190 |
-
f"<p> Actual <h5>{format_numbers(actual_channel_spends)}</h5> </p>",
|
| 2191 |
unsafe_allow_html=True,
|
| 2192 |
)
|
| 2193 |
# st.metric(
|
|
@@ -2199,7 +2199,7 @@ if auth_status == True:
|
|
| 2199 |
|
| 2200 |
# st.write("Actual")
|
| 2201 |
st.markdown(
|
| 2202 |
-
f"<p> Change
|
| 2203 |
unsafe_allow_html=True,
|
| 2204 |
)
|
| 2205 |
# st.markdown(f'<h4 class="custom-text1">{format_numbers(spends_delta)}%</h4>', unsafe_allow_html=True)
|
|
@@ -2212,11 +2212,11 @@ if auth_status == True:
|
|
| 2212 |
# )
|
| 2213 |
with _spend_cols[1]:
|
| 2214 |
st.markdown(
|
| 2215 |
-
f"<p>
|
| 2216 |
unsafe_allow_html=True,
|
| 2217 |
)
|
| 2218 |
st.markdown(
|
| 2219 |
-
f'<p>Percent<h5>{numerize(( spends_delta/actual_channel_spends)*100,0) +"%"}</h5> </p>',
|
| 2220 |
unsafe_allow_html=True,
|
| 2221 |
)
|
| 2222 |
# st.metric(
|
|
@@ -2251,11 +2251,11 @@ if auth_status == True:
|
|
| 2251 |
with _prospect_cols[0]:
|
| 2252 |
# st.write("Actual")
|
| 2253 |
st.markdown(
|
| 2254 |
-
f"<p>
|
| 2255 |
unsafe_allow_html=True,
|
| 2256 |
)
|
| 2257 |
st.markdown(
|
| 2258 |
-
f"<p> Change
|
| 2259 |
unsafe_allow_html=True,
|
| 2260 |
)
|
| 2261 |
|
|
@@ -2274,11 +2274,11 @@ if auth_status == True:
|
|
| 2274 |
# )
|
| 2275 |
with _prospect_cols[1]:
|
| 2276 |
st.markdown(
|
| 2277 |
-
f"<p>
|
| 2278 |
unsafe_allow_html=True,
|
| 2279 |
)
|
| 2280 |
st.markdown(
|
| 2281 |
-
f'<p>Percent<h5>{numerize(( _channel_class.delta_sales/actual_channel_sales)*100,0) +"%"}</h5> </p>',
|
| 2282 |
unsafe_allow_html=True,
|
| 2283 |
)
|
| 2284 |
|
|
|
|
| 2028 |
st.markdown(
|
| 2029 |
"""<hr class="spends-heading-seperator">""", unsafe_allow_html=True
|
| 2030 |
)
|
| 2031 |
+
_columns = st.columns((2, 1.5, 3, 3, 1))
|
| 2032 |
with _columns[0]:
|
| 2033 |
generate_spending_header("Channel")
|
| 2034 |
with _columns[1]:
|
|
|
|
| 2068 |
# st.write(st.session_state["scenario"].channels[channel_name].bounds)
|
| 2069 |
# st.write(st.session_state["scenario"].channels[channel_name].channel_bounds_min)
|
| 2070 |
|
| 2071 |
+
_columns = st.columns((2, 1.5, 3, 3, 1))
|
| 2072 |
response_curve_params = pd.read_excel(
|
| 2073 |
"response_curves_parameters.xlsx", index_col="channel"
|
| 2074 |
)
|
|
|
|
| 2099 |
### # # print(st.session_state[channel_name])
|
| 2100 |
# st.write(_channel_class.channel_bounds_min,channel_bounds_min)
|
| 2101 |
# st.write(_channel_class.channel_bounds_max,channel_bounds_max)
|
| 2102 |
+
_columns_min = st.columns(1)
|
| 2103 |
with _columns_min[0]:
|
| 2104 |
spend_input = st.text_input(
|
| 2105 |
"Absolute",
|
|
|
|
| 2135 |
return float(st.session_state[channel_name_upper_bound])
|
| 2136 |
|
| 2137 |
channel_name_current = f"{channel_name}_change"
|
| 2138 |
+
with _columns_min[0]:
|
| 2139 |
channel_name_upper_bound = f"{channel_name}_upper_bound"
|
| 2140 |
if channel_name_upper_bound not in st.session_state:
|
| 2141 |
st.session_state[channel_name_upper_bound] = str(100)
|
|
|
|
| 2187 |
with _spend_cols[0]:
|
| 2188 |
# st.write("Actual")
|
| 2189 |
st.markdown(
|
| 2190 |
+
f"<p> Actual Spends<h5>{format_numbers(actual_channel_spends)}</h5> </p>",
|
| 2191 |
unsafe_allow_html=True,
|
| 2192 |
)
|
| 2193 |
# st.metric(
|
|
|
|
| 2199 |
|
| 2200 |
# st.write("Actual")
|
| 2201 |
st.markdown(
|
| 2202 |
+
f"<p>Spends Change<h5>{format_numbers(spends_delta)}</h5> </p>",
|
| 2203 |
unsafe_allow_html=True,
|
| 2204 |
)
|
| 2205 |
# st.markdown(f'<h4 class="custom-text1">{format_numbers(spends_delta)}%</h4>', unsafe_allow_html=True)
|
|
|
|
| 2212 |
# )
|
| 2213 |
with _spend_cols[1]:
|
| 2214 |
st.markdown(
|
| 2215 |
+
f"<p>Simulated Spends<h5>{format_numbers(current_channel_spends)}</h5> </p>",
|
| 2216 |
unsafe_allow_html=True,
|
| 2217 |
)
|
| 2218 |
st.markdown(
|
| 2219 |
+
f'<p>Spends Percent<h5>{numerize(( spends_delta/actual_channel_spends)*100,0) +"%"}</h5> </p>',
|
| 2220 |
unsafe_allow_html=True,
|
| 2221 |
)
|
| 2222 |
# st.metric(
|
|
|
|
| 2251 |
with _prospect_cols[0]:
|
| 2252 |
# st.write("Actual")
|
| 2253 |
st.markdown(
|
| 2254 |
+
f"<p>Actual Revenue<h5>$ {format_numbers_f(actual_channel_sales)}</h5> </p>",
|
| 2255 |
unsafe_allow_html=True,
|
| 2256 |
)
|
| 2257 |
st.markdown(
|
| 2258 |
+
f"<p>Revenue Change<h5>$ {format_numbers_f(sales_delta)}</h5> </p>",
|
| 2259 |
unsafe_allow_html=True,
|
| 2260 |
)
|
| 2261 |
|
|
|
|
| 2274 |
# )
|
| 2275 |
with _prospect_cols[1]:
|
| 2276 |
st.markdown(
|
| 2277 |
+
f"<p>Simulated Revenue<h5>$ {format_numbers_f(current_channel_sales)}</h5> </p>",
|
| 2278 |
unsafe_allow_html=True,
|
| 2279 |
)
|
| 2280 |
st.markdown(
|
| 2281 |
+
f'<p>Revenue Percent<h5>{numerize(( _channel_class.delta_sales/actual_channel_sales)*100,0) +"%"}</h5> </p>',
|
| 2282 |
unsafe_allow_html=True,
|
| 2283 |
)
|
| 2284 |
|
response_curves_model_quality.py
CHANGED
|
@@ -187,63 +187,63 @@ for i in range(1,13):
|
|
| 187 |
pdf = fit_data(spend_cols[i],prospect_cols[i],channel_cols[i])
|
| 188 |
plotly_data = plotly_data.merge(pdf,on = ["Date","MAT"],how = "left")
|
| 189 |
|
| 190 |
-
def response_curves(channel,x_modified,y_modified):
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
|
| 248 |
import pandas as pd
|
| 249 |
import numpy as np
|
|
@@ -447,24 +447,61 @@ def response_curves(channel,x_modified,y_modified):
|
|
| 447 |
# mode='markers',
|
| 448 |
# name=x_col.replace('_Spends', '')
|
| 449 |
# ))
|
| 450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
fig.add_trace(go.Scatter(
|
| 452 |
-
x=plotly_data1
|
| 453 |
-
y=plotly_data1
|
| 454 |
mode='lines',
|
| 455 |
-
marker=dict(color
|
| 456 |
name=x_col.replace('_Spends', '')
|
| 457 |
))
|
| 458 |
|
| 459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
# print(dividing_parameter)
|
| 461 |
-
plotly_data2 = plotly_data.copy()
|
| 462 |
-
plotly_data2 = plotly_data[plotly_data[x_col].isnull()==False]
|
| 463 |
-
plotly_data2 = plotly_data2[plotly_data2["MAT"]!="ext"]
|
| 464 |
# .dropna(subset=[x_col]).reset_index(inplace = True)
|
| 465 |
fig.add_trace(go.Scatter(
|
| 466 |
-
x=
|
| 467 |
-
y=
|
| 468 |
mode='markers',
|
| 469 |
marker=dict(
|
| 470 |
size=13 # Adjust the size value to make the markers larger or smaller
|
|
@@ -475,8 +512,8 @@ def response_curves(channel,x_modified,y_modified):
|
|
| 475 |
|
| 476 |
# # print(dividing_parameter)
|
| 477 |
fig.add_trace(go.Scatter(
|
| 478 |
-
x=[
|
| 479 |
-
y=[
|
| 480 |
mode='markers',
|
| 481 |
marker=dict(
|
| 482 |
size=13 # Adjust the size value to make the markers larger or smaller
|
|
|
|
| 187 |
pdf = fit_data(spend_cols[i],prospect_cols[i],channel_cols[i])
|
| 188 |
plotly_data = plotly_data.merge(pdf,on = ["Date","MAT"],how = "left")
|
| 189 |
|
| 190 |
+
# def response_curves(channel,x_modified,y_modified):
|
| 191 |
+
|
| 192 |
+
# # Initialize the Plotly figure
|
| 193 |
+
# fig = go.Figure()
|
| 194 |
+
|
| 195 |
+
# x_col = (channel+"_Spends").replace('\xa0', '')
|
| 196 |
+
# y_col = ("Fit_Data_"+channel).replace('\xa0', '')
|
| 197 |
+
|
| 198 |
+
# # fig.add_trace(go.Scatter(
|
| 199 |
+
# # x=plotly_data[x_col],
|
| 200 |
+
# # y=plotly_data[y_col],
|
| 201 |
+
# # mode='markers',
|
| 202 |
+
# # name=x_col.replace('_Spends', '')
|
| 203 |
+
# # ))
|
| 204 |
+
|
| 205 |
+
# fig.add_trace(go.Scatter(
|
| 206 |
+
# x=plotly_data.sort_values(by=x_col, ascending=True)[x_col],
|
| 207 |
+
# y=plotly_data.sort_values(by=x_col, ascending=True)[y_col],
|
| 208 |
+
# mode='lines+markers',
|
| 209 |
+
# name=x_col.replace('_Spends', '')
|
| 210 |
+
# ))
|
| 211 |
|
| 212 |
+
# plotly_data2 = plotly_data.copy()
|
| 213 |
+
# plotly_data2 = plotly_data[plotly_data[x_col].isnull()==False]
|
| 214 |
+
# # # print(plotly_data[plotly_data2['Date'] == plotly_data2['Date'].max()][x_col])
|
| 215 |
+
# # .dropna(subset=[x_col]).reset_index(inplace = True)
|
| 216 |
+
# fig.add_trace(go.Scatter(
|
| 217 |
+
# x=plotly_data[plotly_data2['Date'] == plotly_data2['Date'].max()][x_col],
|
| 218 |
+
# y=plotly_data[plotly_data2['Date'] == plotly_data2['Date'].max()][y_col],
|
| 219 |
+
# mode='markers',
|
| 220 |
+
# marker=dict(
|
| 221 |
+
# size=13 # Adjust the size value to make the markers larger or smaller
|
| 222 |
+
# , color = 'yellow'
|
| 223 |
+
# ),
|
| 224 |
+
# name="Current Spends"
|
| 225 |
+
# ))
|
| 226 |
+
|
| 227 |
+
# fig.add_trace(go.Scatter(
|
| 228 |
+
# x=[x_modified/104],
|
| 229 |
+
# y=[y_modified/104],
|
| 230 |
+
# mode='markers',
|
| 231 |
+
# marker=dict(
|
| 232 |
+
# size=13 # Adjust the size value to make the markers larger or smaller
|
| 233 |
+
# , color = 'blue'
|
| 234 |
+
# ),
|
| 235 |
+
# name="Optimised Spends"
|
| 236 |
+
# ))
|
| 237 |
+
|
| 238 |
+
# # Update layout with titles
|
| 239 |
+
# fig.update_layout(
|
| 240 |
+
# title=channel+' Response Curve',
|
| 241 |
+
# xaxis_title='Weekly Spends',
|
| 242 |
+
# yaxis_title='Prospects'
|
| 243 |
+
# )
|
| 244 |
+
|
| 245 |
+
# # Show the figure
|
| 246 |
+
# return fig
|
| 247 |
|
| 248 |
import pandas as pd
|
| 249 |
import numpy as np
|
|
|
|
| 447 |
# mode='markers',
|
| 448 |
# name=x_col.replace('_Spends', '')
|
| 449 |
# ))
|
| 450 |
+
|
| 451 |
+
plotly_data2 = plotly_data.copy()
|
| 452 |
+
plotly_data2 = plotly_data[plotly_data[x_col].isnull()==False]
|
| 453 |
+
plotly_data2 = plotly_data2[plotly_data2["MAT"]!="ext"]
|
| 454 |
+
|
| 455 |
+
x_actual = np.array(plotly_data2[x_col].mean())
|
| 456 |
+
y_actual = np.array(plotly_data2[y_col].mean())
|
| 457 |
+
|
| 458 |
+
# Filter data within the limits
|
| 459 |
+
plotly_data1 = plotly_data[(plotly_data["MAT"] != "ext")]
|
| 460 |
+
|
| 461 |
+
# Sort values for smooth plotting
|
| 462 |
+
plotly_data1 = plotly_data1.sort_values(by=x_col, ascending=True)
|
| 463 |
+
dividing_parameter = len(plotly_data1[plotly_data1[x_col].isnull()==False])
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
x_mod = x_modified/dividing_parameter
|
| 467 |
+
y_mod = y_modified/dividing_parameter
|
| 468 |
+
|
| 469 |
+
# Define limits
|
| 470 |
+
x_limit = 1.2 * max(x_actual, x_mod)
|
| 471 |
+
# y_limit = 1.5 * y_actual
|
| 472 |
+
|
| 473 |
+
plotly_data1 = plotly_data[(plotly_data["MAT"] != "ext") &
|
| 474 |
+
(plotly_data[x_col] <= x_limit)]
|
| 475 |
+
plotly_data1 = plotly_data1.sort_values(by=x_col, ascending=True)
|
| 476 |
+
|
| 477 |
+
# Plot
|
| 478 |
fig.add_trace(go.Scatter(
|
| 479 |
+
x=plotly_data1[x_col],
|
| 480 |
+
y=plotly_data1[y_col],
|
| 481 |
mode='lines',
|
| 482 |
+
marker=dict(color='blue'),
|
| 483 |
name=x_col.replace('_Spends', '')
|
| 484 |
))
|
| 485 |
|
| 486 |
+
|
| 487 |
+
# plotly_data1 = plotly_data[plotly_data["MAT"]!="ext"]
|
| 488 |
+
# fig.add_trace(go.Scatter(
|
| 489 |
+
# x=plotly_data1.sort_values(by=x_col, ascending=True)[x_col],
|
| 490 |
+
# y=plotly_data1.sort_values(by=x_col, ascending=True)[y_col],
|
| 491 |
+
# mode='lines',
|
| 492 |
+
# marker=dict(color = 'blue'),
|
| 493 |
+
# name=x_col.replace('_Spends', '')
|
| 494 |
+
# ))
|
| 495 |
+
|
| 496 |
+
|
| 497 |
# print(dividing_parameter)
|
| 498 |
+
# plotly_data2 = plotly_data.copy()
|
| 499 |
+
# plotly_data2 = plotly_data[plotly_data[x_col].isnull()==False]
|
| 500 |
+
# plotly_data2 = plotly_data2[plotly_data2["MAT"]!="ext"]
|
| 501 |
# .dropna(subset=[x_col]).reset_index(inplace = True)
|
| 502 |
fig.add_trace(go.Scatter(
|
| 503 |
+
x=x_actual,
|
| 504 |
+
y=y_actual,
|
| 505 |
mode='markers',
|
| 506 |
marker=dict(
|
| 507 |
size=13 # Adjust the size value to make the markers larger or smaller
|
|
|
|
| 512 |
|
| 513 |
# # print(dividing_parameter)
|
| 514 |
fig.add_trace(go.Scatter(
|
| 515 |
+
x=[x_mod],
|
| 516 |
+
y=[y_mod],
|
| 517 |
mode='markers',
|
| 518 |
marker=dict(
|
| 519 |
size=13 # Adjust the size value to make the markers larger or smaller
|
summary_df.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1756
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b903397f79c77828d7f6b534a45d52f33e534aae4ab41e7352be0809e55a8d64
|
| 3 |
size 1756
|