Stats can be filtered using the regions selector at the top

This commit is contained in:
echarp 2017-07-02 13:28:10 +02:00
parent 7e188aa5f1
commit 208fe78178
2 changed files with 27 additions and 13 deletions

View File

@ -1,18 +1,32 @@
# Generate statistics, around events, by date or place # Generate statistics, around events, by date or place
class StatsController < ApplicationController class StatsController < ApplicationController
before_action :set_temporal, :set_local, only: [:index] has_scope :region, :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
before_action :set_events, :counts, :temporal, :local, only: [:index]
private private
def set_temporal def counts
@years = Event.group(year_grouping).count @events_count = @events.count
@months = Event.group(year_grouping, month_grouping).count @events_um_count = apply_scopes(Event.unmoderated).count
@orgas_count = apply_scopes(Orga).moderated.count
@orgas_um_count = apply_scopes(Orga.unmoderated).count
end end
def set_local def temporal
@regions = Event.joins(:region).group(:region_id, year_grouping).count @years = @events.group(year_grouping).count
@city_events = Event.group(:city).having('count(city) > 3') @months = @events.group(year_grouping, month_grouping).count
.order('count(city) desc').count end
def local
@regions = @events.joins(:region).group(:region_id, year_grouping).count
@city_events = @events.group(:city).having('count(city) > 3')
.order('count(city) desc').count
end
def set_events
@events = apply_scopes Event.moderated
end end
def year_grouping def year_grouping

View File

@ -4,16 +4,16 @@
%dl %dl
%dt= t '.allEvents' %dt= t '.allEvents'
%dd.quantity= number_with_delimiter Event.moderated.count %dd.quantity= number_with_delimiter @events_count
%dt= t '.awaitingModeration' %dt= t '.awaitingModeration'
%dd.quantity= number_with_delimiter Event.unmoderated.count %dd.quantity= number_with_delimiter @events_um_count
%dt= t '.allOrgas' %dt= t '.allOrgas'
%dd.quantity= number_with_delimiter Orga.moderated.count %dd.quantity= number_with_delimiter @orgas_count
%dt= t '.awaitingModeration' %dt= t '.awaitingModeration'
%dd.quantity= number_with_delimiter Orga.unmoderated.count %dd.quantity= number_with_delimiter @orgas_um_count
%h3 %h3
%em.fa.fa-calendar %em.fa.fa-calendar
@ -68,7 +68,7 @@
- @years.each do |year| - @years.each do |year|
%td.quantity %td.quantity
- total += @regions[[region.id, year[0]]] || 0 - total += @regions[[region.id, year[0]]] || 0
= link_to root_path(year: "#{year[0]}", 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 @regions[[region.id, year[0]]]
%th.quantity.total= number_with_delimiter total %th.quantity.total= number_with_delimiter total
%td.sparkline/ %td.sparkline/