Skip to content

Commit

Permalink
Fix default report X and Y axis selectors (#4542)
Browse files Browse the repository at this point in the history
* fix default reports and code duplication in inventory_filter

* fix default dropdown selections

* remove old test

---------

Co-authored-by: Hannah Eslinger <[email protected]>
  • Loading branch information
kflemin and haneslinger authored Feb 26, 2024
1 parent cb8c7af commit 148a432
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions seed/static/seed/partials/inventory_reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ <h2 style="font-size: 18px"><i class="fa-solid fa-bar-chart pull-left"></i> {$::
<div style="display: flex; flex-direction: column;">
<div class="form-group pad-bottom-10">
<label for="xAxisSelector">{$:: 'X Axis' | translate $}:</label>
<sd-dropdown is-button id="xAxisSelector" ng-model="xAxisSelectedItem" items="xAxisVars"></sd-dropdown>
<select class="form-control" id="xAxisSelector" ng-model="xAxisSelectedItem" ng-options="x.name for x in xAxisVars track by x.varName"></select>
</div>

<div class="form-group">
<label for="yAxisSelector">{$:: 'Y Axis' | translate $}:</label>
<sd-dropdown is-button id="yAxisSelector" ng-model="yAxisSelectedItem" items="yAxisVars"></sd-dropdown>
<select class="form-control" id="yAxisSelector" ng-model="yAxisSelectedItem" ng-options="y.name for y in yAxisVars track by y.varName"></select>
</div>
</div>
<div class="form-group">
Expand Down
3 changes: 3 additions & 0 deletions seed/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def split_model_fields(obj, fields):
def median(lst):
if not lst:
return
# ensure list of not a bunch of "None"
if set(lst) is {None}:
return
index = (len(lst) - 1) // 2
if len(lst) % 2:
#
Expand Down
21 changes: 12 additions & 9 deletions seed/views/v3/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ def report_aggregated(self, request, pk=None):
# get data
cycles = Cycle.objects.filter(id__in=params["cycle_ids"])
data = self.get_raw_report_data(pk, access_level_instance, cycles, params["x_var"], params["y_var"])

chart_data = []
property_counts = []
for datum in data:
Expand Down Expand Up @@ -1035,13 +1034,15 @@ def aggregate_property_type(self, yr_e, x_var, buildings):
grouped_uses[str(b['y']).lower()].append(b)

# Now iterate over use groups to make each chart item
# Only include non-None values
for use, buildings_in_uses in grouped_uses.items():
x = [b['x'] for b in buildings_in_uses]
chart_data.append({
'x': sum(x) if x_var == "Count" else median(x),
'y': use.capitalize(),
'yr_e': yr_e
})
x = [b['x'] for b in buildings_in_uses if b['x'] is not None]
if x:
chart_data.append({
'x': sum(x) if x_var == "Count" else median(x),
'y': use.capitalize(),
'yr_e': yr_e
})
return chart_data

def aggregate_year_built(self, yr_e, x_var, buildings):
Expand All @@ -1053,7 +1054,7 @@ def aggregate_year_built(self, yr_e, x_var, buildings):

# Now iterate over decade groups to make each chart item
for decade, buildings_in_decade in grouped_decades.items():
x = [b['x'] for b in buildings_in_decade]
x = [b['x'] for b in buildings_in_decade if b['x'] is not None]
chart_data.append({
'x': sum(x) if x_var == "Count" else median(x),
'y': '%s-%s' % (decade, '%s9' % str(decade)[:-1]), # 1990-1999
Expand Down Expand Up @@ -1081,6 +1082,8 @@ def aggregate_gross_floor_area(self, yr_e, x_var, buildings):
# Group buildings in this year_ending group into ranges
grouped_ranges = defaultdict(list)
for b in buildings:
if b['y'] is None:
continue
area = b['y']
# make sure anything greater than the biggest bin gets put in
# the biggest bin
Expand All @@ -1089,7 +1092,7 @@ def aggregate_gross_floor_area(self, yr_e, x_var, buildings):

# Now iterate over range groups to make each chart item
for range_floor, buildings_in_range in grouped_ranges.items():
x = [b['x'] for b in buildings_in_range]
x = [b['x'] for b in buildings_in_range if b['x'] is not None]
chart_data.append({
'x': sum(x) if x_var == "Count" else median(x),
'y': y_display_map[range_floor],
Expand Down

0 comments on commit 148a432

Please sign in to comment.