Bunco Simulator

Check-in [c6bb9d]
Overview
Comment:Report prizes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c6bb9d857f1657963015bd4b41a566f83a95fd53f792ae0992b7b4c54ef36cab
User & Date: joel on 2018-11-22 17:36:57
Other Links: manifest | tags
Context
2018-11-22
17:49
Update ignore-glob check-in: a1e1f8 user: joel tags: trunk
17:36
Report prizes check-in: c6bb9d user: joel tags: trunk
16:04
Add score sheets for individual players to Excel output (closes [927402827e]) check-in: 940dde user: joel tags: trunk
Changes

Modified bunco.py from [dae914] to [bbae10].

390
391
392
393
394
395
396
































397
398
399
400
401
402
403
            log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts")
            while table.team1_score == table.team2_score:
                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()
































    
log_db = sqlite3.connect("bunco.sqlite")
log_dbc = log_db.cursor()

def run_query(*args):
    log_dbc.execute(*args)
    log_db.commit()







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
            log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts")
            while table.team1_score == table.team2_score:
                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):
    log_dbc.execute(*args)
    log_db.commit()

Modified bunco_app.py from [109c1e] to [36d781].

90
91
92
93
94
95
96





97
98
99
100
101
102
103
                                 'align': 'right',
                                 'num_format': '_(* #,##0_);_(* (#,##0);_(* "-"??_);_(@_)',
                                 'color': '#0070C0'})
    total_style = wb.add_format({'font_name': 'Milk Mustache BB', 
                                 'font_size': 14,
                                 'align': 'center',
                                 'bold': 'true'})






    style['player_title'] = wb.add_format({'font_name': 'Back Issues BB', 
                                 'font_size': 28,
                                 'bold': True,
                                 'color': '#0096FF'})
    style['player_subtitle'] = wb.add_format({'font_name': 'Back Issues BB', 
                                 'font_size': 16})







>
>
>
>
>







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
                                 'align': 'right',
                                 'num_format': '_(* #,##0_);_(* (#,##0);_(* "-"??_);_(@_)',
                                 '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'})
    style['player_subtitle'] = wb.add_format({'font_name': 'Back Issues BB', 
                                 'font_size': 16})
182
183
184
185
186
187
188

189



190
191
192
193
194
195
196
        ws.write(row, end_col + 4, sum(player.round_bunco_counts), total_style)
        ws.write(row, end_col + 5, sum(player.round_roll_counts), total_style)

        excel_score_sheet(wb, style, player, title)

    end_row = 3 + len(g.players)
    ws.write(end_row + 1, 0, "Prizes", title_style)

    



    wb.close()

def excel_score_sheet(workbook, styles, player, title):
    ws = workbook.add_worksheet(player.name)

    ws.set_column('A:A', 14)
    ws.set_column('B:C', 13)







>
|
>
>
>







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
        ws.write(row, end_col + 4, sum(player.round_bunco_counts), total_style)
        ws.write(row, end_col + 5, sum(player.round_roll_counts), total_style)

        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)

    ws.set_column('A:A', 14)
    ws.set_column('B:C', 13)