Jon Solow commited on
Commit
eeb8c5f
·
1 Parent(s): a0f3421

Get stat overrides from google sheet

Browse files
Files changed (2) hide show
  1. src/login.py +20 -0
  2. src/stats.py +17 -7
src/login.py CHANGED
@@ -148,3 +148,23 @@ def get_logged_in_user_name_email() -> tuple[str | None, str | None]:
148
  email = user_info_map.get("email")
149
  name = user_info_map.get("name")
150
  return email, name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  email = user_info_map.get("email")
149
  name = user_info_map.get("name")
150
  return email, name
151
+
152
+
153
+ # hack - data overrides for stats allowing for quick manual edits
154
+ def get_stat_overrides() -> dict[int, dict[str, dict[str, float]]]:
155
+ df = conn.read(
156
+ worksheet="stats-overrides",
157
+ ttl="10m",
158
+ usecols=[0, 1, 2, 3],
159
+ )
160
+ stat_overrides_map: dict[int, dict[str, dict[str, float]]] = {w: {} for w in df.week.values}
161
+
162
+ for week, df_week in df.groupby("week"):
163
+ for player_id, df_player in df_week.groupby("player_id"):
164
+ if player_id not in stat_overrides_map[week]:
165
+ stat_overrides_map[week][player_id] = {}
166
+ for row in df_player.itertuples():
167
+ if row.stat_key and row.stat_value:
168
+ stat_overrides_map[week][player_id][row.stat_key] = float(row.stat_value)
169
+
170
+ return stat_overrides_map
src/stats.py CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
3
  import streamlit as st
4
 
5
  from domain.playoffs import PLAYOFF_TEAM_DEF_PLAYER
 
6
  from queries.nflverse.github_data import get_player_kicking_stats, get_player_stats, get_team_defense_stats
7
 
8
 
@@ -37,13 +38,13 @@ DEF_INT = StatType(key="DEF INT", score=2.0)
37
  FUM_REC = StatType(key="FUM REC", score=2.0)
38
  SAFETY = StatType(key="SAFETY", score=2.0)
39
  SACK = StatType(key="SACK", score=1.0)
40
- PTS_ALLOW_0 = StatType(key="PTS ALLOW 0", score=10.0)
41
- PTS_ALLOW_1_6 = StatType(key="PTS ALLOW 1-6", score=7.0)
42
- PTS_ALLOW_7_13 = StatType(key="PTS ALLOW 7-13", score=4.0)
43
- PTS_ALLOW_14_20 = StatType(key="PTS ALLOW 14-20", score=1.0)
44
- PTS_ALLOW_21_27 = StatType(key="PTS ALLOW 21-27", score=0.0)
45
- PTS_ALLOW_28_34 = StatType(key="PTS ALLOW 28-34", score=-1.0)
46
- PTS_ALLOW_35_ = StatType(key="PTS ALLOW 35+", score=-4.0)
47
  TEAM_WIN = StatType(key="TEAM WIN", score=5.0)
48
  ST_TD = StatType(key="ST TD", score=6.0)
49
 
@@ -202,6 +203,15 @@ def get_stats_map() -> dict[int, dict[str, dict[str, float]]]:
202
  for player_id, player_stats in week_stats.items():
203
  stat_map[week][player_id] = player_stats
204
 
 
 
 
 
 
 
 
 
 
205
  return stat_map
206
 
207
 
 
3
  import streamlit as st
4
 
5
  from domain.playoffs import PLAYOFF_TEAM_DEF_PLAYER
6
+ from login import get_stat_overrides
7
  from queries.nflverse.github_data import get_player_kicking_stats, get_player_stats, get_team_defense_stats
8
 
9
 
 
38
  FUM_REC = StatType(key="FUM REC", score=2.0)
39
  SAFETY = StatType(key="SAFETY", score=2.0)
40
  SACK = StatType(key="SACK", score=1.0)
41
+ PTS_ALLOW_0 = StatType(key="PTS 0", score=10.0)
42
+ PTS_ALLOW_1_6 = StatType(key="PTS 1-6", score=7.0)
43
+ PTS_ALLOW_7_13 = StatType(key="PTS 7-13", score=4.0)
44
+ PTS_ALLOW_14_20 = StatType(key="PTS 14-20", score=1.0)
45
+ PTS_ALLOW_21_27 = StatType(key="PTS 21-27", score=0.0)
46
+ PTS_ALLOW_28_34 = StatType(key="PTS 28-34", score=-1.0)
47
+ PTS_ALLOW_35_ = StatType(key="PTS 35+", score=-4.0)
48
  TEAM_WIN = StatType(key="TEAM WIN", score=5.0)
49
  ST_TD = StatType(key="ST TD", score=6.0)
50
 
 
203
  for player_id, player_stats in week_stats.items():
204
  stat_map[week][player_id] = player_stats
205
 
206
+ stat_overrides = get_stat_overrides()
207
+ # for stat overrides, override at the stat level
208
+ for week, week_stats in stat_overrides.items():
209
+ for player_id, player_stats in week_stats.items():
210
+ for stat_key, stat_value in player_stats.items():
211
+ if player_id not in stat_map[week]:
212
+ stat_map[week][player_id] = {}
213
+ stat_map[week][player_id][stat_key] = stat_value
214
+
215
  return stat_map
216
 
217