-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (55 loc) · 2.09 KB
/
Copy pathapp.py
File metadata and controls
75 lines (55 loc) · 2.09 KB
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
# """
# STREAMLIT DASHBOARD OF DARTBOT MATCHES
# """
import streamlit as st
import pandas as pd
import openpyxl
import plotly.express as px
# https://www.webfx.com/tools/emoji-cheat-sheet/
xlfile = r'D:\EXCEL\Dartbot matches.xlsx'
# st.set_page_config(page_title="Dartbot Matches 2022", page_icon=":bar_chart:", layout="wide")
st.set_page_config(page_title="Dartbot Matches 2022", page_icon=":bar_chart:")
df = pd.read_excel(io=xlfile,engine='openpyxl',sheet_name='Dartbot_matches')
df['Date'] = df['Date'].dt.strftime('%d-%m-%Y')
df.columns = df.columns.str.lower()
dates = df.date.unique()
# """
# -- MEAN OF 3-DART AVERAGE FOR EACH DARTBOT LEVEL
# """
db_level_3da = df.groupby('dartbot_level')['3-dart average'].mean().round(2)
# """
# -- COUNT OF MATCHES AT EACH LEVEL
# """
db_level_count = df.groupby('dartbot_level')['result'].count() # counts number of records at each dartbot level
db_level_result = df['result'].groupby(df['dartbot_level']).value_counts()
# """
# -- TABLE OF WIN %
# """
db_level_crosstab = pd.crosstab(df.dartbot_level,df.result,normalize='index') # normalize gives %age of total, in this case, % of all at that dartbot level, the first parameter
db_level_crosstab.drop('Lost', axis=1,inplace=True)
db_level_crosstab['Won'] *= 100
db_level_crosstab['Won'] = db_level_crosstab['Won'].round(decimals=0)
print(db_level_crosstab)
# """
# -- BAR CHART OF WIN %
# """
# dfb = px.data.tips()
fig = px.bar(db_level_crosstab, x="Won", orientation='h',
height=400,
labels={"dartbot_level" : "3-dart avg",
"Won" : "Win %"}
)
# fig.show()
# ---- HEADER SECTION ----
with st.container():
st.title("Dartbot Matches 2022")
st.subheader("First to 5 legs")
# st.bar_chart(db_level_crosstab)
st.header("Win % by Dartbot Level")
st.write(fig)
date = st.selectbox("Select date", df.date.unique())
match_result = st.selectbox("Select result", df.result.unique())
df_selection = df.query("date == @date & result == @match_result")
df_page = df_selection.transpose().astype(str)
st.table(df_page)
print(df.head())