Spaces:
Sleeping
Sleeping
cassiebuhler
commited on
Commit
•
2059c4a
1
Parent(s):
6284181
adding overall pass percentage
Browse files
app.py
CHANGED
@@ -71,7 +71,7 @@ votes_parquet = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/
|
|
71 |
|
72 |
# get parquet data for charts
|
73 |
con = ibis.duckdb.connect(extensions=["spatial"])
|
74 |
-
|
75 |
.read_parquet(votes_parquet)
|
76 |
.cast({"geometry": "geometry"})
|
77 |
)
|
@@ -94,8 +94,8 @@ def create_chart(df, y_column, ylab, title, color):
|
|
94 |
)
|
95 |
|
96 |
# percentage of measures passing, per party
|
97 |
-
def get_passes(
|
98 |
-
return (
|
99 |
.filter(_.year >= 2000)
|
100 |
.group_by("year", "party")
|
101 |
.aggregate(total=_.count(), passes=_.Status.isin(["Pass", "Pass*"]).sum())
|
@@ -105,8 +105,8 @@ def get_passes(party):
|
|
105 |
|
106 |
|
107 |
# cumulative funding over time
|
108 |
-
def funding_chart(
|
109 |
-
return (
|
110 |
.filter(_.year >= 2000)
|
111 |
.mutate(amount=_.amount.replace('$', '')
|
112 |
.replace(',', '')
|
@@ -270,6 +270,8 @@ party_style = {
|
|
270 |
]
|
271 |
}
|
272 |
|
|
|
|
|
273 |
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
|
274 |
|
275 |
color_choice = st.radio("Color by:", ["Measure Status", "Political Party"])
|
@@ -282,6 +284,11 @@ if social_toggle:
|
|
282 |
if party_toggle:
|
283 |
m.add_pmtiles(party_pmtiles, style = party_style ,visible=True, opacity=0.3, tooltip=True)
|
284 |
|
|
|
|
|
|
|
|
|
|
|
285 |
if color_choice == "Measure Status":
|
286 |
m.add_pmtiles(votes_pmtiles, style=get_style_status("State"), visible=True, opacity=0.8, tooltip=True)
|
287 |
m.add_pmtiles(votes_pmtiles, style=get_style_status("County"), visible=True, opacity=1.0, tooltip=True)
|
@@ -299,9 +306,9 @@ m.to_streamlit()
|
|
299 |
|
300 |
|
301 |
# display charts
|
302 |
-
df_passes = get_passes(
|
303 |
st.altair_chart(create_chart(df_passes, "percent_passed", "Percent Passed","% of Measures Passed", [COLORS["dem_blue"], COLORS["rep_red"]]), use_container_width=True)
|
304 |
|
305 |
-
df_funding = funding_chart(
|
306 |
st.altair_chart(create_chart(df_funding, "cumulative_funding", "Billions of Dollars", "Cumulative Funding", COLORS["dark_green"]), use_container_width=True)
|
307 |
|
|
|
71 |
|
72 |
# get parquet data for charts
|
73 |
con = ibis.duckdb.connect(extensions=["spatial"])
|
74 |
+
votes = (con
|
75 |
.read_parquet(votes_parquet)
|
76 |
.cast({"geometry": "geometry"})
|
77 |
)
|
|
|
94 |
)
|
95 |
|
96 |
# percentage of measures passing, per party
|
97 |
+
def get_passes(votes):
|
98 |
+
return (votes
|
99 |
.filter(_.year >= 2000)
|
100 |
.group_by("year", "party")
|
101 |
.aggregate(total=_.count(), passes=_.Status.isin(["Pass", "Pass*"]).sum())
|
|
|
105 |
|
106 |
|
107 |
# cumulative funding over time
|
108 |
+
def funding_chart(votes):
|
109 |
+
return (votes
|
110 |
.filter(_.year >= 2000)
|
111 |
.mutate(amount=_.amount.replace('$', '')
|
112 |
.replace(',', '')
|
|
|
270 |
]
|
271 |
}
|
272 |
|
273 |
+
|
274 |
+
|
275 |
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
|
276 |
|
277 |
color_choice = st.radio("Color by:", ["Measure Status", "Political Party"])
|
|
|
284 |
if party_toggle:
|
285 |
m.add_pmtiles(party_pmtiles, style = party_style ,visible=True, opacity=0.3, tooltip=True)
|
286 |
|
287 |
+
passed = votes.filter(_.Status.isin(["Pass","Pass*"])).count().execute()
|
288 |
+
total = votes.count().execute()
|
289 |
+
overall_passed = (passed/total*100).round(2)
|
290 |
+
f"{overall_passed}% Measures Passed"
|
291 |
+
|
292 |
if color_choice == "Measure Status":
|
293 |
m.add_pmtiles(votes_pmtiles, style=get_style_status("State"), visible=True, opacity=0.8, tooltip=True)
|
294 |
m.add_pmtiles(votes_pmtiles, style=get_style_status("County"), visible=True, opacity=1.0, tooltip=True)
|
|
|
306 |
|
307 |
|
308 |
# display charts
|
309 |
+
df_passes = get_passes(votes)
|
310 |
st.altair_chart(create_chart(df_passes, "percent_passed", "Percent Passed","% of Measures Passed", [COLORS["dem_blue"], COLORS["rep_red"]]), use_container_width=True)
|
311 |
|
312 |
+
df_funding = funding_chart(votes)
|
313 |
st.altair_chart(create_chart(df_funding, "cumulative_funding", "Billions of Dollars", "Cumulative Funding", COLORS["dark_green"]), use_container_width=True)
|
314 |
|