Statistiques par région et année

This commit is contained in:
echarp 2014-11-06 00:23:01 +01:00
parent 4c6f0908af
commit d9b69aff05
3 changed files with 33 additions and 23 deletions

View File

@ -7,12 +7,14 @@ $(document).ready ->
$(this).find('.sparkline').sparkline vals, width: '5em'
vals = $('table.list.dates tfoot th.quantity').map ->
$('table.list.dates tfoot').each ->
vals = $(this).find('th.quantity').map ->
return parseInt $(this).html().replace(' ', '')
$('tfoot .sparkline').sparkline vals,
$(this).find('.sparkline').sparkline vals,
type: 'bar'
height: '3em'
barWidth: '80em'
barWidth: '100%'
barColor: '#9CC5EE'
barSpacing: 2

View File

@ -5,13 +5,12 @@ class StatsController < ApplicationController
private
def set_temporal
@year_events = Event.group(year_grouping).count
@month_events = Event.group(year_grouping, month_grouping).count
@years = Event.group(year_grouping).count
@months = Event.group(year_grouping, month_grouping).count
end
def set_local
@region_events = Event.joins(:related_region).group(:name)
.order('count(name) desc').count
@regions = Event.joins(:related_region).group(:region, year_grouping).count
@city_events = Event.group(:city).having('count(city) > 3')
.order('count(city) desc').count
end

View File

@ -17,15 +17,15 @@
%thead
%tr
%th/
- @year_events.each do |year|
- @years.each do |year|
%th= year[0]
%tbody
- (1..12).each do |m|
%tr
%th.month= I18n.t('date.month_names')[m]
- @year_events.each do |year|
- @years.each do |year|
%td.quantity
- line = @month_events.find { |line| line[0][0] == year[0] && line[0][1].try(:to_i) == m }
- line = @months.find { |line| line[0][0] == year[0] && line[0][1].try(:to_i) == m }
= link_to root_path(start_date: "#{year[0]}-#{m}-01") do
= number_with_delimiter line[1] if line
%td.sparkline/
@ -33,23 +33,32 @@
%tfoot
%tr
%th=t '.total'
- @year_events.each do |year|
- @years.each do |year|
%th.quantity= number_with_delimiter year[1]
%tr
%th/
%td.sparkline(colspan="#{@year_events.size}")/
%td.sparkline(colspan="#{@years.size}")/
%h3
%em.fa.fa-shield
=t '.regional'
%dl
- @region_events.each do |region|
%dt.item
= link_to root_path region: Region.find_by_name(region[0]).id do
= region[0]
%dd.quantity= number_with_delimiter region[1]
%table.list.dates
%thead
%tr
%th/
- @years.each do |year|
%th= year[0]
%tbody
- Region.all.each do |region|
%tr
%th.month= region
- @years.each do |year|
%td.quantity
= link_to root_path(year: "#{year[0]}", region: region.id) do
= number_with_delimiter @regions[[region.id, year[0]]]
%td.sparkline/
%h3=t '.city'