Spaces:
Sleeping
Sleeping
Pragya Jatav commited on
Commit ·
d458fbe
1
Parent(s): 7905941
m1
Browse files- __pycache__/classes.cpython-310.pyc +0 -0
- classes.py +1 -2
- pages/2_Scenario_Planner.py +61 -37
- summary_df.pkl +1 -1
__pycache__/classes.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/classes.cpython-310.pyc and b/__pycache__/classes.cpython-310.pyc differ
|
|
|
classes.py
CHANGED
|
@@ -431,8 +431,7 @@ class Scenario:
|
|
| 431 |
spends_constant.append(self.channels[channel_name].conversion_rate)
|
| 432 |
# # # print(spends_constant)
|
| 433 |
spends_constraint += (
|
| 434 |
-
self.channels[channel_name].actual_total_spends+ self.channels[channel_name].delta_spends
|
| 435 |
-
#* (1 + self.channels[channel_name].delta_spends / 100)
|
| 436 |
)
|
| 437 |
# # # print("delta spends",self.channels[channel_name].delta_spends)
|
| 438 |
# spends_constraint = spends_constraint * (1 + spends_percent / 100)
|
|
|
|
| 431 |
spends_constant.append(self.channels[channel_name].conversion_rate)
|
| 432 |
# # # print(spends_constant)
|
| 433 |
spends_constraint += (
|
| 434 |
+
self.channels[channel_name].actual_total_spends+ self.channels[channel_name].delta_spends #st.session_state["total_spends_change_abs_slider_options"]
|
|
|
|
| 435 |
)
|
| 436 |
# # # print("delta spends",self.channels[channel_name].delta_spends)
|
| 437 |
# spends_constraint = spends_constraint * (1 + spends_percent / 100)
|
pages/2_Scenario_Planner.py
CHANGED
|
@@ -239,26 +239,26 @@ def update_sales_abs_slider():
|
|
| 239 |
|
| 240 |
|
| 241 |
def update_sales_abs():
|
| 242 |
-
if (
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
):
|
| 246 |
-
|
| 247 |
-
else:
|
| 248 |
-
|
| 249 |
|
| 250 |
actual_sales = _scenario.actual_total_sales
|
| 251 |
-
if (
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
):
|
| 255 |
-
|
| 256 |
st.session_state["total_sales_change_abs"]
|
| 257 |
)
|
| 258 |
-
|
| 259 |
((modified_sales / actual_sales) - 1) * 100
|
| 260 |
)
|
| 261 |
-
|
| 262 |
|
| 263 |
|
| 264 |
def update_sales():
|
|
@@ -309,15 +309,17 @@ def update_sales():
|
|
| 309 |
|
| 310 |
|
| 311 |
def update_all_spends_abs():
|
| 312 |
-
st.write("aon update spends abs")
|
| 313 |
-
if (
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
):
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
| 321 |
|
| 322 |
actual_spends = _scenario.actual_total_spends
|
| 323 |
if (
|
|
@@ -386,17 +388,31 @@ def validate_input(string_input):
|
|
| 386 |
return False
|
| 387 |
return True
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
def update_data_bound_min(channel_name):
|
| 390 |
"""
|
| 391 |
Updates the bounds for the given channel
|
| 392 |
"""
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
|
|
|
|
|
|
| 400 |
def update_data_bound_max(channel_name):
|
| 401 |
"""
|
| 402 |
Updates the bounds for the given channel
|
|
@@ -1595,6 +1611,7 @@ if auth_status == True:
|
|
| 1595 |
# label_visibility="collapsed",
|
| 1596 |
on_change=update_all_spends_abs,
|
| 1597 |
)
|
|
|
|
| 1598 |
# overall_lower_bound = 50.0
|
| 1599 |
# overall_upper_bound = 50.0
|
| 1600 |
with _columns2[1]:
|
|
@@ -1776,28 +1793,35 @@ if auth_status == True:
|
|
| 1776 |
on_change=partial(update_data_bound_min,channel_name)
|
| 1777 |
)
|
| 1778 |
# st.write(st.session_state[channel_name_lower_bound])
|
|
|
|
|
|
|
| 1779 |
if not validate_input(spend_input):
|
| 1780 |
st.error("Invalid input")
|
| 1781 |
-
|
|
|
|
| 1782 |
channel_name_current = f"{channel_name}_change"
|
| 1783 |
with _columns_min[1]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1784 |
st.number_input(
|
| 1785 |
"Percent Change",
|
| 1786 |
key=channel_name_current,
|
| 1787 |
step=1.00,value=0.00,
|
| 1788 |
on_change=partial(update_data_by_percent, channel_name),
|
| 1789 |
-
|
| 1790 |
-
|
| 1791 |
-
|
| 1792 |
-
if channel_name_upper_bound not in st.session_state:
|
| 1793 |
-
st.session_state[channel_name_upper_bound] = str(100)
|
| 1794 |
|
|
|
|
|
|
|
| 1795 |
channel_bounds_max = st.text_input(
|
| 1796 |
"Upper Bound Percentage",
|
| 1797 |
key = channel_name_upper_bound,
|
| 1798 |
on_change=partial(update_data_bound_max,channel_name)
|
| 1799 |
)
|
| 1800 |
-
|
|
|
|
| 1801 |
with _columns[2]:
|
| 1802 |
# spends
|
| 1803 |
current_channel_spends = float(
|
|
|
|
| 239 |
|
| 240 |
|
| 241 |
def update_sales_abs():
|
| 242 |
+
# if (
|
| 243 |
+
# st.session_state["total_sales_change_abs"]
|
| 244 |
+
# in st.session_state["total_sales_change_abs_slider_options"]
|
| 245 |
+
# ):
|
| 246 |
+
# st.session_state["allow_sales_update"] = True
|
| 247 |
+
# else:
|
| 248 |
+
# st.session_state["allow_sales_update"] = False
|
| 249 |
|
| 250 |
actual_sales = _scenario.actual_total_sales
|
| 251 |
+
# if (
|
| 252 |
+
# validate_input(st.session_state["total_sales_change_abs"])
|
| 253 |
+
# and st.session_state["allow_sales_update"]
|
| 254 |
+
# ):
|
| 255 |
+
modified_sales = extract_number_for_string(
|
| 256 |
st.session_state["total_sales_change_abs"]
|
| 257 |
)
|
| 258 |
+
st.session_state["total_sales_change"] = round(
|
| 259 |
((modified_sales / actual_sales) - 1) * 100
|
| 260 |
)
|
| 261 |
+
st.session_state["total_sales_change_abs_slider"] = numerize(modified_sales, 1)
|
| 262 |
|
| 263 |
|
| 264 |
def update_sales():
|
|
|
|
| 309 |
|
| 310 |
|
| 311 |
def update_all_spends_abs():
|
| 312 |
+
# st.write("aon update spends abs")
|
| 313 |
+
# if (
|
| 314 |
+
# st.session_state["total_spends_change_abs"]
|
| 315 |
+
# in st.session_state["total_spends_change_abs_slider_options"]
|
| 316 |
+
# ):
|
| 317 |
+
# st.session_state["allow_spends_update"] = True
|
| 318 |
+
# print st.session_state["total_spends_change_abs_slider_options"]
|
| 319 |
+
# print("not allowed")
|
| 320 |
+
# else:
|
| 321 |
+
# st.session_state["allow_spends_update"] = False
|
| 322 |
+
# # st.warning("Invalid Input")
|
| 323 |
|
| 324 |
actual_spends = _scenario.actual_total_spends
|
| 325 |
if (
|
|
|
|
| 388 |
return False
|
| 389 |
return True
|
| 390 |
|
| 391 |
+
def validate_input_lb(string_input):
|
| 392 |
+
pattern = r"\d+\.?\d*[K|M|B]$"
|
| 393 |
+
match = re.match(pattern, string_input)
|
| 394 |
+
if match is None:
|
| 395 |
+
return False
|
| 396 |
+
response_curve_params = pd.read_excel("response_curves_parameters.xlsx",index_col = "channel")
|
| 397 |
+
param_dicts = {col: response_curve_params[col].to_dict() for col in response_curve_params.columns}
|
| 398 |
+
if float(string_input) < round(param_dicts["x_min"][channel_name]*10400/param_dicts["current_spends"][channel_name]):
|
| 399 |
+
return False
|
| 400 |
+
|
| 401 |
+
return True
|
| 402 |
+
|
| 403 |
def update_data_bound_min(channel_name):
|
| 404 |
"""
|
| 405 |
Updates the bounds for the given channel
|
| 406 |
"""
|
| 407 |
+
if validate_input_lb(st.session_state[f"{channel_name}_lower_bound"]):
|
| 408 |
+
modified_bounds = st.session_state[f"{channel_name}_lower_bound"]
|
| 409 |
+
|
| 410 |
+
# st.session_state['scenario']['channels'][channel_name].channel_bounds_min = st.session_state[f"{channel_name}_lower_bound"]
|
| 411 |
+
st.session_state['scenario'].update_bounds_min(channel_name,modified_bounds)
|
| 412 |
+
st.write(st.session_state["scenario"].channels[channel_name].channel_bounds_min)
|
| 413 |
+
# st.write(st.session_state["scenario"].channels[channel_name]
|
| 414 |
+
|
| 415 |
+
|
| 416 |
def update_data_bound_max(channel_name):
|
| 417 |
"""
|
| 418 |
Updates the bounds for the given channel
|
|
|
|
| 1611 |
# label_visibility="collapsed",
|
| 1612 |
on_change=update_all_spends_abs,
|
| 1613 |
)
|
| 1614 |
+
# st.write(min_value,max_value)
|
| 1615 |
# overall_lower_bound = 50.0
|
| 1616 |
# overall_upper_bound = 50.0
|
| 1617 |
with _columns2[1]:
|
|
|
|
| 1793 |
on_change=partial(update_data_bound_min,channel_name)
|
| 1794 |
)
|
| 1795 |
# st.write(st.session_state[channel_name_lower_bound])
|
| 1796 |
+
# if not validate_input_lb(str(channel_bounds_min)):
|
| 1797 |
+
# st.error("Invalid input")
|
| 1798 |
if not validate_input(spend_input):
|
| 1799 |
st.error("Invalid input")
|
| 1800 |
+
def calc_min_value():
|
| 1801 |
+
return float(st.session_state[channel_name_upper_bound])
|
| 1802 |
channel_name_current = f"{channel_name}_change"
|
| 1803 |
with _columns_min[1]:
|
| 1804 |
+
channel_name_upper_bound = f"{channel_name}_upper_bound"
|
| 1805 |
+
if channel_name_upper_bound not in st.session_state:
|
| 1806 |
+
st.session_state[channel_name_upper_bound] = str(100)
|
| 1807 |
+
# st.write(float(st.session_state[channel_name_lower_bound]),float(st.session_state[channel_name_upper_bound]),)
|
| 1808 |
st.number_input(
|
| 1809 |
"Percent Change",
|
| 1810 |
key=channel_name_current,
|
| 1811 |
step=1.00,value=0.00,
|
| 1812 |
on_change=partial(update_data_by_percent, channel_name),
|
| 1813 |
+
max_value = calc_min_value(),
|
| 1814 |
+
min_value = -1*float(st.session_state[channel_name_lower_bound])
|
|
|
|
|
|
|
|
|
|
| 1815 |
|
| 1816 |
+
)
|
| 1817 |
+
|
| 1818 |
channel_bounds_max = st.text_input(
|
| 1819 |
"Upper Bound Percentage",
|
| 1820 |
key = channel_name_upper_bound,
|
| 1821 |
on_change=partial(update_data_bound_max,channel_name)
|
| 1822 |
)
|
| 1823 |
+
# if not validate_input(channel_bounds_max):
|
| 1824 |
+
# st.error("Invalid input")
|
| 1825 |
with _columns[2]:
|
| 1826 |
# spends
|
| 1827 |
current_channel_spends = float(
|
summary_df.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1822
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cdae4dbff6029967edec8ee6ea14de7d682a0c536c7c0e303557ee644138c112
|
| 3 |
size 1822
|