awacke1 commited on
Commit
d501fab
ยท
1 Parent(s): 12ee41e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
- import plotly.graph_objects as go
5
  from datetime import datetime
6
  from base64 import b64encode
7
 
@@ -13,7 +13,23 @@ def roll_dice(num_rolls, dice_type):
13
  rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
14
  return rolls
15
 
16
- st.title("๐ŸŽฒ Nutrition Dice Game for STEM and Math")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  username = st.text_input("๐Ÿ‘ค Enter your username:")
18
  num_rolls = st.slider("๐Ÿ”ข Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
19
 
@@ -22,8 +38,10 @@ for dice_type in DICE_TYPES:
22
  rolls = roll_dice(num_rolls, dice_type)
23
  highest_rolls = sum(roll == dice_type for roll in rolls)
24
  coin_tokens_added = 0
 
25
  dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls]
26
  st.write(f"๐ŸŽฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}")
 
27
  for roll in rolls:
28
  if roll == dice_type:
29
  st.write(f"๐ŸŽ‰ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐Ÿ’ฐ Adding 3 coins.")
@@ -32,13 +50,17 @@ for dice_type in DICE_TYPES:
32
  st.write(f"๐ŸŽ‰ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐Ÿ’– Adding 10 health tokens.")
33
  if dice_type == 100:
34
  history["health_tokens"].append(history["health_tokens"][-1] + 10)
 
35
  history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls
36
  history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
37
  history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
38
-
39
  st.write("๐Ÿ’ฐ๐Ÿ’– Token Accumulation:")
 
 
40
  df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1)
41
  timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
42
  filename = f"{username}_{timestamp}.csv"
43
  df.to_csv(filename, index=False)
44
- st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True)
 
 
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
+ import pygraphviz as pgv
5
  from datetime import datetime
6
  from base64 import b64encode
7
 
 
13
  rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
14
  return rolls
15
 
16
+ def plot_tokens(health_tokens, coin_tokens):
17
+ dot = pgv.AGraph(strict=False, directed=True)
18
+ dot.node_attr['shape'] = 'plaintext'
19
+ dot.edge_attr['arrowhead'] = 'none'
20
+
21
+ health_foods = [FOOD_LIST[i] for i in health_tokens]
22
+ coin_foods = [FOOD_LIST[i] for i in coin_tokens]
23
+
24
+ health_tokens_str = " | ".join(health_foods)
25
+ coin_tokens_str = " | ".join(coin_foods)
26
+
27
+ dot.add_edge('Health', health_tokens_str)
28
+ dot.add_edge('Coins', coin_tokens_str)
29
+
30
+ st.graphviz_chart(dot.string())
31
+
32
+ st.title("๐ŸŽฒ Slot Machine Game")
33
  username = st.text_input("๐Ÿ‘ค Enter your username:")
34
  num_rolls = st.slider("๐Ÿ”ข Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
35
 
 
38
  rolls = roll_dice(num_rolls, dice_type)
39
  highest_rolls = sum(roll == dice_type for roll in rolls)
40
  coin_tokens_added = 0
41
+
42
  dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls]
43
  st.write(f"๐ŸŽฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}")
44
+
45
  for roll in rolls:
46
  if roll == dice_type:
47
  st.write(f"๐ŸŽ‰ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐Ÿ’ฐ Adding 3 coins.")
 
50
  st.write(f"๐ŸŽ‰ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐Ÿ’– Adding 10 health tokens.")
51
  if dice_type == 100:
52
  history["health_tokens"].append(history["health_tokens"][-1] + 10)
53
+
54
  history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls
55
  history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
56
  history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
57
+
58
  st.write("๐Ÿ’ฐ๐Ÿ’– Token Accumulation:")
59
+ plot_tokens(history["health_tokens"], history["coin_tokens"])
60
+
61
  df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1)
62
  timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
63
  filename = f"{username}_{timestamp}.csv"
64
  df.to_csv(filename, index=False)
65
+ st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True)
66
+