diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 7b2dc480..532ec544 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -20,7 +20,10 @@ class StatsController < ApplicationController end def local - @regions = @events.joins(:region).group(:region_id, year_grouping).count + @region_events = @events.group(:region_id, year_grouping).count + @regions = Region.all.find_all do |region| + @years.sum { |year| @region_events[[region.id, year[0]]] || 0 } > 0 + end @city_events = @events.group(:city).having('count(city) > 3') .order('count(city) desc').count end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 75515bd4..db51f92c 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -61,15 +61,15 @@ %th= t '.total' %th/ %tbody - - Region.all.each do |region| + - @regions.each do |region| %tr %th.region= region - total = 0 - @years.each do |year| %td.quantity - - total += @regions[[region.id, year[0]]] || 0 + - total += @region_events[[region.id, year[0]]] || 0 = link_to root_path(year: year[0].to_s, region: region.id) do - = number_with_delimiter @regions[[region.id, year[0]]] + = number_with_delimiter @region_events[[region.id, year[0]]] %th.quantity.total= number_with_delimiter total %td.sparkline/