Jon Solow
commited on
Commit
·
4d036d6
1
Parent(s):
73408d5
Filter to id map to players on teams in playoffs
Browse files- src/domain/teams.py +10 -0
- src/stats.py +6 -2
src/domain/teams.py
CHANGED
@@ -12,6 +12,7 @@ class NFLTeam:
|
|
12 |
city: str
|
13 |
division: divisions.NFLDivision
|
14 |
footballguys_short_name: str = ""
|
|
|
15 |
rosters_short_name: str = ""
|
16 |
url: str = ""
|
17 |
injury_report_suffix: str = "/team/injury-report/"
|
@@ -20,6 +21,7 @@ class NFLTeam:
|
|
20 |
self.footballguys_short_name = (
|
21 |
self.team_short_name if self.footballguys_short_name == "" else self.footballguys_short_name
|
22 |
)
|
|
|
23 |
self.rosters_short_name = self.team_short_name if self.rosters_short_name == "" else self.rosters_short_name
|
24 |
self.conference: NFLConference = self.division.conference
|
25 |
self.injury_report_url = urljoin(self.url, self.injury_report_suffix)
|
@@ -125,6 +127,7 @@ green_bay_packers = NFLTeam(
|
|
125 |
city="Green Bay",
|
126 |
division=divisions.NFCNorth,
|
127 |
url="https://www.packers.com/",
|
|
|
128 |
)
|
129 |
|
130 |
houston_texans = NFLTeam(
|
@@ -149,6 +152,7 @@ jacksonville_jaguars = NFLTeam(
|
|
149 |
team_short_name="JAX",
|
150 |
division=divisions.AFCSouth,
|
151 |
url="https://www.jaguars.com/",
|
|
|
152 |
)
|
153 |
|
154 |
kansas_city_chiefs = NFLTeam(
|
@@ -157,6 +161,7 @@ kansas_city_chiefs = NFLTeam(
|
|
157 |
team_short_name="KC",
|
158 |
division=divisions.AFCWest,
|
159 |
url="https://www.chiefs.com/",
|
|
|
160 |
)
|
161 |
|
162 |
las_vegas_raiders = NFLTeam(
|
@@ -165,6 +170,7 @@ las_vegas_raiders = NFLTeam(
|
|
165 |
team_short_name="LV",
|
166 |
division=divisions.AFCWest,
|
167 |
url="https://www.raiders.com/",
|
|
|
168 |
)
|
169 |
|
170 |
los_angeles_chargers = NFLTeam(
|
@@ -206,6 +212,7 @@ new_england_patriots = NFLTeam(
|
|
206 |
team_short_name="NE",
|
207 |
division=divisions.AFCEast,
|
208 |
url="https://www.patriots.com/",
|
|
|
209 |
)
|
210 |
|
211 |
new_orleans_saints = NFLTeam(
|
@@ -214,6 +221,7 @@ new_orleans_saints = NFLTeam(
|
|
214 |
team_short_name="NO",
|
215 |
division=divisions.NFCSouth,
|
216 |
url="https://www.neworleanssaints.com/",
|
|
|
217 |
)
|
218 |
|
219 |
new_york_giants = NFLTeam(
|
@@ -254,6 +262,7 @@ san_francisco_49ers = NFLTeam(
|
|
254 |
team_short_name="SF",
|
255 |
division=divisions.NFCWest,
|
256 |
url="https://www.49ers.com/",
|
|
|
257 |
)
|
258 |
|
259 |
seattle_seahawks = NFLTeam(
|
@@ -270,6 +279,7 @@ tampa_bay_buccaneers = NFLTeam(
|
|
270 |
team_short_name="TB",
|
271 |
division=divisions.NFCSouth,
|
272 |
url="https://www.buccaneers.com/",
|
|
|
273 |
)
|
274 |
|
275 |
tennessee_titans = NFLTeam(
|
|
|
12 |
city: str
|
13 |
division: divisions.NFLDivision
|
14 |
footballguys_short_name: str = ""
|
15 |
+
id_map_short_name: str = ""
|
16 |
rosters_short_name: str = ""
|
17 |
url: str = ""
|
18 |
injury_report_suffix: str = "/team/injury-report/"
|
|
|
21 |
self.footballguys_short_name = (
|
22 |
self.team_short_name if self.footballguys_short_name == "" else self.footballguys_short_name
|
23 |
)
|
24 |
+
self.id_map_short_name = self.team_short_name if self.id_map_short_name == "" else self.id_map_short_name
|
25 |
self.rosters_short_name = self.team_short_name if self.rosters_short_name == "" else self.rosters_short_name
|
26 |
self.conference: NFLConference = self.division.conference
|
27 |
self.injury_report_url = urljoin(self.url, self.injury_report_suffix)
|
|
|
127 |
city="Green Bay",
|
128 |
division=divisions.NFCNorth,
|
129 |
url="https://www.packers.com/",
|
130 |
+
id_map_short_name="GBP",
|
131 |
)
|
132 |
|
133 |
houston_texans = NFLTeam(
|
|
|
152 |
team_short_name="JAX",
|
153 |
division=divisions.AFCSouth,
|
154 |
url="https://www.jaguars.com/",
|
155 |
+
id_map_short_name="JAC",
|
156 |
)
|
157 |
|
158 |
kansas_city_chiefs = NFLTeam(
|
|
|
161 |
team_short_name="KC",
|
162 |
division=divisions.AFCWest,
|
163 |
url="https://www.chiefs.com/",
|
164 |
+
id_map_short_name="KCC",
|
165 |
)
|
166 |
|
167 |
las_vegas_raiders = NFLTeam(
|
|
|
170 |
team_short_name="LV",
|
171 |
division=divisions.AFCWest,
|
172 |
url="https://www.raiders.com/",
|
173 |
+
id_map_short_name="LVR",
|
174 |
)
|
175 |
|
176 |
los_angeles_chargers = NFLTeam(
|
|
|
212 |
team_short_name="NE",
|
213 |
division=divisions.AFCEast,
|
214 |
url="https://www.patriots.com/",
|
215 |
+
id_map_short_name="NEP",
|
216 |
)
|
217 |
|
218 |
new_orleans_saints = NFLTeam(
|
|
|
221 |
team_short_name="NO",
|
222 |
division=divisions.NFCSouth,
|
223 |
url="https://www.neworleanssaints.com/",
|
224 |
+
id_map_short_name="NOS",
|
225 |
)
|
226 |
|
227 |
new_york_giants = NFLTeam(
|
|
|
262 |
team_short_name="SF",
|
263 |
division=divisions.NFCWest,
|
264 |
url="https://www.49ers.com/",
|
265 |
+
id_map_short_name="SFO",
|
266 |
)
|
267 |
|
268 |
seattle_seahawks = NFLTeam(
|
|
|
279 |
team_short_name="TB",
|
280 |
division=divisions.NFCSouth,
|
281 |
url="https://www.buccaneers.com/",
|
282 |
+
id_map_short_name="TBB",
|
283 |
)
|
284 |
|
285 |
tennessee_titans = NFLTeam(
|
src/stats.py
CHANGED
@@ -232,8 +232,9 @@ YAHOO_TO_STAT_MAP: dict[str, dict[str, str]] = {
|
|
232 |
# cache id map for 24 hours
|
233 |
@st.cache_data(ttl=60 * 60 * 24)
|
234 |
def get_yahoo_id_map() -> dict[str, str]:
|
|
|
235 |
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv")
|
236 |
-
df = df[(df["yahoo_id"].notna() & df["gsis_id"].notna())]
|
237 |
df["yahoo_id"] = df["yahoo_id"].astype(int).astype(str)
|
238 |
return df.set_index("yahoo_id")["gsis_id"].to_dict()
|
239 |
|
@@ -269,7 +270,10 @@ def add_yahoo_stat_type_to_stat_map(
|
|
269 |
player_id = short_team_names_to_player_id[player["player"]["team"]["abbreviation"]]
|
270 |
else:
|
271 |
raw_player_id = player["player"]["playerId"].split(".")[-1]
|
272 |
-
player_id = get_yahoo_id_map().get(raw_player_id
|
|
|
|
|
|
|
273 |
|
274 |
if player_id not in stat_map[week]:
|
275 |
stat_map[week][player_id] = {}
|
|
|
232 |
# cache id map for 24 hours
|
233 |
@st.cache_data(ttl=60 * 60 * 24)
|
234 |
def get_yahoo_id_map() -> dict[str, str]:
|
235 |
+
teams_included = [x.id_map_short_name for x, _ in PLAYOFF_TEAM_DEF_PLAYER]
|
236 |
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv")
|
237 |
+
df = df[(df["yahoo_id"].notna() & df["gsis_id"].notna() & df["team"].isin(teams_included))]
|
238 |
df["yahoo_id"] = df["yahoo_id"].astype(int).astype(str)
|
239 |
return df.set_index("yahoo_id")["gsis_id"].to_dict()
|
240 |
|
|
|
270 |
player_id = short_team_names_to_player_id[player["player"]["team"]["abbreviation"]]
|
271 |
else:
|
272 |
raw_player_id = player["player"]["playerId"].split(".")[-1]
|
273 |
+
player_id = get_yahoo_id_map().get(raw_player_id)
|
274 |
+
|
275 |
+
if not player_id:
|
276 |
+
continue
|
277 |
|
278 |
if player_id not in stat_map[week]:
|
279 |
stat_map[week][player_id] = {}
|