Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Team.Click.Battle.Multiplayer
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import random
|
5 |
+
import time
|
6 |
+
import plotly.graph_objects as go
|
7 |
+
|
8 |
+
teams = [
|
9 |
+
('Team 1', '๐', 'Cool Squad', 'New York City'),
|
10 |
+
('Team 2', '๐', 'Rocketeers', 'Los Angeles'),
|
11 |
+
('Team 3', '๐ค', 'Robo Gang', 'San Francisco'),
|
12 |
+
('Team 4', '๐', 'Super Stars', 'Chicago'),
|
13 |
+
('Team 5', '๐', 'Dragons', 'Houston')
|
14 |
+
]
|
15 |
+
|
16 |
+
def run_scenario(duration=100, click_card_limit=None):
|
17 |
+
start_time = time.time()
|
18 |
+
votes = {team[0]: [0, 0] for team in teams} # Initialize upvotes and downvotes
|
19 |
+
click_cards = 0
|
20 |
+
chat = []
|
21 |
+
|
22 |
+
while time.time() - start_time < duration:
|
23 |
+
if click_card_limit is None or click_cards < click_card_limit:
|
24 |
+
click_cards += 1
|
25 |
+
|
26 |
+
team = random.choice(teams)
|
27 |
+
vote_type = random.choice(['upvote', 'downvote'])
|
28 |
+
clicks = 1 + 3 * (click_cards > 0)
|
29 |
+
click_cards -= clicks > 1
|
30 |
+
|
31 |
+
if vote_type == 'upvote':
|
32 |
+
votes[team[0]][0] += clicks
|
33 |
+
else:
|
34 |
+
votes[team[0]][1] += clicks
|
35 |
+
chat.append((team, vote_type, clicks))
|
36 |
+
time.sleep(random.uniform(0, 1)) # Random sleep between 0 and 1 seconds
|
37 |
+
|
38 |
+
return votes, chat
|
39 |
+
|
40 |
+
def save_votes_to_file(votes, filename='upvotes.txt'):
|
41 |
+
with open(filename, 'w') as f:
|
42 |
+
for team, vote_counts in votes.items():
|
43 |
+
f.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes\n")
|
44 |
+
|
45 |
+
def create_sankey(votes):
|
46 |
+
labels = []
|
47 |
+
source = []
|
48 |
+
target = []
|
49 |
+
value = []
|
50 |
+
|
51 |
+
for i, team in enumerate(teams):
|
52 |
+
labels.append(f"{team[1]} {team[2]}")
|
53 |
+
source += [i, i]
|
54 |
+
target += [len(teams), len(teams) + 1]
|
55 |
+
value += [votes[team[0]][0], votes[team[0]][1]]
|
56 |
+
|
57 |
+
labels += ['Upvotes', 'Downvotes']
|
58 |
+
|
59 |
+
fig = go.Figure(data=[go.Sankey(
|
60 |
+
node=dict(pad=15, thickness=20, line=dict(color='black', width=0.5), label=labels),
|
61 |
+
link=dict(source=source, target=target, value=value))])
|
62 |
+
|
63 |
+
fig.update_layout(title_text='Location Simulator by Nickname', title_font=dict(size=24, color='blue'))
|
64 |
+
|
65 |
+
return fig
|
66 |
+
|
67 |
+
st.title("Team Upvotes and Downvotes Emoji Game")
|
68 |
+
|
69 |
+
duration = st.slider("Duration (seconds)", min_value=0, max_value=100, value=10, step=1)
|
70 |
+
click_card_limit = st.slider("Click Card Limit", min_value=0, max_value=100, value=10, step=1)
|
71 |
+
|
72 |
+
st.write(f"Running scenario for {duration} seconds with {click_card_limit} click cards...")
|
73 |
+
votes, chat = run_scenario(duration, click_card_limit)
|
74 |
+
|
75 |
+
save_votes_to_file(votes)
|
76 |
+
|
77 |
+
st.header("Results")
|
78 |
+
for team, vote_counts in votes.items():
|
79 |
+
st.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes")
|
80 |
+
|
81 |
+
st.header("Chat")
|
82 |
+
for message in chat:
|
83 |
+
team, vote_type, clicks = message
|
84 |
+
st.write(f"{team[1]} {team[2]}: {clicks} {vote_type}s")
|
85 |
+
|
86 |
+
st.header("Sankey Graph")
|
87 |
+
fig = create_sankey(votes)
|
88 |
+
st.plotly_chart(fig)
|
89 |
+
|
90 |
+
|
91 |
+
|