davidmezzetti
commited on
Commit
•
bd3257d
1
Parent(s):
6517523
Update app.py
Browse files
app.py
CHANGED
@@ -188,7 +188,6 @@ class Stats:
|
|
188 |
if uid[4:] not in ids:
|
189 |
result = self.data[uid].copy()
|
190 |
result["link"] = f'https://www.baseball-reference.com/players/{result["nameLast"].lower()[0]}/{result["bbrefID"]}.shtml'
|
191 |
-
result["yearID"] = str(result["yearID"])
|
192 |
results.append(result)
|
193 |
ids.add(uid[4:])
|
194 |
|
@@ -445,7 +444,15 @@ class Application:
|
|
445 |
"""
|
446 |
)
|
447 |
|
448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
|
450 |
def player(self):
|
451 |
"""
|
@@ -478,11 +485,36 @@ class Application:
|
|
478 |
results = stats.search(name, year)
|
479 |
|
480 |
# Display results
|
481 |
-
self.table(results, ["nameFirst", "nameLast", "teamID"] + stats.columns[1:]
|
482 |
-
|
483 |
# Save parameters
|
484 |
st.experimental_set_query_params(category=category, name=name, year=year)
|
485 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
def params(self):
|
487 |
"""
|
488 |
Get application parameters. This method combines URL parameters with session parameters.
|
@@ -607,7 +639,20 @@ class Application:
|
|
607 |
"""
|
608 |
|
609 |
if results:
|
610 |
-
st.dataframe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
else:
|
612 |
st.write("Player-Year not found")
|
613 |
|
|
|
188 |
if uid[4:] not in ids:
|
189 |
result = self.data[uid].copy()
|
190 |
result["link"] = f'https://www.baseball-reference.com/players/{result["nameLast"].lower()[0]}/{result["bbrefID"]}.shtml'
|
|
|
191 |
results.append(result)
|
192 |
ids.add(uid[4:])
|
193 |
|
|
|
444 |
"""
|
445 |
)
|
446 |
|
447 |
+
player, search = st.tabs(["Player", "Search"])
|
448 |
+
|
449 |
+
# Player tab
|
450 |
+
with player:
|
451 |
+
self.player()
|
452 |
+
|
453 |
+
# Search
|
454 |
+
with search:
|
455 |
+
self.search()
|
456 |
|
457 |
def player(self):
|
458 |
"""
|
|
|
485 |
results = stats.search(name, year)
|
486 |
|
487 |
# Display results
|
488 |
+
self.table(results, ["link", "nameFirst", "nameLast", "teamID"] + stats.columns[1:])
|
489 |
+
|
490 |
# Save parameters
|
491 |
st.experimental_set_query_params(category=category, name=name, year=year)
|
492 |
|
493 |
+
def search(self):
|
494 |
+
"""
|
495 |
+
Stats search tab.
|
496 |
+
"""
|
497 |
+
|
498 |
+
st.markdown("Find players with similar statistics.")
|
499 |
+
|
500 |
+
category = self.category("Batting", "searchcategory")
|
501 |
+
with st.form("search"):
|
502 |
+
if category == "Batting":
|
503 |
+
stats, columns = self.batting, self.batting.columns[:-6]
|
504 |
+
elif category == "Pitching":
|
505 |
+
stats, columns = self.pitching, self.pitching.columns[:-2]
|
506 |
+
|
507 |
+
# Enter stats with data editor
|
508 |
+
inputs = st.data_editor(pd.DataFrame([dict((column, None) for column in columns)]), hide_index=True).astype(float)
|
509 |
+
|
510 |
+
submitted = st.form_submit_button("Search")
|
511 |
+
if submitted:
|
512 |
+
# Run search
|
513 |
+
results = stats.search(row=inputs.to_dict(orient="records")[0])
|
514 |
+
|
515 |
+
# Display table
|
516 |
+
self.table(results, ["link", "nameFirst", "nameLast", "teamID"] + stats.columns[1:])
|
517 |
+
|
518 |
def params(self):
|
519 |
"""
|
520 |
Get application parameters. This method combines URL parameters with session parameters.
|
|
|
639 |
"""
|
640 |
|
641 |
if results:
|
642 |
+
st.dataframe(
|
643 |
+
results,
|
644 |
+
column_order=columns,
|
645 |
+
column_config={
|
646 |
+
"link": st.column_config.LinkColumn("Link", width="small"),
|
647 |
+
"yearID": st.column_config.NumberColumn("Year", format="%d"),
|
648 |
+
"nameFirst": "First",
|
649 |
+
"nameLast": "Last",
|
650 |
+
"teamID": "Team",
|
651 |
+
"age": "Age",
|
652 |
+
"weight": "Weight",
|
653 |
+
"height": "Height",
|
654 |
+
},
|
655 |
+
)
|
656 |
else:
|
657 |
st.write("Player-Year not found")
|
658 |
|