awacke1's picture
Update app.py
f055702
import streamlit as st
import random
import time
import plotly.graph_objects as go
teams = [
('Team 1', '๐Ÿ˜Ž', 'Cool Squad', 'New York City'),
('Team 2', '๐Ÿš€', 'Rocketeers', 'Los Angeles'),
('Team 3', '๐Ÿค–', 'Robo Gang', 'San Francisco'),
('Team 4', '๐ŸŒŸ', 'Super Stars', 'Chicago'),
('Team 5', '๐Ÿ‰', 'Dragons', 'Houston')
]
def create_sankey(votes, turn):
labels = [f"{team[1]} {team[2]}" for team in teams] + ['Upvotes', 'Downvotes']
source = []
target = []
value = []
for i, team in enumerate(teams):
source += [i, i]
target += [len(teams), len(teams) + 1]
value += [votes[team[0]][0], votes[team[0]][1]]
fig = go.Figure(data=[go.Sankey(
node=dict(pad=15, thickness=20, line=dict(color='black', width=0.5), label=labels),
link=dict(source=source, target=target, value=value))])
fig.update_layout(title_text=f'Location Simulator by Nickname (Turn {turn})', title_font=dict(size=24, color='blue'))
return fig
def run_scenario(duration=100, click_card_limit=None):
start_time = time.time()
votes = {team[0]: [0, 0] for team in teams} # Initialize upvotes and downvotes
click_cards = 0
chat = []
turn = 0
st.header("Sankey Graph")
fig = create_sankey(votes, turn)
st.plotly_chart(fig, use_container_width=True)
while time.time() - start_time < duration:
if click_card_limit is None or click_cards < click_card_limit:
click_cards += 1
team = random.choice(teams)
vote_type = random.choice(['upvote', 'downvote'])
clicks = 1 + 3 * (click_cards > 0)
click_cards -= clicks > 1
if vote_type == 'upvote':
votes[team[0]][0] += clicks
else:
votes[team[0]][1] += clicks
chat.append((team, vote_type, clicks))
turn += 1
fig = create_sankey(votes, turn)
st.plotly_chart(fig, use_container_width=True)
time.sleep(random.uniform(0, 1)) # Random sleep between 0 and 1 seconds
return votes, chat
st.title("Team Upvotes and Downvotes Emoji Game")
duration = st.slider("Duration (seconds)", min_value=0, max_value=100, value=10, step=1)
click_card_limit = st.slider("Click Card Limit", min_value=0, max_value=100, value=10, step=1)
st.write(f"Running scenario for {duration} seconds with {click_card_limit} click cards...")
votes, chat = run_scenario(duration, click_card_limit)
st.header("Results")
for team, vote_counts in votes.items():
st.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes")
st.header("Chat")
for message in chat:
team, vote_type, clicks = message
st.write(f"{team[1]} {team[2]}: {clicks} {vote_type}s")
st.header("Final Results")
for team, vote_counts in votes.items():
st.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes")