Skip to content

Commit

Permalink
analytics: Fix sort function in views.sort_client_labels.
Browse files Browse the repository at this point in the history
sort_client_labels sorts first by total, and then to ensure deterministic
outcomes, sorts (reverse) alphabetically by label.

Fixes regression introduced in 0c0e539.
  • Loading branch information
rishig authored and timabbott committed May 9, 2017
1 parent 0414ac6 commit ee16aba
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions analytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ def get_chart_data(request, user_profile, chart_name=REQ(),

def sort_by_totals(value_arrays):
# type: (Dict[str, List[int]]) -> List[str]
totals = []
for label, values in value_arrays.items():
totals.append((label, sum(values)))
totals.sort(key=lambda label_total: "%s:%s" % (label_total[1], label_total[0]), reverse=True)
return [label for label, total in totals]
totals = [(sum(values), label) for label, values in value_arrays.items()]
totals.sort(reverse=True)
return [label for total, label in totals]

# For any given user, we want to show a fixed set of clients in the chart,
# regardless of the time aggregation or whether we're looking at realm or
Expand Down

0 comments on commit ee16aba

Please sign in to comment.