awacke1 commited on
Commit
ecc7544
ยท
1 Parent(s): 39bd597

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -47,26 +47,34 @@ def display_bonus_match(bonus_match, bonus_dice_type, bonus_dice_emoji):
47
  st.success(f'๐ŸŽ‰ You rolled a {bonus_dice_type} {bonus_dice_emoji} on the first roll!')
48
 
49
  def update_dice_roll_history(dice_type, rolls):
50
- bonus_match = False
51
- for dice in dice_types:
52
- if rolls[0] == dice['sides']:
53
- bonus_match = True
54
- bonus_dice_type = dice['name']
55
- bonus_dice_emoji = dice['emoji']
56
- break
57
-
58
- dice_roll_history = st.session_state.dice_roll_history
59
- new_roll_data = pd.DataFrame({'Roll': rolls,
60
- 'Count': np.ones(len(rolls), dtype=np.uint64),
61
- 'DiceNumberOfSides': [dice_type['sides']] * len(rolls),
62
- 'Username': [st.session_state.username] * len(rolls)})
63
- if bonus_match:
64
- new_roll_data['BonusMatchToDiceName'] = [bonus_dice_type] * len(rolls)
65
- new_roll_data['BonusMatchToDiceEmoji'] = [bonus_dice_emoji] * len(rolls)
66
- dice_roll_history = dice_roll_history.append(new_roll_data, ignore_index=True)
67
- st.session_state.dice_roll_history = dice_roll_history
 
 
 
 
 
 
 
 
 
68
 
69
- return bonus_match
70
 
71
  def display_dice_roll_results():
72
  download_history = st.checkbox('๐Ÿ“ฅ Download Roll History', value=False)
 
47
  st.success(f'๐ŸŽ‰ You rolled a {bonus_dice_type} {bonus_dice_emoji} on the first roll!')
48
 
49
  def update_dice_roll_history(dice_type, rolls):
50
+ history = st.session_state.dice_roll_history
51
+ count = st.session_state.count
52
+ dice_name = dice_type['name']
53
+ dice_emoji = dice_type['emoji']
54
+ bonus_match = None
55
+
56
+ # Check if the count matches the number of sides of the dice
57
+ if count > 0 and count % dice_type['sides'] == 0:
58
+ bonus_match = dice_type['name']
59
+ bonus_emoji = dice_type['emoji']
60
+
61
+ # Update the dice roll history
62
+ if history is None:
63
+ history = pd.DataFrame({'Roll': rolls, 'Count': count, 'DiceNumberOfSides': dice_type['sides']})
64
+ else:
65
+ new_history = pd.DataFrame({'Roll': rolls, 'Count': count, 'DiceNumberOfSides': dice_type['sides']})
66
+ history = history.append(new_history, ignore_index=True)
67
+
68
+ if bonus_match is not None:
69
+ history['BonusMatchToDiceName'] = bonus_match
70
+ history['BonusMatchToDiceEmoji'] = bonus_emoji
71
+
72
+ # Add username to history
73
+ history['Username'] = st.session_state.username
74
+
75
+ st.session_state.dice_roll_history = history
76
+ return history
77
 
 
78
 
79
  def display_dice_roll_results():
80
  download_history = st.checkbox('๐Ÿ“ฅ Download Roll History', value=False)