Skip to content

Commit

Permalink
Merge pull request #9 from ttan06/Alex_update
Browse files Browse the repository at this point in the history
Added pyproject toml and requirements files. Also updated UI
  • Loading branch information
Alexander-Schad authored Mar 8, 2024
2 parents 1662f04 + 3561b7b commit 50419a2
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 11 deletions.
122 changes: 111 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from dash import Dash, html, dcc, callback, Output, Input, dash_table, no_update
import plotly.express as px
import plotly.graph_objects as go
import dash_bootstrap_components as dbc
import pandas as pd
import numpy as np
from datetime import date
from makeRoute.makeRoute import route_creator, game_finder, schedule_builder

df = pd.read_csv('data/final_mlb_schedule.csv')

schedule = df.copy()
schedule['date'] = pd.to_datetime(schedule['date'])
print(schedule['home team'].unique().tolist())

# Original graph with no paths added
fig = go.Figure(go.Scattermapbox(
Expand All @@ -25,10 +28,43 @@
'style': "open-street-map",
'zoom': 3})

app = Dash(__name__)

app.layout = html.Div([
html.H1(children='Baseball Travel', style={'textAlign':'center'}),
app = Dash(__name__, external_stylesheets=[dbc.themes.COSMO])

SIDEBAR_STYLE = {
"position": "fixed",
"top": 0,
"left": 0,
"bottom": 0,
"width": "20rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
}
# sidebar = html.Div(
# [
# html.H2("Sidebar", className="display-4"),
# html.Hr(),
# html.P(
# "A simple sidebar layout with navigation links", className="lead"
# ),
# dbc.Nav(
# [
# dbc.NavLink("Home", href="/", active="exact"),
# dbc.NavLink("Page 1", href="/page-1", active="exact"),
# dbc.NavLink("Page 2", href="/page-2", active="exact"),
# ],
# vertical=True,
# pills=True,
# ),
# ],
# style=SIDEBAR_STYLE,
# )
CONTENT_STYLE = {
"margin-left": "22rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
}

selection_sidebar = html.Div([
dcc.DatePickerRange(
# date range
id='date-selection',
Expand All @@ -39,13 +75,18 @@
),
dcc.Dropdown(
# Shows all teams in a drop down list to choose from
df['home team'].unique(),
np.sort(df['home team'].unique()),
multi=True,
id='dropdown-selection',
placeholder="Select teams you wish to visit"),
placeholder="Select teams you wish to visit")],
style=SIDEBAR_STYLE,)

content = html.Div([ dcc.Graph(figure=fig,id='graph-content'),
dash_table.DataTable(id = 'table')]
, style=CONTENT_STYLE)

dcc.Graph(figure=fig,id='graph-content'),
dash_table.DataTable(id = 'table')
app.layout = html.Div([html.H1(children='Baseball Travel', style={'textAlign':'center'}),
selection_sidebar,content
])


Expand Down Expand Up @@ -79,10 +120,17 @@ def update_graph(value, start_date, end_date):
g1 = game_finder(schedule, r1[0], start_date, end_date)
sched = (schedule_builder(g1, r1[0]))


team_lons = sched['Longitude'].tolist()
team_lats = sched['Latitude'].tolist()
team_home = sched['home team'].tolist()
team_away = sched['away team'].tolist()
order = list(range(len(sched)))
order_final = []
for x in order :
order_final.append(str(x+1))

sched['date'] = sched['date'].dt.strftime('%m-%d-%Y')
dates = sched['date'].tolist()
time = sched['time'].tolist()
hover_data_zipped = list(zip(team_home,team_away,dates,time))
Expand All @@ -94,19 +142,70 @@ def update_graph(value, start_date, end_date):


fig = go.Figure(go.Scattermapbox(
mode = "markers+lines",
mode = "markers+lines+text",
lon = team_lons,
lat = team_lats,
hovertext=hover_data_format,
hoverinfo="text",
text=order_final,
textposition='top center',
# textposition='TopCenter',
marker = {'size': 10}))


fig.update_layout(
margin ={'l':0,'t':0,'b':0,'r':0},
mapbox = {
'center': {'lat': 37.0902, 'lon': -95.7129},
'style': "open-street-map",
'zoom': 3})
'zoom': 3},
font=dict(
family="Courier New, monospace",
size=25, # Set the font size here
color="RebeccaPurple")
)

team_to_image_map = {
'San Diego Padres':"", 'Chicago Cubs':"", 'Los Angeles Dodgers':"",
'Texas Rangers':"", 'Colorado Rockies':"",
'Baltimore Orioles': "https://upload.wikimedia.org/wikipedia/commons/e/e9/Baltimore_Orioles_Script.svg",
'Detroit Tigers':"", 'Minnesota Twins':"", 'St. Louis Cardinals':"",
'Tampa Bay Rays':"", 'Toronto Blue Jays':"", 'New York Mets':"",
'Chicago White Sox':"", 'Cleveland Guardians':"", 'Kansas City Royals':"",
'Oakland Athletics':"", 'San Francisco Giants':"", 'Los Angeles Angels':"",
"Arizona D'Backs":"https://loodibee.com/wp-content/uploads/mlb-arizona-diamondbacks-logo.png",
'Washington Nationals':"", 'Atlanta Braves':"", 'Boston Red Sox':"",
'Pittsburgh Pirates':"", 'Philadelphia Phillies':"", 'Houston Astros':"",
'New York Yankees':"", 'Miami Marlins':"", 'Cincinnati Reds':"", 'Milwaukee Brewers':"",
'Seattle Mariners':"",
}

for x_ind, y_ind, team in sched[["Longitude","Latitude","home team"]].values:
fig.add_layout_image(
dict(
source=team_to_image_map[team],
# xref="x domain",
# yref="y domain",
# xanchor="right",
# yanchor="top",
x=1,
y=1,
# sizex=2,
# sizey=2,
# sizing="contain",
# opacity=1.0,
layer="above",
)
# layout=go.Layout(
# xaxis = {
# 'showgrid': False
# },
# yaxis = {
# 'showgrid': True
# })
# ),
)

return fig

@callback(
Expand All @@ -126,7 +225,8 @@ def update_table(value, start_date, end_date):
g1 = game_finder(schedule, r1[0], start_date, end_date)
sched = (schedule_builder(g1, r1[0]))
sched = sched[['date', 'time', 'away team', 'home team']]
sched['date'] = sched['date'].dt.strftime('%m-%d-%Y')
return sched.to_dict("records")

if __name__ == '__main__':
app.run(debug=True)
app.run(debug=False)
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "baseball_travel"
authors = [
{name = "Alexander Schad", email = "[email protected]"},
]
description = "My package description"
readme = "README.md"
requires-python = ">=3.8"
keywords = ["one", "two"]
license = {text = "BSD-3-Clause"}
classifiers = [
"Framework :: Django",
"Programming Language :: Python :: 3",
]
dependencies = [
"requests",
'importlib-metadata; python_version<"3.10"',
]
dynamic = ["version"]

[project.optional-dependencies]
pdf = ["ReportLab>=1.2", "RXP"]
rest = ["docutils>=0.3", "pack ==1.1, ==1.3"]

[project.scripts]
my-script = "my_package.module:function"
15 changes: 15 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-arm64

contourpy==1.0.6
numpy==1.26.4
pylint==3.0.3
plotly==5.19.0
dash==2.15.0
dash-bootstrap-components==1.5.0
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
pandas==2.2.0
python_tsp==0.4.1

0 comments on commit 50419a2

Please sign in to comment.