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
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
def set_temporal
@years = Event.group(year_grouping).count
@months = Event.group(year_grouping, month_grouping).count
def counts
@events_count = @events.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
def set_local
@regions = Event.joins(:region).group(:region_id, year_grouping).count
@city_events = Event.group(:city).having('count(city) > 3')
.order('count(city) desc').count
def temporal
@years = @events.group(year_grouping).count
@months = @events.group(year_grouping, month_grouping).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
def year_grouping

View File

@ -4,16 +4,16 @@
%dl
%dt= t '.allEvents'
%dd.quantity= number_with_delimiter Event.moderated.count
%dd.quantity= number_with_delimiter @events_count
%dt= t '.awaitingModeration'
%dd.quantity= number_with_delimiter Event.unmoderated.count
%dd.quantity= number_with_delimiter @events_um_count
%dt= t '.allOrgas'
%dd.quantity= number_with_delimiter Orga.moderated.count
%dd.quantity= number_with_delimiter @orgas_count
%dt= t '.awaitingModeration'
%dd.quantity= number_with_delimiter Orga.unmoderated.count
%dd.quantity= number_with_delimiter @orgas_um_count
%h3
%em.fa.fa-calendar
@ -68,7 +68,7 @@
- @years.each do |year|
%td.quantity
- 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]]]
%th.quantity.total= number_with_delimiter total
%td.sparkline/