forked from SBodapati11/DataMavericks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (91 loc) · 3.82 KB
/
main.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
import os
import numpy as np
import pandas as pd
import streamlit as st
import altair as alt
from PIL import Image
from SeasonDataFiltering import SeasonDataFiltering
from Matchups import Matchups
from Lineups import Lineups
# Players
players_mavs = ["Luka Doncic", "Kyrie Irving", "Justin Holiday", "Theo Pinson", "Jaden Hardy", "Dwight Powell",
"Josh Green", "Tim Hardaway Jr.", "Markieff Morris", "Frank Ntilikina", "Reggie Bullock",
"Christian Wood", "Maxi Kleber", "Davis Bertans", "Javale McGee", "AJ Lawson",
"Dorian Lawrence Finney-Smith", "Spencer Dinwiddie"]
# image folder
image_folder = "images"
# Define function for the third tab
def Shooting_Calculator():
st.header("Shooting Calculator")
st.write(f"<span style='color: blue'><b>Select Player</b></span>", unsafe_allow_html=True)
selected_player_1 = st.selectbox(" ", players_mavs, index=0)
basketball_shots = ['Jump Shot', 'Layup', 'Dunk', 'Hook Shot', 'Tip Shot', 'Alley-oop', 'Free Throw',
'Three-Pointer']
st.write(f"<span style='color: red'><b>Select a Shot</b></span>", unsafe_allow_html=True)
selected_shot = st.selectbox(" ", basketball_shots, index=0)
# TODO: Actually calculate the chance he has using a time series
estimated_chance = 99.875
# TODO: Make this graph take in actual data
# Generate sample data
time = pd.date_range("2022-01-01", periods=100, freq="1min")
y = np.random.randn(100)
y = np.abs(y) # Make all values positive
# Create two columns
col1, col2 = st.columns([1, 2])
# TODO: match selected_player_1 to its image mapping
with col1:
# after doing that, put them next to each other using an automatically pulled image
image_name = "{0}.png".format(selected_player_1.split()[0].lower())
image_path = os.path.join(image_folder, image_name)
selection = Image.open(image_path)
st.image(selection, use_column_width=True)
# Add line chart to the second column
with col2:
# Create dataframe with sample data
df = pd.DataFrame({"time": time, "y": y})
# Create line chart
line_chart = (
alt.Chart(df)
.mark_line(color="darkblue")
.encode(
x="time:T",
y="y:Q",
)
)
# Create filled area below the line chart
area_chart = (
alt.Chart(df)
.mark_area(color="lightblue", opacity=0.3)
.encode(
x="time:T",
y=alt.Y("y:Q", stack=None),
tooltip=["y:Q"],
)
)
# Combine the line chart and area chart
chart = line_chart + area_chart
# Set chart size and title
chart.properties(width=700, height=400, title="Sample Line Chart with Filled Area")
# Display the chart
st.altair_chart(chart, use_container_width=True)
# Add more code here for custom functionality
# Write Prediction
st.subheader("Prediction")
st.write(
f"<span style='color: blue'>{selected_player_1}</span> has a <b>{str(estimated_chance)}</b> chance of making a <b>{selected_shot}</b>.",
unsafe_allow_html=True)
# Define the Streamlit app layout
st.set_page_config(page_title="Data Mavericks", layout="wide")
image_name = "teams_logos/mavericks.png"
image_path = os.path.join(image_folder, image_name)
st.sidebar.image(image_path, width=200) # Add an image to the sidebar
st.sidebar.title("DataMavericks")
tabs = ["Lineups", "Matchups", "Player Shot Analysis"]
selected_tab = st.sidebar.radio("Navigation", tabs, index=0)
# Run the appropriate function based on the selected tab
if selected_tab == "Lineups":
Lineups()
elif selected_tab == "Matchups":
Matchups()
elif selected_tab == "Player Shot Analysis":
SeasonDataFiltering()