cassiebuhler commited on
Commit
6560afd
·
1 Parent(s): 9d9a528
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -74,21 +74,22 @@ nonprofit_color = "#D77031" #orange
74
  from functools import reduce
75
 
76
  def get_summary(ca, combined_filter, column, colors=None):
77
- df = (ca
78
- .filter(combined_filter)
 
 
 
 
79
  .group_by(*column) # unpack the list for grouping
80
  .aggregate(percent_protected=100 * _.Acres.sum() / ca_area_acres)
81
  .mutate(percent_protected=_.percent_protected.round(1))
82
- )
83
 
84
- if colors is not None and not colors.empty: # df used for chart.
85
- df = (df #add color column + only gaps 1 and 2.
86
- .filter(_.reGAP <3)
87
- .inner_join(colors, column)
88
- )
89
- # df = df.inner_join(colors, column)
90
 
91
- df = df.cast({col: "string" for col in column})
92
  df = df.to_pandas()
93
  return df
94
 
@@ -105,7 +106,7 @@ def summary_table(column, colors, filter_cols, filter_vals):
105
  filters.append(getattr(_, filter_col) == filter_val[0])
106
 
107
  combined_filter = reduce(lambda x, y: x & y, filters)
108
-
109
  df = get_summary(ca, combined_filter, [column], colors) # df used for charts
110
  df_tab = get_summary(ca, combined_filter, filter_cols, colors = None) #df used for printed table
111
 
 
74
  from functools import reduce
75
 
76
  def get_summary(ca, combined_filter, column, colors=None):
77
+ df = ca.filter(combined_filter)
78
+
79
+ if colors is not None and not colors.empty: # df used for chart.
80
+ df = df.filter(_.reGAP <3) # only show gaps 1 and 2 for chart.
81
+
82
+ df = (df
83
  .group_by(*column) # unpack the list for grouping
84
  .aggregate(percent_protected=100 * _.Acres.sum() / ca_area_acres)
85
  .mutate(percent_protected=_.percent_protected.round(1))
86
+ )
87
 
88
+ if colors is not None and not colors.empty: #
89
+ df = df.inner_join(colors, column) # chart colors
90
+
 
 
 
91
 
92
+ df = df.cast({col: "string" for col in column})
93
  df = df.to_pandas()
94
  return df
95
 
 
106
  filters.append(getattr(_, filter_col) == filter_val[0])
107
 
108
  combined_filter = reduce(lambda x, y: x & y, filters)
109
+
110
  df = get_summary(ca, combined_filter, [column], colors) # df used for charts
111
  df_tab = get_summary(ca, combined_filter, filter_cols, colors = None) #df used for printed table
112