-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
194 lines (161 loc) · 5.83 KB
/
app.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import streamlit as st
from src import STORY
from src import logic as lg
from src import Simulation
st.set_page_config(
page_title="Guacamole Contest",
page_icon="img/avocado-emoji.png",
initial_sidebar_state="collapsed")
lg.initialize_session_state()
num_townspeople, st_dev, fullness_factor = lg.sidebar()
st.title("The Allegory of the Avocados")
st.write("""
Here is the link to our
[Google Doc](https://docs.google.com/document/d/1CA9NXp8I9b6ds16khcJLrY1ZL7ZBABK6KRu9SvBL5JI/edit?usp=sharing)
where we're developing and commenting on the story.""")
st.subheader("Welcome to Sunnyvale")
lg.write_story("Introduction")
st.subheader("Let’s Play Guac God")
lg.write_story("Guac God")
lg.write_instructions("Guac God")
guac_df, scenario = lg.choose_scenario()
lg.write_story("demo_voting")
lg.demo_contest(scenario, st_dev)
st.write("""
Takeaway: When it's clearly good or bad, there's a lot more agreement.
Agreement is trickier when something is just average, not compelling in
either way""")
# st.image("img/holy_guacamole.jpeg", width=400, caption="This is you, the Guacamole Goddess.")
st.markdown("---")
st.subheader("Let's Taste and Vote!")
section_title = "simulation_1"
lg.write_story(section_title)
lg.write_instructions(section_title)
sim1 = Simulation(guac_df, num_townspeople, st_dev, fullness_factor=fullness_factor)
sim1.simulate()
lg.animate_results(sim1, key=section_title)
if st.session_state[f"{section_title}_keep_chart_visible"]:
lg.success_message(section_title, sim1.success)
st.markdown("---")
lg.write_story("transition_1_to_2")
st.subheader("Not Enough Guac to Go Around")
section_title = "simulation_2"
lg.write_story(section_title)
col1, col2 = st.columns(2)
lg.write_instructions(section_title, col1)
guac_limit2 = col2.slider(
"How many guacs will tasters try? Start by just removing a couple and then push it from there.",
value=18,
min_value=1,
max_value=20)
sim2 = Simulation(guac_df, num_townspeople, st_dev, assigned_guacs=guac_limit2)
sim2.simulate()
lg.animate_results(sim2, key=section_title)
if st.session_state[f"{section_title}_keep_chart_visible"]:
lg.success_message(section_title, sim2.success, guac_limit2)
st.write("")
st.write("")
lg.write_story("simulation_2_a")
lg.animate_results_of_100_runs(sim2, scenario, section_title)
st.markdown("---")
lg.write_story("transition_2_to_3")
st.subheader("Different People, Different Tastes")
section_title = "simulation_3"
lg.write_story(section_title)
st.text("")
lg.write_instructions(section_title+"_a")
pepe, fra, carlos = lg.types_of_voters(section_title)
col1, col2 = st.columns(2)
lg.write_instructions(section_title+"_b", col1)
guac_limit3 = col2.slider(
"How many guacamoles does each voter get to try?",
value=15,
min_value=1,
max_value=20,
key=section_title)
sim3 = Simulation(guac_df, num_townspeople, st_dev,
assigned_guacs=guac_limit3,
perc_fra=fra,
perc_pepe=pepe,
perc_carlos=carlos)
sim3.simulate()
lg.animate_results(sim3, key=section_title)
lg.success_message(section_title, sim3.success)
num_cronies = sum(townie.carlos_crony for townie in sim3.townspeople)
num_effective_cronies = sum(townie.voted_for_our_boy for townie in sim3.townspeople)
st.caption(f"Also, {num_cronies} of Carlos's cronies voted in the contest and {num_effective_cronies} were able to vote for him.")
st.markdown("---")
st.subheader("A New Idea")
section_title = "condorcet"
lg.write_story(section_title + "_1")
st.image("img/napkin_ballot.jpg", width=400)
lg.write_story(section_title + "_2")
st.text("")
st.text("")
lg.write_instructions(section_title)
pepe_4, fra_4, carlos_4 = lg.types_of_voters(section_title, pepe, fra, carlos)
col1, col2 = st.columns(2)
guac_limit4 = col1.slider(
"How many guacamoles does each voter get to try?",
value=guac_limit3,
min_value=1,
max_value=20,
key=section_title)
num_townspeople4 = col2.slider(
"How many townspeople vote in the contest?",
value=num_townspeople,
min_value=10,
max_value=500,
step=10,
key=section_title)
sim4 = Simulation(guac_df, num_townspeople4, st_dev,
assigned_guacs=guac_limit4,
perc_fra=fra,
perc_pepe=pepe,
perc_carlos=carlos,
method="condorcet")
sim4.simulate()
lg.animate_results(sim4, key=section_title)
lg.success_message(section_title, sim4.success)
num_cronies = sum(townie.carlos_crony for townie in sim4.townspeople)
num_effective_cronies = sum(townie.voted_for_our_boy for townie in sim4.townspeople)
st.caption(f"Also, {num_cronies} of Carlos's cronies voted in the contest and {num_effective_cronies} were able to vote for him.")
st.markdown("---")
st.subheader("Out in the Real World")
lg.write_story("conclusion")
st.markdown("---")
st.subheader("Sandbox")
section_title = "sandbox"
lg.write_story(section_title)
sandbox_df, sandbox_scenario = lg.choose_scenario(key=section_title)
pepe_sb, fra_sb, carlos_sb = lg.types_of_voters(section_title, pepe, fra, carlos)
col1, col2 = st.columns(2)
guac_limit_sb = col1.slider(
"How many guacamoles does each voter get to try?",
value=guac_limit3,
min_value=1,
max_value=20,
key=section_title)
num_townspeople_sb = col2.slider(
"How many townspeople vote in the contest?",
value=num_townspeople,
min_value=10,
max_value=500,
step=10,
key=section_title)
methods = {
"Summing the Scores": "sum",
"Tallying Implicit Rankings": "condorcet",
"Ranked Choice Voting": "rcv",
}
method_chosen = st.selectbox("How should we tally the votes?",
options=methods.keys())
sandbox_sim = Simulation(sandbox_df, num_townspeople_sb, st_dev,
assigned_guacs=guac_limit_sb,
perc_fra=fra_sb,
perc_pepe=pepe_sb,
perc_carlos=carlos_sb,
method=methods[method_chosen])
sandbox_sim.simulate()
lg.animate_results(sandbox_sim, key=section_title)
lg.success_message(section_title, sandbox_sim.success)