Spaces:
Sleeping
Sleeping
Jon Solow
commited on
Commit
·
6e3dcdf
1
Parent(s):
2988866
Allow to include in progress week
Browse files
src/analyze_yahoo.py
CHANGED
@@ -2,11 +2,14 @@ import pandas as pd
|
|
2 |
from typing import Optional
|
3 |
|
4 |
|
5 |
-
def calculate_luck(df: pd.DataFrame, as_of_week: Optional[int] = None) -> pd.DataFrame:
|
6 |
if as_of_week:
|
7 |
df_complete = df[df.week <= as_of_week]
|
8 |
else:
|
9 |
-
|
|
|
|
|
|
|
10 |
df_complete["actual_wins"] = df_complete["win_probability"].apply(lambda x: x > 0.5)
|
11 |
df_list = []
|
12 |
n_teams = df.team_name.nunique()
|
|
|
2 |
from typing import Optional
|
3 |
|
4 |
|
5 |
+
def calculate_luck(df: pd.DataFrame, as_of_week: Optional[int] = None, include_current: bool = False) -> pd.DataFrame:
|
6 |
if as_of_week:
|
7 |
df_complete = df[df.week <= as_of_week]
|
8 |
else:
|
9 |
+
status_list = ["postevent"]
|
10 |
+
if include_current:
|
11 |
+
status_list.append("midevent")
|
12 |
+
df_complete = df[df.matchup_status.isin(status_list)]
|
13 |
df_complete["actual_wins"] = df_complete["win_probability"].apply(lambda x: x > 0.5)
|
14 |
df_list = []
|
15 |
n_teams = df.team_name.nunique()
|
src/pages/51_League_Results_Summary.py
CHANGED
@@ -12,9 +12,9 @@ def get_all_league_settings_with_cache(season: int):
|
|
12 |
|
13 |
|
14 |
@st.cache_resource(ttl=60 * 10)
|
15 |
-
def get_cached_league_luck(league_key):
|
16 |
df_weekly_results = st.session_state.yahoo_client.full_schedule_dataframe(league_key)
|
17 |
-
df_weekly_luck = calculate_luck(df_weekly_results)
|
18 |
df_grouped_luck = get_grouped_luck(df_weekly_luck)
|
19 |
return df_weekly_results, df_weekly_luck, df_grouped_luck
|
20 |
|
@@ -37,7 +37,8 @@ def get_page():
|
|
37 |
selected_league = st.selectbox("Select league", user_leagues, format_func=lambda x: x.name)
|
38 |
st.header(f"{selected_league.name} - {selected_league.season}")
|
39 |
|
40 |
-
|
|
|
41 |
|
42 |
st.header("Weekly Top Half Scores")
|
43 |
luck_pivot = df_weekly_luck.pivot_table(
|
|
|
12 |
|
13 |
|
14 |
@st.cache_resource(ttl=60 * 10)
|
15 |
+
def get_cached_league_luck(league_key, include_current: bool):
|
16 |
df_weekly_results = st.session_state.yahoo_client.full_schedule_dataframe(league_key)
|
17 |
+
df_weekly_luck = calculate_luck(df_weekly_results, include_current=include_current)
|
18 |
df_grouped_luck = get_grouped_luck(df_weekly_luck)
|
19 |
return df_weekly_results, df_weekly_luck, df_grouped_luck
|
20 |
|
|
|
37 |
selected_league = st.selectbox("Select league", user_leagues, format_func=lambda x: x.name)
|
38 |
st.header(f"{selected_league.name} - {selected_league.season}")
|
39 |
|
40 |
+
check_current = st.checkbox("Include week in progress")
|
41 |
+
df_weekly_results, df_weekly_luck, df_luck = get_cached_league_luck(selected_league.league_key, check_current)
|
42 |
|
43 |
st.header("Weekly Top Half Scores")
|
44 |
luck_pivot = df_weekly_luck.pivot_table(
|