Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #560 from hacken-in/bugs/515-statement-invalid-in-…
Browse files Browse the repository at this point in the history
…statistics-show

Fixed statistics page for postgres, closes #515
  • Loading branch information
bascht committed Feb 5, 2015
2 parents d78818a + 201e851 commit 8e50aff
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
8 changes: 5 additions & 3 deletions app/controllers/statistics_controller.rb
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/models/region.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions 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)
7 changes: 3 additions & 4 deletions 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)
11 changes: 3 additions & 8 deletions 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'
6 changes: 6 additions & 0 deletions config/locales/de.yml
Expand Up @@ -269,3 +269,9 @@ de:
next_label: Nächste &#8594;
page_gap: "&hellip;"
previous_label: "&#8592; Zurück"
statistics:
index:
headline: "Statistiken"
show:
headline: "Statistiken für %{region}"
weekdays: "Wochentage"
6 changes: 6 additions & 0 deletions config/locales/en.yml
Expand Up @@ -269,3 +269,9 @@ en:
next_label: Next &#8594;
page_gap: "&hellip;"
previous_label: "&#8592; Back"
statistics:
index:
headline: "Statistics"
show:
headline: "Statistics for %{region}"
weekdays: "Weekdays"

0 comments on commit 8e50aff

Please sign in to comment.