Update app.py
Browse files
app.py
CHANGED
@@ -11,17 +11,34 @@ teams = [
|
|
11 |
('Team 5', '🐉', 'Dragons', 'Houston')
|
12 |
]
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def run_scenario(duration=100, click_card_limit=None):
|
15 |
start_time = time.time()
|
16 |
votes = {team[0]: [0, 0] for team in teams} # Initialize upvotes and downvotes
|
17 |
click_cards = 0
|
18 |
chat = []
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
label=[f"{team[1]} {team[2]}" for team in teams] + ['Upvotes', 'Downvotes']),
|
23 |
-
link=dict(source=[], target=[], value=[]))])
|
24 |
-
|
25 |
st.plotly_chart(fig, use_container_width=True)
|
26 |
|
27 |
while time.time() - start_time < duration:
|
@@ -39,19 +56,8 @@ def run_scenario(duration=100, click_card_limit=None):
|
|
39 |
votes[team[0]][1] += clicks
|
40 |
chat.append((team, vote_type, clicks))
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
source += [i, i]
|
45 |
-
target += [len(teams), len(teams) + 1]
|
46 |
-
value += [votes[team[0]][0], votes[team[0]][1]]
|
47 |
-
|
48 |
-
fig = go.Figure(data=[go.Sankey(
|
49 |
-
node=dict(pad=15, thickness=20, line=dict(color='black', width=0.5),
|
50 |
-
label=[f"{team[1]} {team[2]}" for team in teams] + ['Upvotes', 'Downvotes']),
|
51 |
-
link=dict(source=source, target=target, value=value))])
|
52 |
-
|
53 |
-
fig.update_layout(title_text='Location Simulator by Nickname', title_font=dict(size=24, color='blue'))
|
54 |
-
|
55 |
st.plotly_chart(fig, use_container_width=True)
|
56 |
|
57 |
time.sleep(random.uniform(0, 1)) # Random sleep between 0 and 1 seconds
|
@@ -79,6 +85,3 @@ st.header("Final Results")
|
|
79 |
for team, vote_counts in votes.items():
|
80 |
st.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes")
|
81 |
|
82 |
-
st.header("Sankey Graph")
|
83 |
-
fig = create_sankey(votes)
|
84 |
-
st.plotly_chart(fig, use_container_width=True)
|
|
|
11 |
('Team 5', '🐉', 'Dragons', 'Houston')
|
12 |
]
|
13 |
|
14 |
+
def create_sankey(votes, turn):
|
15 |
+
labels = [f"{team[1]} {team[2]}" for team in teams] + ['Upvotes', 'Downvotes']
|
16 |
+
source = []
|
17 |
+
target = []
|
18 |
+
value = []
|
19 |
+
|
20 |
+
for i, team in enumerate(teams):
|
21 |
+
source += [i, i]
|
22 |
+
target += [len(teams), len(teams) + 1]
|
23 |
+
value += [votes[team[0]][0], votes[team[0]][1]]
|
24 |
+
|
25 |
+
fig = go.Figure(data=[go.Sankey(
|
26 |
+
node=dict(pad=15, thickness=20, line=dict(color='black', width=0.5), label=labels),
|
27 |
+
link=dict(source=source, target=target, value=value))])
|
28 |
+
|
29 |
+
fig.update_layout(title_text=f'Location Simulator by Nickname (Turn {turn})', title_font=dict(size=24, color='blue'))
|
30 |
+
|
31 |
+
return fig
|
32 |
+
|
33 |
def run_scenario(duration=100, click_card_limit=None):
|
34 |
start_time = time.time()
|
35 |
votes = {team[0]: [0, 0] for team in teams} # Initialize upvotes and downvotes
|
36 |
click_cards = 0
|
37 |
chat = []
|
38 |
+
turn = 0
|
39 |
|
40 |
+
st.header("Sankey Graph")
|
41 |
+
fig = create_sankey(votes, turn)
|
|
|
|
|
|
|
42 |
st.plotly_chart(fig, use_container_width=True)
|
43 |
|
44 |
while time.time() - start_time < duration:
|
|
|
56 |
votes[team[0]][1] += clicks
|
57 |
chat.append((team, vote_type, clicks))
|
58 |
|
59 |
+
turn += 1
|
60 |
+
fig = create_sankey(votes, turn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
st.plotly_chart(fig, use_container_width=True)
|
62 |
|
63 |
time.sleep(random.uniform(0, 1)) # Random sleep between 0 and 1 seconds
|
|
|
85 |
for team, vote_counts in votes.items():
|
86 |
st.write(f"{team}: {vote_counts[0]} upvotes, {vote_counts[1]} downvotes")
|
87 |
|
|
|
|
|
|