Commit
·
9147f5f
1
Parent(s):
5998f39
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ Install txtai and streamlit (>= 1.23) to run:
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
import datetime
|
|
|
|
| 9 |
import os
|
| 10 |
import random
|
| 11 |
|
|
@@ -92,18 +93,21 @@ class Stats:
|
|
| 92 |
|
| 93 |
# Get unique names
|
| 94 |
names = {}
|
| 95 |
-
rows = self.stats[["nameFirst", "nameLast", "playerID"]]
|
| 96 |
-
for
|
| 97 |
# Name key
|
| 98 |
key = f"{row['nameFirst']} {row['nameLast']}"
|
| 99 |
-
key += f" ({row['playerID']})" if key in names
|
| 100 |
|
| 101 |
if key not in names:
|
| 102 |
-
#
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
# Save name key - values pair
|
| 106 |
-
names[key] = (row["playerID"],
|
| 107 |
|
| 108 |
return names
|
| 109 |
|
|
@@ -492,9 +496,9 @@ class Application:
|
|
| 492 |
|
| 493 |
# Sync parameters with session state
|
| 494 |
if all(x in st.session_state for x in ["category", "name", "year"]):
|
| 495 |
-
#
|
| 496 |
-
params["year"] = str(st.session_state["year"]) if params[
|
| 497 |
-
|
| 498 |
# Copy category and name from session state
|
| 499 |
params["category"] = st.session_state["category"]
|
| 500 |
params["name"] = st.session_state["name"]
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
import datetime
|
| 9 |
+
import math
|
| 10 |
import os
|
| 11 |
import random
|
| 12 |
|
|
|
|
| 93 |
|
| 94 |
# Get unique names
|
| 95 |
names = {}
|
| 96 |
+
rows = self.stats.sort_values(by=self.metric(), ascending=False)[["nameFirst", "nameLast", "playerID"]].drop_duplicates().reset_index()
|
| 97 |
+
for x, row in rows.iterrows():
|
| 98 |
# Name key
|
| 99 |
key = f"{row['nameFirst']} {row['nameLast']}"
|
| 100 |
+
key += f" ({row['playerID']})" if key in names else ""
|
| 101 |
|
| 102 |
if key not in names:
|
| 103 |
+
# Scale scores of top n players
|
| 104 |
+
exponent = 2 if ((len(rows) - x) / len(rows)) >= 0.95 else 1
|
| 105 |
+
|
| 106 |
+
# score = num seasons ^ exponent
|
| 107 |
+
score = math.pow(len(self.stats[self.stats["playerID"] == row["playerID"]]), exponent)
|
| 108 |
|
| 109 |
# Save name key - values pair
|
| 110 |
+
names[key] = (row["playerID"], score)
|
| 111 |
|
| 112 |
return names
|
| 113 |
|
|
|
|
| 496 |
|
| 497 |
# Sync parameters with session state
|
| 498 |
if all(x in st.session_state for x in ["category", "name", "year"]):
|
| 499 |
+
# Copy session year if category and name are unchanged
|
| 500 |
+
params["year"] = str(st.session_state["year"]) if all(params[x] == st.session_state[x] for x in ["category", "name"]) else None
|
| 501 |
+
|
| 502 |
# Copy category and name from session state
|
| 503 |
params["category"] = st.session_state["category"]
|
| 504 |
params["name"] = st.session_state["name"]
|