awacke1's picture
Create backup.app.py
a4c1f3a
# 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)