Index: bunco.py ================================================================== --- bunco.py +++ bunco.py @@ -392,10 +392,42 @@ log('all', f"{table} having a roll-off to resolve a tie") table.roll_off() log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts") table.notch_wins() + + def prizes(self): + prizelist = {} + scores = [sum(p.round_scores) for p in self.players] + wins = [sum(p.round_wins) for p in self.players] + losses = [Game.current_round() - w for w in wins] + buncos = [sum(p.round_bunco_counts) for p in self.players] + contrib_pcts = [p.average_contrib_pct() for p in self.players] + rolls = [sum(p.round_roll_counts) for p in self.players] + streaks = [p.max_streak for p in self.players] + fuzzy_streaks = [p.max_fuzzydie_streak for p in self.players] + avg_diffs = [sum(p.round_scores) - self.average_total_score() for p in self.players] + median_diffs = [sum(p.round_scores) - self.median_total_score() for p in self.players] + smallest_avg_diff = avg_diffs[list(map(abs,avg_diffs)).index(min(list(map(abs,avg_diffs))))] + smallest_median_diff = median_diffs[list(map(abs,median_diffs)).index(min(list(map(abs,median_diffs))))] + + # Build a list of prizes and winners, allowing for ties + prizelist["Highest Score"] = f"{', '.join([str(p) for p in self.players if sum(p.round_scores) == max(scores)])} ({max(scores)})" + prizelist["Lowest Score"] = f"{', '.join([str(p) for p in self.players if sum(p.round_scores) == min(scores)])} ({min(scores)})" + prizelist["Most Wins"] = f"{', '.join([str(p) for p in self.players if sum(p.round_wins) == max(wins)])} ({max(wins)})" + prizelist["Most Losses"] = f"{', '.join([str(p) for p in self.players if Game.current_round() - sum(p.round_wins) == max(losses)])} ({max(losses)})" + prizelist["Most Buncos"] = f"{', '.join([str(p) for p in self.players if sum(p.round_bunco_counts) == max(buncos)])} ({max(buncos)})" + prizelist["Highest Team Contributor"] = f"{', '.join([str(p) for p in self.players if p.average_contrib_pct() == max(contrib_pcts)])} ({max(contrib_pcts):.2%})" + prizelist["Most Rolls"] = f"{', '.join([str(p) for p in self.players if sum(p.round_roll_counts) == max(rolls)])} ({max(rolls)})" + prizelist["Longest Roll Streak"] = f"{', '.join([str(p) for p in self.players if p.max_streak == max(streaks)])} ({max(streaks)})" + prizelist["Fewest Rolls"] = f"{', '.join([str(p) for p in self.players if sum(p.round_roll_counts) == min(rolls)])} ({min(rolls)})" + prizelist["Last Fuzzy Die Holder"] = fuzzydie_holder.name + prizelist["Longest Time with Fuzzy Die"] = f"{', '.join([str(p) for p in self.players if p.max_fuzzydie_streak == max(fuzzy_streaks)])} ({max(fuzzy_streaks)})" + prizelist["Most Average Total Score"] = f"{', '.join([str(p) for p in self.players if abs(sum(p.round_scores) - self.average_total_score()) == abs(smallest_avg_diff)])} ({smallest_avg_diff})" + prizelist["Closest to Median Total Score"] = f"{', '.join([str(p) for p in self.players if abs(sum(p.round_scores) - self.median_total_score()) == abs(smallest_median_diff)])} ({smallest_median_diff})" + + return prizelist log_db = sqlite3.connect("bunco.sqlite") log_dbc = log_db.cursor() def run_query(*args): Index: bunco_app.py ================================================================== --- bunco_app.py +++ bunco_app.py @@ -92,10 +92,15 @@ 'color': '#0070C0'}) total_style = wb.add_format({'font_name': 'Milk Mustache BB', 'font_size': 14, 'align': 'center', 'bold': 'true'}) + prizename_style = wb.add_format({'font_name': 'Milk Mustache BB', + 'font_size': 14}) + prizewinner_style = wb.add_format({'font_name': 'Back Issues BB', + 'font_size': 12, + 'color': '#E26B0A'}) style['player_title'] = wb.add_format({'font_name': 'Back Issues BB', 'font_size': 28, 'bold': True, 'color': '#0096FF'}) @@ -184,11 +189,15 @@ excel_score_sheet(wb, style, player, title) end_row = 3 + len(g.players) ws.write(end_row + 1, 0, "Prizes", title_style) - + prizelist = g.prizes() + + for n, (prizename, winners) in enumerate(prizelist.items()): + ws.write(end_row + 2 + n, 0, prizename, prizename_style) + ws.write(end_row + 2 + n, 1, winners, prizewinner_style) wb.close() def excel_score_sheet(workbook, styles, player, title): ws = workbook.add_worksheet(player.name)