2014-11-05 21:25:18 +01:00
|
|
|
# Generate statistics, around events, by date or place
|
|
|
|
class StatsController < ApplicationController
|
|
|
|
before_action :set_temporal, :set_local, only: [:index]
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_temporal
|
2014-11-06 00:23:01 +01:00
|
|
|
@years = Event.group(year_grouping).count
|
|
|
|
@months = Event.group(year_grouping, month_grouping).count
|
2014-11-05 21:25:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_local
|
2015-02-15 15:56:27 +01:00
|
|
|
@regions = Event.joins(:region).group(:region_id, year_grouping).count
|
2014-11-05 21:25:18 +01:00
|
|
|
@city_events = Event.group(:city).having('count(city) > 3')
|
2016-02-13 17:24:23 +01:00
|
|
|
.order('count(city) desc').count
|
2014-11-05 21:25:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def year_grouping
|
2017-04-22 20:01:47 +02:00
|
|
|
if %w[Mysql2 MySQL PostgreSQL].include? Event.connection.adapter_name
|
2014-11-05 21:25:18 +01:00
|
|
|
'extract(year from start_time)'
|
|
|
|
elsif Event.connection.adapter_name == 'SQLite'
|
|
|
|
'strftime("%Y", start_time)'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def month_grouping
|
2017-04-22 20:01:47 +02:00
|
|
|
if %w[Mysql2 MySQL PostgreSQL].include? Event.connection.adapter_name
|
2014-11-05 21:25:18 +01:00
|
|
|
'extract(month from start_time)'
|
|
|
|
elsif Event.connection.adapter_name == 'SQLite'
|
|
|
|
'strftime("%m", start_time)'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|