Skip to content
Extraits de code Groupes Projets
Valider 37c0829b rédigé par echarp's avatar echarp
Parcourir les fichiers

Les statistiques fonctionnent à la fois pour mysql et sqlite, en utilisant des...

Les statistiques fonctionnent à la fois pour mysql et sqlite, en utilisant des requêtes spécifiques pour extraction des mois et année
parent 2001e2ae
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -7,17 +7,26 @@ class RegionsController < InheritedResources::Base
@city_events = Event.group(:city).having('count(city) > 3')
.order('count(city) desc').count :city
# Used in sqlite
# .group('strftime("%Y", start_time)')
@year_events = Event
.group('extract(year from start_time)').count
@year_events = Event.group(year_grouping).count
# Used in sqlite
# .group('strftime("%Y", start_time)')
# .group('strftime("%m", start_time)')
@month_events = Event
.group('extract(year from start_time)')
.group('extract(month from start_time)')
.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
......@@ -25,8 +25,9 @@
%th.month= I18n.t('date.month_names')[m]
- @year_events.each do |year|
%td.quantity
- line = @month_events.find { |line| line[0][0] == year[0] && line[0][1] == m }
= number_with_delimiter line[1] if line
- line = @month_events.find { |line| line[0][0] == year[0] && line[0][1].try(:to_i) == m }
= link_to root_url(start_date: "#{year[0]}-#{m}-01") do
= number_with_delimiter line[1] if line
%td.sparkline/
%tfoot
......
development_old:
development:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/development.sqlite3
development:
adapter: mysql2
database: adl_fr
username: manu
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter