Skip to content

Commit

Permalink
Accounting for odd thanksgiving week
Browse files Browse the repository at this point in the history
  • Loading branch information
tefirman committed Oct 6, 2024
1 parent b13513b commit 4d04230
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions FantasySports/UltimateSurvivor.py
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ def __init__(self, season: int = datetime.datetime.now().year, schedule_loc: str
self.season = season
self.load_probs(schedule_loc)
self.load_picks(picks_loc)
self.week = int(self.picks.columns[-1].split('_')[-1][:-1]) + 1
self.week = int(self.picks.columns[-1].split('_')[-1][:-1]) + 1 if self.picks.shape[1] > 1 else 1
self.best_combos(limit)
self.season_sims(num_sims)

@@ -149,10 +149,15 @@ def best_combos(self, limit: int = 1000) -> pd.DataFrame:
if week == probs_tg.week.unique()[0]: # Thanksgiving
self.combos = pd.merge(left=self.combos,right=self.probs.loc[(self.probs.week == week) & (self.probs.prob >= 0.5),['dummy','team','prob']]\
.rename(columns={'team':f'team_{week}c','prob':f'prob_{week}c'}),how='inner',on='dummy')
self.combos = self.combos.loc[self.combos[f'team_{week}b'] < self.combos[f'team_{week}c']].reset_index(drop=True)
self.combos = self.combos.loc[self.combos[f'team_{week}a'].isin(probs_tg.team.tolist()) \
| self.combos[f'team_{week}b'].isin(probs_tg.team.tolist()) \
| self.combos[f'team_{week}c'].isin(probs_tg.team.tolist())].reset_index(drop=True)
if week%2 == 1:
self.combos.rename(columns={f'team_{week}c':f'team_{week}b'},inplace=True)
self.combos = self.combos.loc[self.combos[f'team_{week}a'].isin(probs_tg.team.tolist()) \
| self.combos[f'team_{week}b'].isin(probs_tg.team.tolist())].reset_index(drop=True)
else:
self.combos = self.combos.loc[self.combos[f'team_{week}b'] < self.combos[f'team_{week}c']].reset_index(drop=True)
self.combos = self.combos.loc[self.combos[f'team_{week}a'].isin(probs_tg.team.tolist()) \
| self.combos[f'team_{week}b'].isin(probs_tg.team.tolist()) \
| self.combos[f'team_{week}c'].isin(probs_tg.team.tolist())].reset_index(drop=True)
team_cols = [team for team in self.combos.columns if team.startswith('team_')]
self.combos = self.combos.loc[self.combos[team_cols].nunique(axis=1) >= len(team_cols) - int(week >= 12)].reset_index(drop=True)
self.combos['tot_prob'] = self.combos[[team for team in self.combos.columns if team.startswith('prob_')]].sum(axis=1)

0 comments on commit 4d04230

Please sign in to comment.