Nettoyage de code pour suivre les dernières métriques ABC
parent
542abdf7de
commit
bb5a037356
@ -1,32 +1,3 @@
|
||||
# Manage regions, mostly get stats out of them
|
||||
class RegionsController < InheritedResources::Base
|
||||
def stats
|
||||
@region_events = Event.joins(:related_region).group(:name)
|
||||
.order('count(name) desc').count :name
|
||||
|
||||
@city_events = Event.group(:city).having('count(city) > 3')
|
||||
.order('count(city) desc').count :city
|
||||
|
||||
@year_events = Event.group(year_grouping).count
|
||||
|
||||
@month_events = Event.group(year_grouping, month_grouping).count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def year_grouping
|
||||
if %w(Mysql2 MySQL PostgreSQL).include? Event.connection.adapter_name
|
||||
'extract(year from start_time)'
|
||||
elsif Event.connection.adapter_name == 'SQLite'
|
||||
'strftime("%Y", start_time)'
|
||||
end
|
||||
end
|
||||
|
||||
def month_grouping
|
||||
if %w(Mysql2 MySQL PostgreSQL).include? Event.connection.adapter_name
|
||||
'extract(month from start_time)'
|
||||
elsif Event.connection.adapter_name == 'SQLite'
|
||||
'strftime("%m", start_time)'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,34 @@
|
||||
# Generate statistics, around events, by date or place
|
||||
class StatsController < ApplicationController
|
||||
before_action :set_temporal, :set_local, only: [:index]
|
||||
|
||||
private
|
||||
|
||||
def set_temporal
|
||||
@year_events = Event.group(year_grouping).count
|
||||
@month_events = Event.group(year_grouping, month_grouping).count
|
||||
end
|
||||
|
||||
def set_local
|
||||
@region_events = Event.joins(:related_region).group(:name)
|
||||
.order('count(name) desc').count
|
||||
@city_events = Event.group(:city).having('count(city) > 3')
|
||||
.order('count(city) desc').count
|
||||
end
|
||||
|
||||
def year_grouping
|
||||
if %w(Mysql2 MySQL PostgreSQL).include? Event.connection.adapter_name
|
||||
'extract(year from start_time)'
|
||||
elsif Event.connection.adapter_name == 'SQLite'
|
||||
'strftime("%Y", start_time)'
|
||||
end
|
||||
end
|
||||
|
||||
def month_grouping
|
||||
if %w(Mysql2 MySQL PostgreSQL).include? Event.connection.adapter_name
|
||||
'extract(month from start_time)'
|
||||
elsif Event.connection.adapter_name == 'SQLite'
|
||||
'strftime("%m", start_time)'
|
||||
end
|
||||
end
|
||||
end
|