Statistics only display data for the selected region

This commit is contained in:
echarp 2017-07-02 14:13:09 +02:00
parent 208fe78178
commit 491287ed01
2 changed files with 7 additions and 4 deletions

View File

@ -20,7 +20,10 @@ class StatsController < ApplicationController
end end
def local 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') @city_events = @events.group(:city).having('count(city) > 3')
.order('count(city) desc').count .order('count(city) desc').count
end end

View File

@ -61,15 +61,15 @@
%th= t '.total' %th= t '.total'
%th/ %th/
%tbody %tbody
- Region.all.each do |region| - @regions.each do |region|
%tr %tr
%th.region= region %th.region= region
- total = 0 - total = 0
- @years.each do |year| - @years.each do |year|
%td.quantity %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 = 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 %th.quantity.total= number_with_delimiter total
%td.sparkline/ %td.sparkline/