awacke1 commited on
Commit
982e84c
ยท
1 Parent(s): ee36aac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -8
app.py CHANGED
@@ -3,13 +3,38 @@ import numpy as np
3
  import pandas as pd
4
  import plotly.express as px
5
 
6
- st.title('Random ๐ŸŽฒDice๐ŸŽฒ Games for STEM Math and Data Science')
7
 
8
- # Get user input for the number of dice rolls
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000, 1000)
10
 
11
  # Generate dice rolls
12
- rolls = np.random.randint(1, 7, num_rolls)
13
 
14
  # Count the number of occurrences of each roll
15
  roll_counts = pd.Series(rolls).value_counts().sort_index()
@@ -17,7 +42,7 @@ roll_counts = pd.Series(rolls).value_counts().sort_index()
17
  # Create a sunburst chart of the roll counts
18
  fig = px.sunburst(
19
  names=[f'Roll {i}' for i in roll_counts.index],
20
- parents=['Dice Rolls'] * 6,
21
  values=roll_counts.values,
22
  color=[f'Roll {i}' for i in roll_counts.index],
23
  color_discrete_sequence=px.colors.qualitative.Dark24,
@@ -38,15 +63,17 @@ if not show_labels:
38
  fig.update_traces(textinfo='none')
39
  fig.show()
40
 
41
- # Allow user to download roll data as CSV file
42
  if st.button('Download Roll Data as CSV'):
43
  roll_data = pd.DataFrame({
44
  'Roll': rolls,
45
- 'Count': np.ones(num_rolls)
 
46
  })
 
47
  st.download_button(
48
  label='Download CSV',
49
  data=roll_data.to_csv(index=False),
50
- file_name='roll_data.csv',
51
  mime='text/csv'
52
- )
 
3
  import pandas as pd
4
  import plotly.express as px
5
 
6
+ st.title('Random Dice Game')
7
 
8
+ # Define the available types of dice
9
+ dice_types = [
10
+ {
11
+ 'name': 'Six-sided Dice ๐ŸŽฒ',
12
+ 'sides': 6,
13
+ 'emoji': '๐ŸŽฒ'
14
+ },
15
+ {
16
+ 'name': 'Twenty-sided Dice ๐ŸŽฏ',
17
+ 'sides': 20,
18
+ 'emoji': '๐ŸŽฏ'
19
+ },
20
+ {
21
+ 'name': 'Thirty-sided Dice ๐ŸŽฏ',
22
+ 'sides': 30,
23
+ 'emoji': '๐ŸŽฏ'
24
+ },
25
+ {
26
+ 'name': 'One Hundred-sided Dice ๐ŸŽฒ',
27
+ 'sides': 100,
28
+ 'emoji': '๐ŸŽฒ'
29
+ }
30
+ ]
31
+
32
+ # Get user input for the type of dice and number of rolls
33
+ dice_type = st.selectbox('Choose a type of dice', dice_types)
34
  num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000, 1000)
35
 
36
  # Generate dice rolls
37
+ rolls = np.random.randint(1, dice_type['sides']+1, num_rolls)
38
 
39
  # Count the number of occurrences of each roll
40
  roll_counts = pd.Series(rolls).value_counts().sort_index()
 
42
  # Create a sunburst chart of the roll counts
43
  fig = px.sunburst(
44
  names=[f'Roll {i}' for i in roll_counts.index],
45
+ parents=['Dice Rolls'] * dice_type['sides'],
46
  values=roll_counts.values,
47
  color=[f'Roll {i}' for i in roll_counts.index],
48
  color_discrete_sequence=px.colors.qualitative.Dark24,
 
63
  fig.update_traces(textinfo='none')
64
  fig.show()
65
 
66
+ # Allow user to download roll data as CSV file with their name and dice type
67
  if st.button('Download Roll Data as CSV'):
68
  roll_data = pd.DataFrame({
69
  'Roll': rolls,
70
+ 'Count': np.ones(num_rolls),
71
+ 'DiceNumberOfSides': [dice_type['sides']] * num_rolls
72
  })
73
+ filename = f'roll_data_{dice_type["name"].replace(" ", "_")}_{st.session_state.name}.csv'
74
  st.download_button(
75
  label='Download CSV',
76
  data=roll_data.to_csv(index=False),
77
+ file_name=filename,
78
  mime='text/csv'
79
+ )