Jon Solow commited on
Commit
73408d5
·
1 Parent(s): c52156b

Revert "Revert "Replace the hack id map for yahoo player ids to gsis_id""

Browse files

This reverts commit c52156b18324e94eb7ebd2530422b8cce4341372.

Files changed (1) hide show
  1. src/stats.py +9 -14
src/stats.py CHANGED
@@ -229,19 +229,14 @@ YAHOO_TO_STAT_MAP: dict[str, dict[str, str]] = {
229
  }
230
 
231
 
232
- # HACK find permanent source of this map
233
- YAHOO_PLAYER_ID_MAP = {
234
- "30123": "00-0033873", # Patrick Mahomes
235
- "28654": "00-0031687", # Raheem Mostert
236
- "29399": "00-0033040", # Tyreek
237
- "31093": "00-0034798", # Durham Smythe
238
- "31199": "00-0034794", # Jason Sanders
239
- "30142": "00-0033885", # David Njoku
240
- "29792": "00-0032726", # Fairbairn
241
- "34207": "00-0037197", # Pacheco
242
- "26686": "00-0030506", # Kelce
243
- "30346": "00-0033303", # Butker
244
- }
245
 
246
  # happens to be the same
247
  YAHOO_WEEK_MAP = NFLVERSE_STAT_WEEK_TO_PLAYOFF_WEEK
@@ -274,7 +269,7 @@ def add_yahoo_stat_type_to_stat_map(
274
  player_id = short_team_names_to_player_id[player["player"]["team"]["abbreviation"]]
275
  else:
276
  raw_player_id = player["player"]["playerId"].split(".")[-1]
277
- player_id = YAHOO_PLAYER_ID_MAP.get(raw_player_id, raw_player_id)
278
 
279
  if player_id not in stat_map[week]:
280
  stat_map[week][player_id] = {}
 
229
  }
230
 
231
 
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
+
 
 
 
 
 
240
 
241
  # happens to be the same
242
  YAHOO_WEEK_MAP = NFLVERSE_STAT_WEEK_TO_PLAYOFF_WEEK
 
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, raw_player_id)
273
 
274
  if player_id not in stat_map[week]:
275
  stat_map[week][player_id] = {}