File size: 5,192 Bytes
ce7029c
 
 
 
 
 
c11db43
ddb3454
 
 
ce7029c
 
 
 
 
 
 
 
6b5d290
 
ce7029c
 
 
6b5d290
 
ce7029c
6b5d290
 
 
 
 
ce7029c
6b5d290
 
ce7029c
 
 
 
 
 
 
 
6b5d290
ce7029c
 
 
 
 
 
 
6b5d290
 
ce7029c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b5d290
 
ce7029c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Code Destiny and Density is equal to one hundred.

#st.Markdown("TODO: A code density slider bar shows and adjusts the size of lines.  ')
#st.Markdown('Any ๐ŸŽฒDice๐ŸŽฒ way to compress the lines yet make it readable as optimal list of sets will do.  Match language from good math books.')
            
import os
import streamlit as st
import numpy as np
import pandas as pd
import plotly.express as px
st.set_page_config(layout='wide')
st.title('Any ๐ŸŽฒDice๐ŸŽฒ Way - STEM Math and Data Science Numerical Potluck')
dice_types = [{'name': 'Six-sided Dice', 'sides': 6, 'emoji': '๐ŸŽฒ'},
              {'name': 'Twenty-sided Dice', 'sides': 20, 'emoji': '๐Ÿฟ'},
              {'name': 'Thirty-sided Dice', 'sides': 30, 'emoji': '๐Ÿฅ—'},
              {'name': 'One Hundred-sided Dice', 'sides': 100, 'emoji': '๐ŸŽ‚'}]
if 'username' not in st.session_state:
    st.session_state.username = ''
if 'dice_roll_history' not in st.session_state:
    st.session_state.dice_roll_history = pd.DataFrame()
dice_type = st.selectbox('Choose a type of dice', dice_types, format_func=lambda d: f"{d['name']} {d['emoji']}")
num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000, 1000)
rolls = np.random.randint(1, dice_type['sides'] + 1, num_rolls, dtype=np.uint64)
roll_counts = pd.Series(rolls).value_counts().sort_index()
fig = px.sunburst(names=[f'Roll {i}' for i in roll_counts.index],
                  parents=['Dice Rolls'] * dice_type['sides'],
                  values=roll_counts.values,
                  color=[f'Roll {i}' for i in roll_counts.index],
                  color_discrete_sequence=px.colors.qualitative.Dark24,
                  maxdepth=2)
fig.update_layout(title='Dice Roll Distribution', margin=dict(l=20, r=20, t=40, b=20), width=800, height=600)
show_labels = st.checkbox('Show Labels', value=True)
if not show_labels:
    fig.update_traces(textinfo='none')
fig.show()
bonus_match = False
for dice in dice_types:
    if rolls[0] == dice['sides']:
        bonus_match = True
        bonus_dice_type = dice['name']
        bonus_dice_emoji = dice['emoji']
        break
dice_roll_history = st.session_state.dice_roll_history
new_roll_data = pd.DataFrame({'Roll': rolls,
                              'Count': np.ones(num_rolls, dtype=np.uint64),
                              'DiceNumberOfSides': [dice_type['sides']] * num_rolls,
                              'Username': [st.session_state.username] * num_rolls})
if bonus_match:
    new_roll_data['BonusMatchToDiceName'] = [bonus_dice_type] * num_rolls
    new_roll_data['BonusMatchToDiceEmoji'] = [bonus_dice_emoji] * num_rolls
dice_roll_history = dice_roll_history.append(new_roll_data, ignore_index=True)
st.session_state.dice_roll_history = dice_roll_history
include_name_column = st.checkbox('Include Username Column in Downloaded CSV', value=True)
if st.button('Download Results'):
    filename = f'dice_roll_history_{st.session_state.username}{dice_type["emoji"]}.csv'
    if not include_name_column:
        dice_roll_history = dice_roll_history.drop(columns=['Username'])
        filename = f'dice_roll_history{dice_type["emoji"]}.csv'
    st.download_button(label='Download CSV', data=dice_roll_history.to_csv(index=False), file_name=filename, mime='text/csv')
