Les statistiques fonctionnent à la fois pour mysql et sqlite, en utilisant des requêtes spécifiques pour extraction des mois et année

This commit is contained in:
echarp 2014-10-24 01:33:50 +02:00
parent 2001e2ae1c
commit 37c0829b6f
3 changed files with 24 additions and 18 deletions

View File

@ -7,17 +7,26 @@ class RegionsController < InheritedResources::Base
@city_events = Event.group(:city).having('count(city) > 3') @city_events = Event.group(:city).having('count(city) > 3')
.order('count(city) desc').count :city .order('count(city) desc').count :city
# Used in sqlite @year_events = Event.group(year_grouping).count
# .group('strftime("%Y", start_time)')
@year_events = Event
.group('extract(year from start_time)').count
# Used in sqlite @month_events = Event.group(year_grouping, month_grouping).count
# .group('strftime("%Y", start_time)') end
# .group('strftime("%m", start_time)')
@month_events = Event private
.group('extract(year from start_time)')
.group('extract(month from start_time)') def year_grouping
.count 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
end end

View File

@ -25,8 +25,9 @@
%th.month= I18n.t('date.month_names')[m] %th.month= I18n.t('date.month_names')[m]
- @year_events.each do |year| - @year_events.each do |year|
%td.quantity %td.quantity
- line = @month_events.find { |line| line[0][0] == year[0] && line[0][1] == m } - line = @month_events.find { |line| line[0][0] == year[0] && line[0][1].try(:to_i) == m }
= number_with_delimiter line[1] if line = link_to root_url(start_date: "#{year[0]}-#{m}-01") do
= number_with_delimiter line[1] if line
%td.sparkline/ %td.sparkline/
%tfoot %tfoot

View File

@ -1,12 +1,8 @@
development_old: development:
adapter: sqlite3 adapter: sqlite3
pool: 5 pool: 5
timeout: 5000 timeout: 5000
database: db/development.sqlite3 database: db/development.sqlite3
development:
adapter: mysql2
database: adl_fr
username: manu
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".