File size: 2,839 Bytes
a4c1f3a |
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 |
# Team.Click.Battle.Multiplayer
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 = []
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))
time.sleep(random.uniform(0, 1)) # Random sleep between 0 and 1 seconds
return votes, chat
def save_votes_to_file(votes, filename='upvotes.txt'):
with open(filename, 'w') as f:
for team, vote_counts in votes.items():
f.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes\n")
def create_sankey(votes):
labels = []
source = []
target = []
value = []
for i, team in enumerate(teams):
labels.append(f"{team[1]} {team[2]}")
source += [i, i]
target += [len(teams), len(teams) + 1]
value += [votes[team[0]][0], votes[team[0]][1]]
labels += ['Upvotes', 'Downvotes']
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='Location Simulator by Nickname', title_font=dict(size=24, color='blue'))
return fig
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)
save_votes_to_file(votes)
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("Sankey Graph")
fig = create_sankey(votes)
st.plotly_chart(fig) |