Skip to content

Commit

Permalink
Updated Weekly Luck Record function to also calculate and report Seas…
Browse files Browse the repository at this point in the history
…on Luck Record and Ranking/Place
  • Loading branch information
cdpeca committed Oct 22, 2024
1 parent 9ef8e9c commit 6d34885
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
66 changes: 63 additions & 3 deletions report/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,71 @@ def create_pdf_report(self) -> Path:
)

# add weekly record to luck data

wins = 0
losses = 0

time_series_luck = {}

week_counter = 1

while week_counter <= self.league.week_for_report:
for team_luck_data_entry in report_data.data_for_luck:
for team in self.league.teams_by_week[str(week_counter)].values(): # type: BaseTeam
if team_luck_data_entry[1] == team.name:
wins = team.weekly_overall_record.get_wins()
losses = team.weekly_overall_record.get_losses()
if week_counter == 1:
time_series_luck[team.name] = {'name': team.name, 'wins': wins, 'losses': losses}
elif week_counter < self.league.week_for_report:
wins += time_series_luck[team.name]['wins']
losses += time_series_luck[team.name]['losses']
time_series_luck[team.name] = {'name': team.name, 'wins': wins, 'losses': losses}
else:
wins += time_series_luck[team.name]['wins']
losses += time_series_luck[team.name]['losses']
time_series_luck[team.name] = {'name': team.name, 'wins': wins, 'losses': losses}
week_counter += 1

# Calculate Season Luck Record and resolve ties

sorted_time_series_luck = dict(sorted(time_series_luck.items(), key=lambda x: list(x[1].values())[1], reverse=True))

team_index = 0

for i in sorted_time_series_luck:
team_index += 1
if team_index == 1:
previous_name = ""
name = sorted_time_series_luck[i]['name']
previous_wins = 0
wins = sorted_time_series_luck[i]['wins']
previous_losses = 0
losses = sorted_time_series_luck[i]['losses']
else:
previous_name = name
name = sorted_time_series_luck[i]['name']
previous_wins = wins
wins = sorted_time_series_luck[i]['wins']
previous_losses = losses
losses = sorted_time_series_luck[i]['losses']
if wins == previous_wins:
sorted_time_series_luck[i] = {'name': name, 'wins': wins, 'losses': losses, 'season_luck': str(team_index - 1) + "*"}
sorted_time_series_luck[previous_name] = {'name': previous_name, 'wins': previous_wins, 'losses': previous_losses, 'season_luck': str(team_index - 1) + "*"}
else:
sorted_time_series_luck[i] = {'name': name, 'wins': wins, 'losses': losses, 'season_luck': team_index}

# Append Weekly Luck Record along with Season Luck Record and Season Luck Record Ranking (Place)
for team_luck_data_entry in report_data.data_for_luck:
for team in self.league.teams_by_week[str(self.league.week_for_report)].values():
team: BaseTeam
for team in self.league.teams_by_week[str(self.league.week_for_report)].values(): # type: BaseTeam
if team_luck_data_entry[1] == team.name:
team_luck_data_entry.append(team.weekly_overall_record.get_record_str())
for i in sorted_time_series_luck:
if team_luck_data_entry[1] == sorted_time_series_luck[i]['name']:
name = sorted_time_series_luck[i]['name']
wins = sorted_time_series_luck[i]['wins']
losses = sorted_time_series_luck[i]['losses']
season_luck = sorted_time_series_luck[i]['season_luck']
team_luck_data_entry.append(team.weekly_overall_record.get_record_str() + " / " + str(wins) + "-" + str(losses) + " (" + str(season_luck) + ")")

# add season total optimal points to optimal points data
sorted_season_total_optimal_points_data = dict(sorted(season_total_optimal_points_data.items(), key=lambda x: x[1], reverse=True))
Expand Down
2 changes: 1 addition & 1 deletion report/pdf/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def __init__(self, season: int, league: BaseLeague, playoff_prob_sims: int,
self.zscores_headers = [["Place", "Team", "Manager", "Z-Score"]]
self.scores_headers = [["Place", "Team", "Manager", "Points", "Season Avg. (Place)"]]
self.efficiency_headers = [["Place", "Team", "Manager", "Coaching Efficiency (%)", "Season Avg. (Place)"]]
self.luck_headers = [["Place", "Team", "Manager", "Luck", "Season Avg. (Place)", "Weekly Record (W-L)"]]
self.luck_headers = [["Place", "Team", "Manager", "Luck", "Season Avg. (Place)", "Week/Seas Rec. (Pl.)"]]
self.optimal_scores_headers = [["Place", "Team", "Manager", "Optimal Points", "Season Total (Place)"]]
self.bad_boy_headers = [["Place", "Team", "Manager", "Bad Boy Pts", "Worst Offense", "# Offenders"]]
self.beef_headers = [["Place", "Team", "Manager", "TABBU(s)"]]
Expand Down

0 comments on commit 6d34885

Please sign in to comment.