-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
233 lines (166 loc) · 8.19 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
import streamlit as st
import pandas as pd
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import plotly.graph_objects as go
import plotly.express as px
new = pd.read_excel("merged.xlsx")
st.set_page_config(page_title="KD 3198 Stats Dashboard",layout="wide")
def format_tick_label(x):
if abs(x) >= 1e9:
return f"{x / 1e9:.2f}B"
elif abs(x) >= 1e6:
return f"{x / 1e6:.2f}M"
else:
return str(x)
st.markdown("""
<style>
header{
visibility:hidden;
}
</style>
""",unsafe_allow_html=True)
@st.cache_data
def get_data_from_excel(option):
df = pd.read_excel("merged.xlsx")
kvk_mapping = {'KvK1': 1, 'kvk2': 2, 'kvk3': 3}
df['KvK Numeric'] = df['KvK'].map(kvk_mapping)
groups = df.groupby('Governor ID')
updated_dfs = []
for _, group in groups:
last_kvk_row = group.loc[group['KvK Numeric'].idxmin()]
group['Governor Name'] = last_kvk_row['Governor Name']
updated_dfs.append(group)
updated_df = pd.concat(updated_dfs)
updated_df.drop(columns=['KvK Numeric'], inplace=True)
y=updated_df
if option != "All Kvk":
if option.lower() != "kvk1":
updated_df = updated_df[updated_df['KvK'] == option.lower()]
else:
updated_df = updated_df[updated_df['KvK'] == "KvK1"]
return updated_df,y
def get_df_from_name(name):
if name != "All Names":
show_df = df_grouped.where(df_grouped["Governor Name"]==name).dropna()
pie_df = merged_df.where(merged_df["Governor Name"]==name).dropna()
return show_df,pie_df
def get_df_from_id(id):
if id != "All ID":
show_df = df_grouped.where(df_grouped["Governor ID"].astype(str)==id).dropna()
pie_df = merged_df.where(merged_df["Governor ID"].astype(str)==id).dropna()
else:
show_df = df_grouped
pie_df = merged_df
return show_df,pie_df
st.markdown("""
<style> .st-af {
font-size:20px;
}
p, ol, ul, dl {
font-size:22px; }
.st-emotion-cache-1avcm0n .ezrtsby2 {
visibility:hidden;
}
</style>
""",unsafe_allow_html=True)
pd.options.display.large_repr = 'truncate'
header_col1, header_col2, header_col3, header_col4 = st.columns(4)
kvk_list = ["All Kvk","KvK1", "KvK2", "KvK3"]
title = header_col1.markdown("<p style='font-size :48px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold; margin-left: 10px;'>Kingdom 3198</p>", unsafe_allow_html=True)
kvk = header_col2.selectbox("Kvk", options=kvk_list)
df,merged_df = get_data_from_excel(kvk)
try :
df=df.drop(columns=["Unnamed: 0"])
except:
pass
df["Governor ID"] = df["Governor ID"].astype(str)
df_grouped = df.groupby(["Governor ID", "Governor Name"]).sum()
df_grouped.reset_index(inplace=True)
id_options = df_grouped["Governor ID"].tolist()
name_options = df_grouped["Governor Name"].tolist()
name_options.sort()
id_options.insert(0, "All ID")
name_options.insert(0, "All Names")
df_grouped = df_grouped.sort_values(by="Total Kill Points",ascending=False).reset_index()
df_grouped=df_grouped.dropna()
df_grouped = df_grouped.drop(columns="index")
total_t4Kills = df_grouped["T4 Kills"].sum()
total_t5Kills = df_grouped["T5 Kills"].sum()
total_kills = df_grouped["T5-T4 Total Kills"].sum()
total_deads = df_grouped["Dead Gain"].sum()
table_df = merged_df.groupby(["KvK"],as_index=False).sum()
table_df = table_df.drop(columns=["Governor ID","T4 Kills","T5 Kills","Total Kill Points"])
id = header_col3.selectbox("ID", options=id_options,key="ID")
name = header_col4.selectbox("NAME", options=name_options,)
sub_title = header_col1.markdown("<p style='font-size :32px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold; margin-left: 10px;'>Data & Stats Tracking</p>", unsafe_allow_html=True)
if name != "All Names":
show_df,pie_df = get_df_from_name(name)
else:
show_df,pie_df = get_df_from_id(id)
col1, col2, col3 = st.columns(spec=[0.25,0.25,0.5],gap="large")
with col1:
st.markdown("<p style='font-size :20px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold; margin-left: 10px;'>Performance Breakdown</p>", unsafe_allow_html=True)
st.markdown("<p style='font-size :16px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold; margin-top:0;margin-bottom:5.5px ;margin-left: 10px;'>by Total Kills, T5 & T4 Kills, Dead Troops</p>", unsafe_allow_html=True)
st.header("Seperated T4 - T5 Kills")
st.subheader("Total T4 Kills")
st.info(f"{format_tick_label(total_t4Kills)}")
st.subheader("Total T5 Kills")
st.info(f"{format_tick_label(total_t5Kills)}")
with col2:
st.markdown("<p style='font-size :20px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold;visibility:hidden ;margin-left: 10px;'>Performance Breakdown</p>", unsafe_allow_html=True)
st.markdown("<p style='font-size :16px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold;visibility:hidden; margin-top:0;margin-bottom:5.5px ;margin-left: 10px;'>by Total Kills, T5 & T4 Kills, Dead Troops</p>", unsafe_allow_html=True)
st.header("Total Kill - Dead")
st.subheader("Total Kill Points")
st.info(f"{format_tick_label(total_kills)}")
st.subheader("Total Deads")
st.info(f"{format_tick_label(total_deads)}")
with col3:
st.markdown("<p style='font-size :20px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold;visibility:hidden ;margin-left: 10px;'>Performance Breakdown</p>", unsafe_allow_html=True)
st.markdown("<p style='font-size :16px; color: yellow; margin-right:20px; font-family: Tahoma, Verdana, sans-serif; font-weight: bold;visibility:hidden; margin-top:0;margin-bottom:5.5px ;margin-left: 10px;'>by Total Kills, T5 & T4 Kills, Dead Troops</p>", unsafe_allow_html=True)
fig = px.scatter(table_df, x="T5-T4 Total Kills", y="Dead Gain", color="KvK",
title=" KvK Performance",
labels={"T5-T4 Total Kills": "Total Kills ", "Dead Gain": "Total Deads ", "KvK ": "KvK"},
template="plotly_dark")
fig.update_traces(marker=dict(size=30, opacity=0.7))
fig.update_layout(xaxis=dict(
title='Total Kills',
tickfont=dict(size=12, color='yellow'),
gridcolor='black',
showline=True,
linewidth=2,
linecolor='orange'),
yaxis=dict(
title='Total Deads',
tickfont=dict(size=12, color='orange'),
gridcolor='black',
showline=True,
linewidth=2,
linecolor='orange'),
plot_bgcolor='black',
font=dict(family="Arial", size=14, color="orange"))
# Display the scatter plot
st.plotly_chart(fig,use_container_width=True)
col4,col5,col6 = st.columns([0.6,0.3,0.3])
with col4:
st.dataframe(show_df,use_container_width=True)
with col5:
fig = px.pie(pie_df, values='T5-T4 Total Kills', names='KvK', title=f'T5-T4 Kill Distribution',
template='plotly_dark')
fig.update_traces(marker=dict(colors=['#1f77b4', '#ff7f0e', '#2ca02c'], line=dict(color='#000000', width=2)))
st.plotly_chart(fig, use_container_width=True)
# Animated pie chart for Dead Gain
with col6:
fig = px.pie(pie_df, values='Dead Gain', names='KvK', title=f'Dead Distribution',
template='plotly_dark')
fig.update_traces(marker=dict(colors=['#1f77b4', '#ff7f0e', '#2ca02c'], line=dict(color='#000000', width=2)))
st.plotly_chart(fig, use_container_width=True)
def format_tick_label(x):
if abs(x) >= 1e9:
return f"{x / 1e9:.2f}B"
elif abs(x) >= 1e6:
return f"{x / 1e6:.2f}M"
else:
return str(x)