csv_files = [f for f in os.listdir('.') if os.path.isfile
              f.endswith('.csv') and 'dice_roll_history' in f]
if csv_files:
    st.write('Downloaded files:')
    for csv_file in csv_files:
        st.markdown(f'[Download {csv_file}]({csv_file})')
st.write('---')
st.subheader('Settings')
st.session_state.username = st.text_input('Username', st.session_state.username)
st.write('---')
st.subheader('Dice Roll History')
st.write(dice_roll_history)

st.write("""
๐Ÿž Bread
๐Ÿฅ Croissant
๐Ÿฅ– Baguette Bread
๐Ÿซ“ Flatbread
๐Ÿฅจ Pretzel
๐Ÿฅฏ Bagel
๐Ÿฅž Pancakes
๐Ÿง‡ Waffle
๐Ÿง€ Cheese Wedge
๐Ÿ– Meat on Bone
๐Ÿ— Poultry Leg
๐Ÿฅฉ Cut of Meat
๐Ÿฅ“ Bacon
๐Ÿ” Hamburger
๐ŸŸ French Fries
๐Ÿ• Pizza
๐ŸŒญ Hot Dog
๐Ÿฅช Sandwich
๐ŸŒฎ Taco
๐ŸŒฏ Burrito
๐Ÿซ” Tamale
๐Ÿฅ™ Stuffed Flatbread
๐Ÿง† Falafel
๐Ÿฅš Egg
๐Ÿณ Cooking
๐Ÿฅ˜ Shallow Pan of Food
๐Ÿฒ Pot of Food
๐Ÿซ• Fondue
๐Ÿฅฃ Bowl with Spoon
๐Ÿฅ— Green Salad
๐Ÿฟ Popcorn
๐Ÿงˆ Butter
๐Ÿง‚ Salt
๐Ÿฅซ Canned Food
๐Ÿฑ Bento Box
๐Ÿ˜ Rice Cracker
๐Ÿ™ Rice Ball
๐Ÿš Cooked Rice
๐Ÿ› Curry Rice
๐Ÿœ Steaming Bowl
๐Ÿ Spaghetti
๐Ÿ  Roasted Sweet Potato
๐Ÿข Oden
๐Ÿฃ Sushi
๐Ÿค Fried Shrimp
๐Ÿฅ Fish Cake with Swirl
๐Ÿฅฎ Moon Cake
๐Ÿก Dango
๐ŸฅŸ Dumpling
๐Ÿฅ  Fortune Cookie
๐Ÿฅก Takeout Box
๐Ÿฆช Oyster
๐Ÿฆ Soft Ice Cream
๐Ÿง Shaved Ice
๐Ÿจ Ice Cream
๐Ÿฉ Doughnut
๐Ÿช Cookie
๐ŸŽ‚ Birthday Cake
๐Ÿฐ Shortcake
๐Ÿง Cupcake
๐Ÿฅง Pie
๐Ÿซ Chocolate Bar
๐Ÿฌ Candy
๐Ÿญ Lollipop
๐Ÿฎ Custard
๐Ÿฏ Honey Pot
๐Ÿผ Baby Bottle
๐Ÿฅ› Glass of Milk
โ˜• Hot Beverage
๐Ÿซ– Teapot
๐Ÿต Teacup Without Handle
๐Ÿถ Sake
๐Ÿพ Bottle with Popping Cork
๐Ÿท Wine Glass
๐Ÿธ Cocktail Glass
๐Ÿน Tropical Drink
๐Ÿบ Beer Mug
๐Ÿป Clinking Beer Mugs
๐Ÿฅ‚ Clinking Glasses
๐Ÿฅƒ Tumbler Glass
๐Ÿซ— Pouring Liquid
๐Ÿฅค Cup with Straw
๐Ÿง‹ Bubble Tea
๐Ÿงƒ Beverage Box
๐Ÿง‰ Mate
๐ŸงŠ Ice
๐Ÿฅข Chopsticks
๐Ÿฝ๏ธ Fork and Knife with Plate
๐Ÿด Fork and Knife
๐Ÿฅ„ Spoon
๐Ÿซ™ Jar
""")