Spaces:
Running
Running
Jon Solow
commited on
Commit
·
7ccb57f
1
Parent(s):
b90f26c
Map defensive players and show any unmatched
Browse files- src/pages/3_Draft_View.py +60 -12
- src/yahoo_client.py +5 -1
src/pages/3_Draft_View.py
CHANGED
|
@@ -14,7 +14,46 @@ def load_yahoo_to_fp_id_map() -> dict[str, str]:
|
|
| 14 |
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv")
|
| 15 |
for id_col in ["yahoo_id", "fantasypros_id"]:
|
| 16 |
df[id_col] = df[id_col].fillna(-9999).apply(lambda x: str(int(x)))
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def extract_ecr_var_data(request_text_str, var_name: str):
|
|
@@ -111,31 +150,40 @@ def get_page():
|
|
| 111 |
pd.DataFrame(league_settings.roster_positions).set_index("position")["count"],
|
| 112 |
)
|
| 113 |
|
| 114 |
-
draft_result =
|
| 115 |
if st.button("Load / Refresh"):
|
| 116 |
-
draft_result =
|
| 117 |
if "player_key" in draft_result:
|
| 118 |
draft_result["player_id"] = draft_result["player_key"].apply(lambda x: x.rsplit(".", 1)[-1] if x else x)
|
| 119 |
else:
|
| 120 |
draft_result["player_id"] = ""
|
| 121 |
-
draft_result["fp_id"] = draft_result["player_id"].apply(lambda x: load_yahoo_to_fp_id_map().get(x))
|
| 122 |
-
|
| 123 |
-
if "team_key" not in draft_result:
|
| 124 |
-
draft_result["team_key"] = ""
|
| 125 |
|
| 126 |
-
with st.expander("Show Draft Results"):
|
| 127 |
-
st.dataframe(draft_result)
|
| 128 |
-
|
| 129 |
-
st.header("ECR Tiers")
|
| 130 |
ecr_data = load_ecr_data()
|
| 131 |
draft_result_merge_cols = [
|
| 132 |
"fp_id",
|
| 133 |
"team_key",
|
|
|
|
|
|
|
| 134 |
]
|
|
|
|
|
|
|
|
|
|
| 135 |
ecr_with_draft = ecr_data.merge(
|
| 136 |
-
draft_result[draft_result_merge_cols], how="
|
| 137 |
)
|
| 138 |
ecr_with_draft["is_drafted"] = ecr_with_draft["fp_id"].notna()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
with st.expander("Filters"):
|
| 140 |
filtered_data = filter_dataframe(
|
| 141 |
ecr_with_draft, force_on=True, force_on_columns=["is_drafted", "player_position_id"]
|
|
|
|
| 14 |
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv")
|
| 15 |
for id_col in ["yahoo_id", "fantasypros_id"]:
|
| 16 |
df[id_col] = df[id_col].fillna(-9999).apply(lambda x: str(int(x)))
|
| 17 |
+
|
| 18 |
+
player_id_dict = df.set_index("yahoo_id")["fantasypros_id"].to_dict()
|
| 19 |
+
# map team DST
|
| 20 |
+
player_id_dict.update(
|
| 21 |
+
{
|
| 22 |
+
"100022": "8000", # Arizona
|
| 23 |
+
"100001": "8010", # Atlanta
|
| 24 |
+
"100033": "8020", # Baltimore
|
| 25 |
+
"100002": "8030", # Buffalo
|
| 26 |
+
"100029": "8040", # Carolina
|
| 27 |
+
"100003": "8050", # Chicago
|
| 28 |
+
"100004": "8060", # Cincinnati
|
| 29 |
+
"100005": "8070", # Cleveland
|
| 30 |
+
"100006": "8080", # Dallas
|
| 31 |
+
"100007": "8090", # Denver
|
| 32 |
+
"100008": "8100", # Detroit
|
| 33 |
+
"100009": "8110", # Green Bay
|
| 34 |
+
"100034": "8120", # Houston
|
| 35 |
+
"100011": "8130", # Indianapolis
|
| 36 |
+
"100030": "8140", # Jacksonville
|
| 37 |
+
"100012": "8150", # Kansas City
|
| 38 |
+
"100013": "8220", # Las Vegas
|
| 39 |
+
"100014": "8280", # Los Angeles Rams
|
| 40 |
+
"100024": "8250", # Los Angeles Chargers
|
| 41 |
+
"100015": "8160", # Miami
|
| 42 |
+
"100016": "8170", # Minnesota
|
| 43 |
+
"100017": "8180", # New England
|
| 44 |
+
"100018": "8190", # New Orleans
|
| 45 |
+
"100019": "8200", # New York Giants
|
| 46 |
+
"100020": "8210", # New York Jets
|
| 47 |
+
"100021": "8230", # Philadelphia
|
| 48 |
+
"100023": "8240", # Pittsburgh
|
| 49 |
+
"100025": "8270", # San Francisco
|
| 50 |
+
"100026": "8260", # Seattle
|
| 51 |
+
"100027": "8290", # Tampa Bay
|
| 52 |
+
"100010": "8300", # Tennessee
|
| 53 |
+
"100028": "8310", # Washington
|
| 54 |
+
}
|
| 55 |
+
)
|
| 56 |
+
return player_id_dict
|
| 57 |
|
| 58 |
|
| 59 |
def extract_ecr_var_data(request_text_str, var_name: str):
|
|
|
|
| 150 |
pd.DataFrame(league_settings.roster_positions).set_index("position")["count"],
|
| 151 |
)
|
| 152 |
|
| 153 |
+
draft_result = st.session_state.yahoo_client.get_draft(selected_league)
|
| 154 |
if st.button("Load / Refresh"):
|
| 155 |
+
draft_result = st.session_state.yahoo_client.get_draft(selected_league)
|
| 156 |
if "player_key" in draft_result:
|
| 157 |
draft_result["player_id"] = draft_result["player_key"].apply(lambda x: x.rsplit(".", 1)[-1] if x else x)
|
| 158 |
else:
|
| 159 |
draft_result["player_id"] = ""
|
| 160 |
+
draft_result["fp_id"] = draft_result["player_id"].apply(lambda x: load_yahoo_to_fp_id_map().get(x, x))
|
|
|
|
|
|
|
|
|
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
ecr_data = load_ecr_data()
|
| 163 |
draft_result_merge_cols = [
|
| 164 |
"fp_id",
|
| 165 |
"team_key",
|
| 166 |
+
"round",
|
| 167 |
+
"pick",
|
| 168 |
]
|
| 169 |
+
for col in draft_result_merge_cols:
|
| 170 |
+
if col not in draft_result:
|
| 171 |
+
draft_result[col] = ""
|
| 172 |
ecr_with_draft = ecr_data.merge(
|
| 173 |
+
draft_result[draft_result_merge_cols], how="outer", left_on="player_id", right_on="fp_id"
|
| 174 |
)
|
| 175 |
ecr_with_draft["is_drafted"] = ecr_with_draft["fp_id"].notna()
|
| 176 |
+
|
| 177 |
+
if ("round" in ecr_with_draft) and ("pick" in ecr_with_draft):
|
| 178 |
+
draft_picks_only = ecr_with_draft[ecr_with_draft.is_drafted].sort_values(["round", "pick"])
|
| 179 |
+
|
| 180 |
+
with st.expander("Show Draft Results"):
|
| 181 |
+
st.dataframe(draft_picks_only)
|
| 182 |
+
|
| 183 |
+
with st.expander("Unmatched"):
|
| 184 |
+
st.dataframe(ecr_with_draft[ecr_with_draft.player_name.isna()])
|
| 185 |
+
|
| 186 |
+
st.header("ECR Tiers")
|
| 187 |
with st.expander("Filters"):
|
| 188 |
filtered_data = filter_dataframe(
|
| 189 |
ecr_with_draft, force_on=True, force_on_columns=["is_drafted", "player_position_id"]
|
src/yahoo_client.py
CHANGED
|
@@ -130,7 +130,11 @@ class YahooFantasyClient:
|
|
| 130 |
}
|
| 131 |
for x in draft_results_xml.findall("./league/draft_results/*")
|
| 132 |
]
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
def parse_weeks_matchups(self, week: str, league_key: str) -> List[Mapping[str, Union[str, float]]]:
|
| 136 |
url = f"https://fantasysports.yahooapis.com/fantasy/v2/leagues;league_keys={league_key}/scoreboard;week={week}"
|
|
|
|
| 130 |
}
|
| 131 |
for x in draft_results_xml.findall("./league/draft_results/*")
|
| 132 |
]
|
| 133 |
+
df = pd.DataFrame(parsed_draft)
|
| 134 |
+
for col in ["round", "pick"]:
|
| 135 |
+
if col in df:
|
| 136 |
+
df[col] = df[col].astype(int)
|
| 137 |
+
return df
|
| 138 |
|
| 139 |
def parse_weeks_matchups(self, week: str, league_key: str) -> List[Mapping[str, Union[str, float]]]:
|
| 140 |
url = f"https://fantasysports.yahooapis.com/fantasy/v2/leagues;league_keys={league_key}/scoreboard;week={week}"
|