Spaces:
Running
Running
harrychangjr commited on
Commit ·
b399bc7
1
Parent(s): 30c9e7b
analysis overview
Browse files- .DS_Store +0 -0
- Home.py +2 -2
- gaming/Last 28 days.xlsx +0 -0
- gaming/Last 60 days.xlsx +0 -0
- gaming/Last 7 days.xlsx +0 -0
- gaming/Total followers.xlsx +0 -0
- gaming/Trending videos.xlsx +0 -0
- gaming/Video Posts.xlsx +0 -0
- pages/04_Case Study:_Gaming_Clips.py +279 -0
.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
Home.py
CHANGED
|
@@ -15,9 +15,9 @@ import streamlit as st
|
|
| 15 |
# add_page_title()
|
| 16 |
|
| 17 |
# Set page title
|
| 18 |
-
st.set_page_config(page_title="
|
| 19 |
|
| 20 |
-
st.header("
|
| 21 |
|
| 22 |
|
| 23 |
|
|
|
|
| 15 |
# add_page_title()
|
| 16 |
|
| 17 |
# Set page title
|
| 18 |
+
st.set_page_config(page_title="Enhanced TikTok Analytics Dashboard", page_icon = "📊", layout = "centered", initial_sidebar_state = "auto")
|
| 19 |
|
| 20 |
+
st.header("Enhanced TikTok Analytics Dashboard")
|
| 21 |
|
| 22 |
|
| 23 |
|
gaming/Last 28 days.xlsx
ADDED
|
Binary file (19.6 kB). View file
|
|
|
gaming/Last 60 days.xlsx
ADDED
|
Binary file (25.1 kB). View file
|
|
|
gaming/Last 7 days.xlsx
ADDED
|
Binary file (15.9 kB). View file
|
|
|
gaming/Total followers.xlsx
ADDED
|
Binary file (20.9 kB). View file
|
|
|
gaming/Trending videos.xlsx
ADDED
|
Binary file (19.8 kB). View file
|
|
|
gaming/Video Posts.xlsx
ADDED
|
Binary file (12.5 kB). View file
|
|
|
pages/04_Case Study:_Gaming_Clips.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import datetime
|
| 5 |
+
import plotly.express as px
|
| 6 |
+
import plotly.graph_objects as go
|
| 7 |
+
import statsmodels.api as sm
|
| 8 |
+
from millify import millify
|
| 9 |
+
from sklearn.linear_model import LinearRegression
|
| 10 |
+
from sklearn.metrics import r2_score
|
| 11 |
+
from st_aggrid import AgGrid
|
| 12 |
+
import io
|
| 13 |
+
import re
|
| 14 |
+
import emoji
|
| 15 |
+
from collections import Counter
|
| 16 |
+
import openpyxl
|
| 17 |
+
from gensim.models import Word2Vec
|
| 18 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 19 |
+
from sklearn.linear_model import LinearRegression
|
| 20 |
+
from sklearn.ensemble import RandomForestRegressor
|
| 21 |
+
from xgboost import XGBRegressor
|
| 22 |
+
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
|
| 23 |
+
from sklearn.model_selection import train_test_split
|
| 24 |
+
import seaborn as sns
|
| 25 |
+
import matplotlib.pyplot as plt
|
| 26 |
+
from mpl_toolkits.mplot3d import Axes3D
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Set page title
|
| 30 |
+
st.set_page_config(page_title="Case Study: Gaming Clips - Tiktok Analytics Dashboard", page_icon = "📊", layout = "centered", initial_sidebar_state = "auto")
|
| 31 |
+
|
| 32 |
+
st.header("Case Study: Gaming Clips")
|
| 33 |
+
|
| 34 |
+
selected_options = ["Background Information", "Uploaded Datasets", "Analysis"]
|
| 35 |
+
selected = st.selectbox("Which section would you like to read?", options = selected_options)
|
| 36 |
+
st.write("Current selection:", selected)
|
| 37 |
+
if selected == "Background Information":
|
| 38 |
+
st.subheader("Background Information")
|
| 39 |
+
elif selected == "Uploaded Datasets":
|
| 40 |
+
st.subheader("Uploaded Datasets")
|
| 41 |
+
last7days = pd.read_excel('gaming/Last 7 days.xlsx')
|
| 42 |
+
last28days = pd.read_excel('gaming/Last 28 days.xlsx')
|
| 43 |
+
last60days = pd.read_excel('gaming/Last 60 days.xlsx')
|
| 44 |
+
totalfollowers = pd.read_excel('gaming/Total followers.xlsx')
|
| 45 |
+
trendingvideos = pd.read_excel('gaming/Trending videos.xlsx')
|
| 46 |
+
videoposts = pd.read_excel('gaming/Video Posts.xlsx')
|
| 47 |
+
|
| 48 |
+
#function to convert any dataframe to a csv file
|
| 49 |
+
@st.cache_data
|
| 50 |
+
|
| 51 |
+
def convert_df(df):
|
| 52 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
| 53 |
+
return df.to_csv().encode('utf-8')
|
| 54 |
+
|
| 55 |
+
st.write('Last 7 days.xlsx')
|
| 56 |
+
st.write(last7days)
|
| 57 |
+
#converting the sample dataframe
|
| 58 |
+
csv = convert_df(last7days)
|
| 59 |
+
#adding a download button to download csv file
|
| 60 |
+
st.download_button(
|
| 61 |
+
label="Download data as CSV",
|
| 62 |
+
data=csv,
|
| 63 |
+
file_name='Last 7 days.csv',
|
| 64 |
+
mime='text/csv',
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
st.write('Last 28 days.xlsx')
|
| 68 |
+
st.write(last28days)
|
| 69 |
+
#converting the sample dataframe
|
| 70 |
+
csv = convert_df(last28days)
|
| 71 |
+
#adding a download button to download csv file
|
| 72 |
+
st.download_button(
|
| 73 |
+
label="Download data as CSV",
|
| 74 |
+
data=csv,
|
| 75 |
+
file_name='Last 28 days.csv',
|
| 76 |
+
mime='text/csv',
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
st.write('Last 60 days.xlsx')
|
| 80 |
+
st.write(last60days)
|
| 81 |
+
#converting the sample dataframe
|
| 82 |
+
csv = convert_df(last60days)
|
| 83 |
+
#adding a download button to download csv file
|
| 84 |
+
st.download_button(
|
| 85 |
+
label="Download data as CSV",
|
| 86 |
+
data=csv,
|
| 87 |
+
file_name='Last 60 days.csv',
|
| 88 |
+
mime='text/csv',
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
st.write('Total followers.xlsx')
|
| 92 |
+
st.write(totalfollowers)
|
| 93 |
+
#converting the sample dataframe
|
| 94 |
+
csv = convert_df(totalfollowers)
|
| 95 |
+
#adding a download button to download csv file
|
| 96 |
+
st.download_button(
|
| 97 |
+
label="Download data as CSV",
|
| 98 |
+
data=csv,
|
| 99 |
+
file_name='Total followers.csv',
|
| 100 |
+
mime='text/csv',
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
st.write('Trending videos.xlsx')
|
| 104 |
+
st.write(trendingvideos)
|
| 105 |
+
#converting the sample dataframe
|
| 106 |
+
csv = convert_df(trendingvideos)
|
| 107 |
+
#adding a download button to download csv file
|
| 108 |
+
st.download_button(
|
| 109 |
+
label="Download data as CSV",
|
| 110 |
+
data=csv,
|
| 111 |
+
file_name='Trending videos.csv',
|
| 112 |
+
mime='text/csv',
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
st.write('Video Posts.xlsx')
|
| 116 |
+
st.write(videoposts)
|
| 117 |
+
#converting the sample dataframe
|
| 118 |
+
csv = convert_df(videoposts)
|
| 119 |
+
#adding a download button to download csv file
|
| 120 |
+
st.download_button(
|
| 121 |
+
label="Download data as CSV",
|
| 122 |
+
data=csv,
|
| 123 |
+
file_name='Video Posts.csv',
|
| 124 |
+
mime='text/csv',
|
| 125 |
+
)
|
| 126 |
+
elif selected == "Analysis":
|
| 127 |
+
def plot_chart(data, chart_type, x_var, y_var, z_var=None, show_regression_line=False, show_r_squared=False):
|
| 128 |
+
scatter_marker_color = 'green'
|
| 129 |
+
regression_line_color = 'red'
|
| 130 |
+
if chart_type == "line":
|
| 131 |
+
fig = px.line(data, x=x_var, y=y_var)
|
| 132 |
+
|
| 133 |
+
elif chart_type == "bar":
|
| 134 |
+
fig = px.bar(data, x=x_var, y=y_var)
|
| 135 |
+
|
| 136 |
+
elif chart_type == "scatter":
|
| 137 |
+
fig = px.scatter(data, x=x_var, y=y_var, color_discrete_sequence=[scatter_marker_color])
|
| 138 |
+
|
| 139 |
+
if show_regression_line and x_var != 'Date':
|
| 140 |
+
X = data[x_var].values.reshape(-1, 1)
|
| 141 |
+
y = data[y_var].values.reshape(-1, 1)
|
| 142 |
+
model = LinearRegression().fit(X, y)
|
| 143 |
+
y_pred = model.predict(X)
|
| 144 |
+
r_squared = r2_score(y, y_pred) # Calculate R-squared value
|
| 145 |
+
|
| 146 |
+
fig.add_trace(
|
| 147 |
+
go.Scatter(x=data[x_var], y=y_pred[:, 0], mode='lines', name='Regression Line', line=dict(color=regression_line_color))
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
# Add R-squared value as a text annotation
|
| 151 |
+
fig.add_annotation(
|
| 152 |
+
x=data[x_var].max(),
|
| 153 |
+
y=y_pred[-1, 0],
|
| 154 |
+
text=f"R-squared: {r_squared:.4f}",
|
| 155 |
+
showarrow=False,
|
| 156 |
+
font=dict(size=14),
|
| 157 |
+
bgcolor='rgba(255, 255, 255, 0.8)',
|
| 158 |
+
bordercolor='black',
|
| 159 |
+
borderwidth=1,
|
| 160 |
+
borderpad=4
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
elif chart_type == "heatmap":
|
| 164 |
+
fig = px.imshow(data, color_continuous_scale='Inferno')
|
| 165 |
+
|
| 166 |
+
elif chart_type == "scatter_3d":
|
| 167 |
+
if z_var is not None:
|
| 168 |
+
fig = px.scatter_3d(data, x=x_var, y=y_var, z=z_var, color=data.columns[0])
|
| 169 |
+
else:
|
| 170 |
+
st.warning("Please select Z variable for 3D line plot.")
|
| 171 |
+
return
|
| 172 |
+
|
| 173 |
+
elif chart_type == "line_3d":
|
| 174 |
+
if z_var is not None:
|
| 175 |
+
fig = go.Figure(data=[go.Scatter3d(x=data[x_var], y=data[y_var], z=data[z_var], mode='lines')])
|
| 176 |
+
fig.update_layout(scene=dict(xaxis_title=x_var, yaxis_title=y_var, zaxis_title=z_var)) # Set the axis name
|
| 177 |
+
else:
|
| 178 |
+
st.warning("Please select Z variable for 3D line plot.")
|
| 179 |
+
return
|
| 180 |
+
|
| 181 |
+
elif chart_type == "surface_3d":
|
| 182 |
+
if z_var is not None:
|
| 183 |
+
fig = go.Figure(data=[go.Surface(z=data.values)])
|
| 184 |
+
fig.update_layout(scene=dict(xaxis_title=x_var, yaxis_title=y_var, zaxis_title=z_var)) # Set the axis name
|
| 185 |
+
else:
|
| 186 |
+
st.warning("Please select Z variable for 3D line plot.")
|
| 187 |
+
return
|
| 188 |
+
|
| 189 |
+
elif chart_type == "radar":
|
| 190 |
+
fig = go.Figure()
|
| 191 |
+
for col in data.columns[1:]:
|
| 192 |
+
fig.add_trace(go.Scatterpolar(r=data[col], theta=data[x_var], mode='lines', name=col))
|
| 193 |
+
fig.update_layout(polar=dict(radialaxis=dict(visible=True, range=[data[data.columns[1:]].min().min(), data[data.columns[1:]].max().max()])))
|
| 194 |
+
|
| 195 |
+
st.plotly_chart(fig)
|
| 196 |
+
|
| 197 |
+
def plot_radar_chart(data, columns):
|
| 198 |
+
df = data[columns]
|
| 199 |
+
fig = go.Figure()
|
| 200 |
+
|
| 201 |
+
for i in range(len(df)):
|
| 202 |
+
date_label = data.loc[i, 'Date']
|
| 203 |
+
fig.add_trace(go.Scatterpolar(
|
| 204 |
+
r=df.loc[i].values,
|
| 205 |
+
theta=df.columns,
|
| 206 |
+
fill='toself',
|
| 207 |
+
name=date_label
|
| 208 |
+
))
|
| 209 |
+
|
| 210 |
+
fig.update_layout(
|
| 211 |
+
polar=dict(
|
| 212 |
+
radialaxis=dict(
|
| 213 |
+
visible=True,
|
| 214 |
+
range=[0, df.max().max()]
|
| 215 |
+
)
|
| 216 |
+
),
|
| 217 |
+
showlegend=True
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
st.plotly_chart(fig)
|
| 221 |
+
st.subheader("Analysis")
|
| 222 |
+
taba, tabb, tabc = st.tabs(["Overview", "Content", "Followers"])
|
| 223 |
+
with taba:
|
| 224 |
+
st.write("**Overview**")
|
| 225 |
+
|
| 226 |
+
data = pd.read_excel('gaming/Last 7 days.xlsx')
|
| 227 |
+
|
| 228 |
+
x_var = st.sidebar.selectbox("Select X variable for Last 7 days", data.columns)
|
| 229 |
+
y_var = st.sidebar.selectbox("Select Y variable for Last 7 days", data.columns)
|
| 230 |
+
show_regression_line = False
|
| 231 |
+
|
| 232 |
+
z_var_options = ["None"] + list(data.columns)
|
| 233 |
+
z_var = st.sidebar.selectbox("Select Z variable for 3D charts (if applicable)", z_var_options)
|
| 234 |
+
|
| 235 |
+
tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8 = st.tabs(["Line", "Bar", "Scatterplot", "Heatmap",
|
| 236 |
+
"3D Scatterplot", "3D Lineplot", "3D Surfaceplot", "Radar chart"])
|
| 237 |
+
with tab1:
|
| 238 |
+
st.write("Lineplot for 'Last 7 days'")
|
| 239 |
+
plot_chart(data, "line", x_var, y_var)
|
| 240 |
+
|
| 241 |
+
with tab2:
|
| 242 |
+
st.write("Barplot for 'Last 7 days'")
|
| 243 |
+
plot_chart(data, "bar", x_var, y_var)
|
| 244 |
+
|
| 245 |
+
with tab3:
|
| 246 |
+
st.write("Scatterplot for 'Last 7 days'")
|
| 247 |
+
show_regression_line = st.checkbox("Show regression line for Last 7 days scatterplot (does not apply when X = Date)")
|
| 248 |
+
plot_chart(data, "scatter", x_var, y_var, show_regression_line=show_regression_line)
|
| 249 |
+
|
| 250 |
+
with tab4:
|
| 251 |
+
st.write("Heatmap for 'Last 7 days'")
|
| 252 |
+
plot_chart(data, "heatmap", x_var, y_var)
|
| 253 |
+
|
| 254 |
+
with tab5:
|
| 255 |
+
st.write("3D Scatterplot for 'Last 7 days'")
|
| 256 |
+
if z_var != "None":
|
| 257 |
+
plot_chart(data, "scatter_3d", x_var, y_var, z_var)
|
| 258 |
+
|
| 259 |
+
with tab6:
|
| 260 |
+
st.write("3D Lineplot for 'Last 7 days'")
|
| 261 |
+
if z_var != "None":
|
| 262 |
+
plot_chart(data, "line_3d", x_var, y_var, z_var)
|
| 263 |
+
|
| 264 |
+
with tab7:
|
| 265 |
+
st.write("3D Surfaceplot for 'Last 7 days'")
|
| 266 |
+
if z_var != "None":
|
| 267 |
+
plot_chart(data, "surface_3d", x_var, y_var, z_var)
|
| 268 |
+
|
| 269 |
+
with tab8:
|
| 270 |
+
st.write("Radar chart for 'Last 60 days'")
|
| 271 |
+
radar_columns = ['Video views', 'Profile views', 'Likes', 'Comments', 'Shares']
|
| 272 |
+
plot_radar_chart(data, radar_columns)
|
| 273 |
+
# Add more conditions for other specific file names if needed
|
| 274 |
+
|
| 275 |
+
with tabb:
|
| 276 |
+
st.write("**Content**")
|
| 277 |
+
|
| 278 |
+
with tabc:
|
| 279 |
+
st.write("**Followers**")
|