File size: 3,066 Bytes
7fe06e0 68c52f8 7fe06e0 68c52f8 7fe06e0 68c52f8 7fe06e0 68c52f8 7fe06e0 68c52f8 7fe06e0 68c52f8 7fe06e0 68c52f8 7fe06e0 8ff8a56 68c52f8 79470c6 7fe06e0 68c52f8 |
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 |
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 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 = []
fig = go.Figure(data=[go.Sankey(
node=dict(pad=15, thickness=20, line=dict(color='black', width=0.5),
label=[f"{team[1]} {team[2]}" for team in teams] + ['Upvotes', 'Downvotes']),
link=dict(source=[], target=[], value=[]))])
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))
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=[f"{team[1]} {team[2]}" for team in teams] + ['Upvotes', 'Downvotes']),
link=dict(source=source, target=target, value=value))])
fig.update_layout(title_text='Location Simulator by Nickname', title_font=dict(size=24, color='blue'))
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")
st.header("Sankey Graph")
fig = create_sankey(votes)
st.plotly_chart(fig, use_container_width=True) |