Spaces:
Sleeping
Sleeping
Upload 10_Optimized_Result_Analysis.py
Browse files
pages/10_Optimized_Result_Analysis.py
CHANGED
@@ -14,7 +14,15 @@ import plotly.express as px
|
|
14 |
import numpy as np
|
15 |
import plotly.graph_objects as go
|
16 |
import pandas as pd
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def summary_plot(data, x, y, title, text_column, color, format_as_percent=False, format_as_decimal=False):
|
20 |
fig = px.bar(data, x=x, y=y, orientation='h',
|
@@ -96,6 +104,7 @@ spends_data=pd.read_excel('Overview_data_test.xlsx')
|
|
96 |
|
97 |
with open('summary_df.pkl', 'rb') as file:
|
98 |
summary_df_sorted = pickle.load(file)
|
|
|
99 |
|
100 |
selected_scenario= st.selectbox('Select Saved Scenarios',['S1','S2'])
|
101 |
|
@@ -334,31 +343,75 @@ with st.expander("Return Forecast by Media Channel"):
|
|
334 |
|
335 |
summary_df_sorted=summary_df_sorted.merge(effectiveness_df,left_on="Channel_name",right_on='Channel')
|
336 |
|
337 |
-
#
|
338 |
-
summary_df_sorted['Efficiency']=summary_df_sorted['ResponseMetricValue']/summary_df_sorted['Optimized_spend']
|
339 |
-
|
340 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
|
|
347 |
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
from plotly.subplots import make_subplots
|
362 |
|
363 |
# Create figure with subplots
|
364 |
# fig = make_subplots(rows=1, cols=2)
|
|
|
14 |
import numpy as np
|
15 |
import plotly.graph_objects as go
|
16 |
import pandas as pd
|
17 |
+
from plotly.subplots import make_subplots
|
18 |
|
19 |
+
def format_number(x):
|
20 |
+
if x >= 1_000_000:
|
21 |
+
return f'{x / 1_000_000:.2f}M'
|
22 |
+
elif x >= 1_000:
|
23 |
+
return f'{x / 1_000:.2f}K'
|
24 |
+
else:
|
25 |
+
return f'{x:.2f}'
|
26 |
|
27 |
def summary_plot(data, x, y, title, text_column, color, format_as_percent=False, format_as_decimal=False):
|
28 |
fig = px.bar(data, x=x, y=y, orientation='h',
|
|
|
104 |
|
105 |
with open('summary_df.pkl', 'rb') as file:
|
106 |
summary_df_sorted = pickle.load(file)
|
107 |
+
#st.write(summary_df_sorted)
|
108 |
|
109 |
selected_scenario= st.selectbox('Select Saved Scenarios',['S1','S2'])
|
110 |
|
|
|
343 |
|
344 |
summary_df_sorted=summary_df_sorted.merge(effectiveness_df,left_on="Channel_name",right_on='Channel')
|
345 |
|
346 |
+
#
|
347 |
+
summary_df_sorted['Efficiency'] = summary_df_sorted['ResponseMetricValue'] / summary_df_sorted['Optimized_spend']
|
348 |
+
summary_df_sorted=summary_df_sorted.sort_values(by='Optimized_spend',ascending=True)
|
349 |
+
#st.dataframe(summary_df_sorted)
|
350 |
+
|
351 |
+
channel_colors = px.colors.qualitative.Plotly
|
352 |
+
|
353 |
+
fig = make_subplots(rows=1, cols=3, subplot_titles=('Optimized Spends', 'Effectiveness', 'Efficiency'), horizontal_spacing=0.05)
|
354 |
+
|
355 |
+
for i, channel in enumerate(summary_df_sorted['Channel_name'].unique()):
|
356 |
+
channel_df = summary_df_sorted[summary_df_sorted['Channel_name'] == channel]
|
357 |
+
channel_color = channel_colors[i % len(channel_colors)]
|
358 |
+
|
359 |
+
fig.add_trace(go.Bar(x=channel_df['Optimized_spend'],
|
360 |
+
y=channel_df['Channel_name'],
|
361 |
+
text=channel_df['Optimized_spend'].apply(format_number),
|
362 |
+
marker_color=channel_color,
|
363 |
+
orientation='h'), row=1, col=1)
|
364 |
+
|
365 |
+
fig.add_trace(go.Bar(x=channel_df['ResponseMetricValue'],
|
366 |
+
y=channel_df['Channel_name'],
|
367 |
+
text=channel_df['ResponseMetricValue'].apply(format_number),
|
368 |
+
marker_color=channel_color,
|
369 |
+
orientation='h', showlegend=False), row=1, col=2)
|
370 |
+
|
371 |
+
fig.add_trace(go.Bar(x=channel_df['Efficiency'],
|
372 |
+
y=channel_df['Channel_name'],
|
373 |
+
text=channel_df['Efficiency'].apply(format_number),
|
374 |
+
marker_color=channel_color,
|
375 |
+
orientation='h', showlegend=False), row=1, col=3)
|
376 |
+
|
377 |
+
fig.update_layout(
|
378 |
+
height=600,
|
379 |
+
width=900,
|
380 |
+
title='Media Channel Performance',
|
381 |
+
showlegend=False
|
382 |
+
)
|
383 |
+
|
384 |
+
fig.update_yaxes(showticklabels=False ,row=1, col=2 )
|
385 |
+
fig.update_yaxes(showticklabels=False, row=1, col=3)
|
386 |
+
|
387 |
+
fig.update_xaxes(showticklabels=False, row=1, col=1)
|
388 |
+
fig.update_xaxes(showticklabels=False, row=1, col=2)
|
389 |
+
fig.update_xaxes(showticklabels=False, row=1, col=3)
|
390 |
+
|
391 |
+
|
392 |
+
st.plotly_chart(fig, use_container_width=True)
|
393 |
+
|
394 |
|
395 |
+
|
396 |
+
# columns= st.columns(3)
|
397 |
+
# with columns[0]:
|
398 |
+
# fig=summary_plot(summary_df_sorted, x='Optimized_spend', y='Channel_name', title='', text_column='Optimized_spend',color='Channel_name')
|
399 |
+
# st.plotly_chart(fig,use_container_width=True)
|
400 |
+
# with columns[1]:
|
401 |
|
402 |
+
# # effectiveness=(selected_metric.groupby(by=['MediaChannelName'])['ResponseMetricValue'].sum()).values
|
403 |
+
# # effectiveness_df=pd.DataFrame({'Channel':st.session_state['raw_data']['MediaChannelName'].unique(),"ResponseMetricValue":effectiveness})
|
404 |
+
# # # effectiveness.reset_index(inplace=True)
|
405 |
+
# # # st.dataframe(effectiveness.head())
|
406 |
+
|
407 |
+
|
408 |
+
# fig=summary_plot(summary_df_sorted, x='ResponseMetricValue', y='Channel_name', title='Effectiveness', text_column='ResponseMetricValue',color='Channel_name')
|
409 |
+
# st.plotly_chart(fig,use_container_width=True)
|
410 |
+
|
411 |
+
# with columns[2]:
|
412 |
+
# fig=summary_plot(summary_df_sorted, x='Efficiency', y='Channel_name', title='Efficiency', text_column='Efficiency',color='Channel_name',format_as_decimal=True)
|
413 |
+
# st.plotly_chart(fig,use_container_width=True)
|
414 |
+
|
|
|
415 |
|
416 |
# Create figure with subplots
|
417 |
# fig = make_subplots(rows=1, cols=2)
|