From 201e851fd3cb414b596f911a5eb4e004d70e4935 Mon Sep 17 00:00:00 2001 From: Bodo Tasche Date: Sun, 1 Feb 2015 15:20:07 +0100 Subject: [PATCH] Fixed statistics page for postgres, closes #515 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and added i18n along the way. Should we add this page to the menu somehow and add more text that explains the numbers? --- app/controllers/statistics_controller.rb | 8 +++++--- app/models/region.rb | 2 ++ app/views/statistics/_other_regions.html.haml | 3 +++ app/views/statistics/index.html.haml | 7 +++---- app/views/statistics/show.html.haml | 11 +++-------- config/locales/de.yml | 6 ++++++ config/locales/en.yml | 6 ++++++ 7 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 app/views/statistics/_other_regions.html.haml diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index 0968052f..5cfa660a 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -5,12 +5,14 @@ def index end def show - week_data = SingleEvent.in_region(@current_region).where("occurrence <= ?", Date.yesterday).group("weekday(occurrence)").count + week_data = SingleEvent.unscoped.in_region(@current_region).where("occurrence <= ?", Date.yesterday).select("extract('dow' from occurrence) as dow, count(*)").group("extract('dow' from occurrence)") day_names = I18n.t(:"date.day_names").rotate - @chart_data = week_data.keys.sort.map do |key| - [day_names[key], week_data[key]] + @chart_data = day_names.map {|name| [name, 0] } + + week_data.map do |key| + @chart_data[key.dow - 1][1] = key.count end end diff --git a/app/models/region.rb b/app/models/region.rb index 15b6bebb..474cb1d9 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -5,6 +5,8 @@ class Region < ActiveRecord::Base has_many :region_organizers has_many :organizers, :through => :region_organizers, :source => :user + scope :active, -> { where(active: true) } + def to_param "#{self.id}-#{self.slug}" end diff --git a/app/views/statistics/_other_regions.html.haml b/app/views/statistics/_other_regions.html.haml new file mode 100644 index 00000000..0a7179be --- /dev/null +++ b/app/views/statistics/_other_regions.html.haml @@ -0,0 +1,3 @@ +%ul + - Region.active.each do |region| + %li= link_to region.name, show_statistic_path(region: region.slug) diff --git a/app/views/statistics/index.html.haml b/app/views/statistics/index.html.haml index 9558a6a0..47045cf7 100644 --- a/app/views/statistics/index.html.haml +++ b/app/views/statistics/index.html.haml @@ -1,5 +1,4 @@ -%h2 Statistiken +%h2= t("statistics.index.headline") + += render partial: 'other_regions' -%ul - - Region.all.each do |region| - %li= link_to region.name, show_statistic_path(region: region.slug) diff --git a/app/views/statistics/show.html.haml b/app/views/statistics/show.html.haml index 748dd766..8d437478 100644 --- a/app/views/statistics/show.html.haml +++ b/app/views/statistics/show.html.haml @@ -1,12 +1,7 @@ -%h2 Statistiken für #{@current_region.name} +%h2= t("statistics.show.headline", region: @current_region.name) -%h3 Wochentage +%h3= t("statistics.show.weekdays") = column_chart @chart_data -%p - Weitere Statistiken für - -%ul - - Region.all.each do |region| - %li= link_to region.name, show_statistic_path(region: region.slug) += render partial: 'other_regions' diff --git a/config/locales/de.yml b/config/locales/de.yml index 8b298e81..cf6562c3 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -265,3 +265,9 @@ de: next_label: Nächste → page_gap: "…" previous_label: "← Zurück" + statistics: + index: + headline: "Statistiken" + show: + headline: "Statistiken für %{region}" + weekdays: "Wochentage" diff --git a/config/locales/en.yml b/config/locales/en.yml index 5f2e9a50..f8fccec6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -265,3 +265,9 @@ en: next_label: Next → page_gap: "…" previous_label: "← Back" + statistics: + index: + headline: "Statistics" + show: + headline: "Statistics for %{region}" + weekdays: "Weekdays"