cassiebuhler commited on
Commit
e5599e8
·
1 Parent(s): 6c124af

fixed percent_CA bug

Browse files

I was accidentally excluding the value "0" for connected & resilient networks. The percent protected was thus incorrect (24.74%). It's now fixed.

Files changed (3) hide show
  1. app/app.py +3 -3
  2. app/utils.py +6 -5
  3. app/variables.py +1 -10
app/app.py CHANGED
@@ -38,8 +38,8 @@ for col,val in style_options.items():
38
  for name in val['stops']:
39
  key = val['property']+str(name[0])
40
  if key not in st.session_state:
41
- st.session_state[key] = default_boxes.get(name[0], True)
42
-
43
  #customizing style with CSS
44
  st.markdown(app_formatting,unsafe_allow_html=True)
45
 
@@ -222,7 +222,7 @@ with st.sidebar:
222
  for label in style_options: # get selected filters (based on the buttons selected)
223
  with st.expander(label):
224
  if label in ["GAP Code","30x30 Status"]: # gap code 1 and 2 are on by default
225
- opts = get_buttons(style_options, label, default_boxes)
226
  else: # other buttons are not on by default.
227
  opts = get_buttons(style_options, label)
228
  filters.update(opts)
 
38
  for name in val['stops']:
39
  key = val['property']+str(name[0])
40
  if key not in st.session_state:
41
+ st.session_state[key] = True
42
+
43
  #customizing style with CSS
44
  st.markdown(app_formatting,unsafe_allow_html=True)
45
 
 
222
  for label in style_options: # get selected filters (based on the buttons selected)
223
  with st.expander(label):
224
  if label in ["GAP Code","30x30 Status"]: # gap code 1 and 2 are on by default
225
+ opts = get_buttons(style_options, label)
226
  else: # other buttons are not on by default.
227
  opts = get_buttons(style_options, label)
228
  filters.update(opts)
app/utils.py CHANGED
@@ -15,13 +15,12 @@ import re
15
  from variables import *
16
 
17
  ######################## UI FUNCTIONS
18
- def get_buttons(style_options, style_choice, default_boxes=None):
19
  """
20
  Creates Streamlit checkboxes based on style options and returns the selected filters.
21
  """
22
  column = style_options[style_choice]['property']
23
  opts = [style[0] for style in style_options[style_choice]['stops']]
24
- default_boxes = default_boxes or {}
25
 
26
  buttons = {}
27
  for name in opts:
@@ -92,7 +91,6 @@ def get_summary(ca, combined_filter, column, main_group, colors = None):
92
  "percent_CA": (_.acres.sum() / ca_area_acres),
93
  "acres": _.acres.sum(),
94
  }
95
-
96
  # add percent + acres aggregates
97
  dynamic_aggs = {}
98
  for key in keys:
@@ -102,7 +100,7 @@ def get_summary(ca, combined_filter, column, main_group, colors = None):
102
 
103
  # join all aggregates
104
  all_aggs = {**base_aggs, **dynamic_aggs}
105
-
106
  # group and aggregate
107
  df = (ca.filter(combined_filter)
108
  .group_by(*column)
@@ -117,8 +115,10 @@ def get_summary(ca, combined_filter, column, main_group, colors = None):
117
  )
118
 
119
  df = (df.inner_join(group_totals, main_group)
120
- .mutate(percent_group=( _.acres / _.total_acres).round(3))
 
121
  )
 
122
  # if colors is not None and not colors.empty:
123
  if colors is not None:
124
  df = df.inner_join(colors, column[-1])
@@ -155,6 +155,7 @@ def get_summary_table(ca, column, select_colors, color_choice, filter_cols, filt
155
 
156
  # df for stacked 30x30 status bar chart
157
  df_bar_30x30 = None if column in ["status", "gap_code"] else get_summary(ca, combined_filter, [column, 'status'], column, color_table(select_colors, "30x30 Status", 'status'))
 
158
  return df, df_tab, df_percent, df_bar_30x30
159
 
160
 
 
15
  from variables import *
16
 
17
  ######################## UI FUNCTIONS
18
+ def get_buttons(style_options, style_choice):
19
  """
20
  Creates Streamlit checkboxes based on style options and returns the selected filters.
21
  """
22
  column = style_options[style_choice]['property']
23
  opts = [style[0] for style in style_options[style_choice]['stops']]
 
24
 
25
  buttons = {}
26
  for name in opts:
 
91
  "percent_CA": (_.acres.sum() / ca_area_acres),
92
  "acres": _.acres.sum(),
93
  }
 
94
  # add percent + acres aggregates
95
  dynamic_aggs = {}
96
  for key in keys:
 
100
 
101
  # join all aggregates
102
  all_aggs = {**base_aggs, **dynamic_aggs}
103
+
104
  # group and aggregate
105
  df = (ca.filter(combined_filter)
106
  .group_by(*column)
 
115
  )
116
 
117
  df = (df.inner_join(group_totals, main_group)
118
+ # .mutate(percent_group=( _.acres / _.total_acres).round(3))
119
+ .mutate(percent_group=( _.acres / _.total_acres))
120
  )
121
+
122
  # if colors is not None and not colors.empty:
123
  if colors is not None:
124
  df = df.inner_join(colors, column[-1])
 
155
 
156
  # df for stacked 30x30 status bar chart
157
  df_bar_30x30 = None if column in ["status", "gap_code"] else get_summary(ca, combined_filter, [column, 'status'], column, color_table(select_colors, "30x30 Status", 'status'))
158
+
159
  return df, df_tab, df_percent, df_bar_30x30
160
 
161
 
app/variables.py CHANGED
@@ -213,16 +213,6 @@ app_formatting = """
213
  </style>
214
  """
215
 
216
- # gap codes 3 and 4 are off by default.
217
- default_boxes = {
218
- 0: False,
219
- # 3: False,
220
- # 4: False,
221
- # "other-conserved":False,
222
- # "unknown":False,
223
- # "non-conserved":False
224
- }
225
-
226
  # Maplibre styles. (should these be functions?)
227
  manager = {
228
  'property': 'manager_type',
@@ -429,6 +419,7 @@ style_options = {
429
  "Access Type": access,
430
  }
431
 
 
432
  select_column = {
433
  "30x30 Status": "status",
434
  "GAP Code": "gap_code",
 
213
  </style>
214
  """
215
 
 
 
 
 
 
 
 
 
 
 
216
  # Maplibre styles. (should these be functions?)
217
  manager = {
218
  'property': 'manager_type',
 
419
  "Access Type": access,
420
  }
421
 
422
+ print(style_options)
423
  select_column = {
424
  "30x30 Status": "status",
425
  "GAP Code": "gap_code",