|
import streamlit as st
|
|
import pandas as pd
|
|
import numpy as np
|
|
import plotly.express as px
|
|
import Streamlit_functions as sf
|
|
import response_curves_model_quality_base as rc1
|
|
st.set_page_config(
|
|
layout="wide"
|
|
)
|
|
from pptx import Presentation
|
|
from pptx.util import Inches
|
|
from io import BytesIO
|
|
import plotly.io as pio
|
|
import Streamlit_functions as sf
|
|
import response_curves_model_quality_base as rc1
|
|
|
|
|
|
def save_ppt_file():
|
|
|
|
|
|
prs = Presentation()
|
|
|
|
def add_plotly_chart_to_slide(slide, fig, left, top, width, height):
|
|
img_stream = BytesIO()
|
|
pio.write_image(fig, img_stream, format='png')
|
|
slide.shapes.add_picture(img_stream, left, top, width, height)
|
|
|
|
|
|
slide_1 = prs.slides.add_slide(prs.slide_layouts[5])
|
|
title_1 = slide_1.shapes.title
|
|
title_1.text = "Model Quality"
|
|
i = 0
|
|
|
|
|
|
fig = sf.mmm_model_quality()
|
|
|
|
|
|
add_plotly_chart_to_slide(slide_1, fig, Inches(1), Inches(2), width=Inches(9), height=Inches(4.5))
|
|
i = i+1
|
|
|
|
|
|
slide_2 = prs.slides.add_slide(prs.slide_layouts[5])
|
|
title_2 = slide_2.shapes.title
|
|
title_2.text = "Media Data Elasticity"
|
|
i = i+1
|
|
|
|
|
|
media_df = sf.media_data()
|
|
fig = sf.elasticity(media_df)
|
|
fig.update_layout(
|
|
margin=dict(l=150, r=50, t=50, b=50),
|
|
|
|
)
|
|
i = i+1
|
|
|
|
|
|
add_plotly_chart_to_slide(slide_2, fig, Inches(1), Inches(2), width=Inches(8), height=Inches(4.5))
|
|
i = i+1
|
|
|
|
|
|
slide_3 = prs.slides.add_slide(prs.slide_layouts[5])
|
|
title_3 = slide_3.shapes.title
|
|
title_3.text = "Half-Life Analysis"
|
|
i = i+1
|
|
|
|
|
|
fig = sf.half_life(media_df)
|
|
fig.update_layout(
|
|
margin=dict(l=150, r=100, t=50, b=50),
|
|
|
|
)
|
|
i = i+1
|
|
|
|
|
|
add_plotly_chart_to_slide(slide_3, fig, Inches(1), Inches(2), width=Inches(8), height=Inches(4.5))
|
|
i = i+1
|
|
|
|
|
|
|
|
|
|
channels = [
|
|
'Broadcast TV',
|
|
'Cable TV',
|
|
'Connected & OTT TV',
|
|
'Display Prospecting',
|
|
'Display Retargeting',
|
|
'Video',
|
|
'Social Prospecting',
|
|
'Social Retargeting',
|
|
'Search Brand',
|
|
'Search Non-brand',
|
|
'Digital Partners',
|
|
'Audio',
|
|
'Email']
|
|
i = 4
|
|
for channel_name in channels:
|
|
slide_4 = prs.slides.add_slide(prs.slide_layouts[5])
|
|
title_4 = slide_4.shapes.title
|
|
title_4.text = "Response Curves"
|
|
i = i+1
|
|
|
|
selected_option = channel_name
|
|
selected_option2 = 'View Line Plot'
|
|
fig = rc1.response_curves(selected_option, selected_option2)
|
|
|
|
add_plotly_chart_to_slide(slide_4, fig, Inches(1), Inches(2), width=Inches(6), height=Inches(4.5))
|
|
|
|
|
|
|
|
|
|
|
|
ppt_stream = BytesIO()
|
|
prs.save(ppt_stream)
|
|
ppt_stream.seek(0)
|
|
|
|
return ppt_stream.getvalue()
|
|
|
|
|
|
|
|
|
|
st.header("Model Quality")
|
|
|
|
|
|
st.plotly_chart(sf.mmm_model_quality(),use_container_width=True)
|
|
fig = sf.mmm_model_quality()
|
|
|
|
|
|
|
|
|
|
media_df = sf.media_data()
|
|
|
|
col1, col2 , col3 = st.columns([1,0.2,1])
|
|
df1 = sf.model_metrics_table_func()
|
|
st.dataframe(df1,hide_index = True,use_container_width=True)
|
|
|
|
|
|
with col1:
|
|
st.plotly_chart(sf.elasticity(media_df))
|
|
fig = sf.elasticity(media_df)
|
|
|
|
with col2:
|
|
st.write("")
|
|
with col3:
|
|
st.plotly_chart(sf.half_life(media_df))
|
|
fig = sf.elasticity(media_df)
|
|
|
|
|
|
|
|
|
|
options = [
|
|
'Broadcast TV',
|
|
'Cable TV',
|
|
'Connected & OTT TV',
|
|
'Display Prospecting',
|
|
'Display Retargeting',
|
|
'Video',
|
|
'Social Prospecting',
|
|
'Social Retargeting',
|
|
'Search Brand',
|
|
'Search Non-brand',
|
|
'Digital Partners',
|
|
'Audio',
|
|
'Email']
|
|
options1 = [
|
|
'View Line Plot',
|
|
'View Scattered Plot',
|
|
"View Both"]
|
|
col1, col2 = st.columns(2)
|
|
|
|
with col1:
|
|
selected_option = st.selectbox('Select A Media Channel:', options)
|
|
selected_option2 = st.selectbox('Select A Chart Type', options1)
|
|
|
|
|
|
with col2:
|
|
st.write("")
|
|
st.plotly_chart(rc1.response_curves(selected_option,selected_option2))
|
|
|
|
if st.button("Prepare Analysis Download"):
|
|
ppt_file = save_ppt_file()
|
|
|
|
st.download_button(
|
|
label="Download Analysis",
|
|
data=ppt_file,
|
|
file_name="MMM_Model_Quality_Presentation.pptx",
|
|
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
)
|
|
|
|
|
|
|