cassiebuhler commited on
Commit
46725fa
1 Parent(s): 4a9207f

adding parties

Browse files
Files changed (1) hide show
  1. app.py +47 -2
app.py CHANGED
@@ -63,8 +63,9 @@ year = st.slider("Select a year", min_value=1988, max_value=2024, value=2022, st
63
  import leafmap.maplibregl as leafmap
64
  m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
65
 
66
- url = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/landvote_polygons.pmtiles"
67
- # url = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/votes.pmtiles"
 
68
 
69
  dark_orange = 'rgba(171, 86, 1, 1)' # dark orange - min value
70
  light_orange = 'rgba(243, 211, 177, 1)' # light orange
@@ -72,6 +73,40 @@ grey = 'rgba(211, 211, 211, 1)' # grey
72
  light_green = 'rgba(195, 219, 195, 1)' # light green
73
  dark_green = 'rgba(65, 125, 65, 1)' # dark green - max value
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  style_municipals = {
77
  "layers": [
@@ -232,6 +267,16 @@ m.add_pmtiles(
232
  fit_bounds=False
233
  )
234
 
 
235
  m.add_layer_control()
236
  m.to_streamlit()
 
 
 
 
 
 
 
 
 
237
 
 
63
  import leafmap.maplibregl as leafmap
64
  m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
65
 
66
+ # url = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/landvote_polygons.pmtiles"
67
+ url = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/votes.pmtiles"
68
+ parties = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/votes.parquet"
69
 
70
  dark_orange = 'rgba(171, 86, 1, 1)' # dark orange - min value
71
  light_orange = 'rgba(243, 211, 177, 1)' # light orange
 
73
  light_green = 'rgba(195, 219, 195, 1)' # light green
74
  dark_green = 'rgba(65, 125, 65, 1)' # dark green - max value
75
 
76
+ con = ibis.duckdb.connect(extensions=["spatial"])
77
+
78
+ party = (con
79
+ .read_parquet(parties)
80
+ .cast({"geometry": "geometry"})
81
+ )
82
+
83
+
84
+ def get_summary(party, year):
85
+ total_measures = party.filter(_.year == year).count().execute()
86
+
87
+ df = (party
88
+ .filter(_.year == year)
89
+ .mutate(
90
+ # Convert 'amount' from string with '$' and ',' to numeric
91
+ amount_numeric=_.amount.replace('$', '').replace(',', '').cast('float64')
92
+ )
93
+ .group_by("party")
94
+ .aggregate(
95
+ percent_passed= (_.Status.isin(["Pass", "Pass*"]).sum() / total_measures).round(2),
96
+ approved_funds= ibis.case()
97
+ .when(_.Status.isin(["Pass", "Pass*"]), _.amount_numeric)
98
+ .else_(ibis.literal(0))
99
+ .end()
100
+ .sum()
101
+ )
102
+ .mutate(color=ibis.case()
103
+ .when(_.party == "DEMOCRAT", ibis.literal("#083A90"))
104
+ .else_(ibis.literal("#E81B23"))
105
+ .end())
106
+ )
107
+
108
+ df = df.to_pandas()
109
+ return df
110
 
111
  style_municipals = {
112
  "layers": [
 
267
  fit_bounds=False
268
  )
269
 
270
+
271
  m.add_layer_control()
272
  m.to_streamlit()
273
+ # st.dataframe(df)
274
+
275
+ df = get_summary(party, year)
276
+ st.bar_chart(df, x= "party",y = "percent_passed",color="color")
277
+
278
+ st.bar_chart(df, x= "party",y = "approved_funds",color="color")
279
+
280
+ # st.divider()
281
+ # footer = st.container()
282