Meilleurs stats par dates, avec sparklines

This commit is contained in:
echarp 2014-10-19 16:20:44 +02:00
parent d8492dbae7
commit 0fe4fa8eb5
12 changed files with 90 additions and 18 deletions

View File

@ -56,7 +56,7 @@ gem 'devise-i18n'
gem 'rails-i18n' gem 'rails-i18n'
# Store some specific content, like application name and static pages contents # Store some specific content, like application name and static pages contents
gem 'i18n-active_record', gem 'i18n-active_record',
git: 'git://github.com/svenfuchs/i18n-active_record.git', github: 'svenfuchs/i18n-active_record',
require: 'i18n/active_record' require: 'i18n/active_record'
gem 'http_accept_language' gem 'http_accept_language'
@ -74,6 +74,8 @@ gem 'activeadmin', github: 'gregbell/active_admin'
# A nicer markdown editor in active admin # A nicer markdown editor in active admin
gem 'activeadmin_pagedown' gem 'activeadmin_pagedown'
gem 'jquery-sparkline-rails', github: 'cubus/jquery-sparkline-rails'
# Markdown display # Markdown display
gem 'redcarpet' gem 'redcarpet'

View File

@ -1,3 +1,11 @@
GIT
remote: git://github.com/cubus/jquery-sparkline-rails.git
revision: 5c2ced0fa68e5e099bec82b67bdf71f9d865da8a
specs:
jquery-sparkline-rails (2.1.1)
jquery-rails
rails (>= 3.2.2)
GIT GIT
remote: git://github.com/gregbell/active_admin.git remote: git://github.com/gregbell/active_admin.git
revision: 05778f4b7c8e821d584c7b4b08bcd79c02a0db76 revision: 05778f4b7c8e821d584c7b4b08bcd79c02a0db76
@ -87,7 +95,7 @@ GEM
builder (3.2.2) builder (3.2.2)
celluloid (0.16.0) celluloid (0.16.0)
timers (~> 4.0.0) timers (~> 4.0.0)
chunky_png (1.3.1) chunky_png (1.3.2)
coderay (1.1.0) coderay (1.1.0)
coffee-rails (4.1.0) coffee-rails (4.1.0)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
@ -176,7 +184,7 @@ GEM
inherited_resources (1.4.1) inherited_resources (1.4.1)
has_scope (~> 0.6.0.rc) has_scope (~> 0.6.0.rc)
responders (~> 1.0.0.rc) responders (~> 1.0.0.rc)
jbuilder (2.2.2) jbuilder (2.2.3)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
jquery-rails (3.1.2) jquery-rails (3.1.2)
@ -185,7 +193,7 @@ GEM
jquery-turbolinks (2.1.0) jquery-turbolinks (2.1.0)
railties (>= 3.1.0) railties (>= 3.1.0)
turbolinks turbolinks
jquery-ui-rails (5.0.1) jquery-ui-rails (5.0.2)
railties (>= 3.2.16) railties (>= 3.2.16)
json (1.8.1) json (1.8.1)
kaminari (0.16.1) kaminari (0.16.1)
@ -376,6 +384,7 @@ DEPENDENCIES
i18n-active_record! i18n-active_record!
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
jquery-sparkline-rails!
jquery-turbolinks jquery-turbolinks
leaflet-rails leaflet-rails
meta-tags meta-tags

View File

@ -12,6 +12,7 @@
# #
#= require jquery #= require jquery
#= require jquery_ujs #= require jquery_ujs
#= require jquery.sparkline
#= require jquery.turbolinks #= require jquery.turbolinks
#= require turbolinks #= require turbolinks
#= require tinymce-jquery #= require tinymce-jquery

View File

@ -0,0 +1,17 @@
$(document).ready ->
$('table.list.dates tbody tr').each ->
vals = $(this).find('td.quantity').map ->
val = $(this).html().replace(' ', '').trim()
if (val != '')
return parseInt val
$(this).find('.sparkline').sparkline vals, width: '5em'
vals = $('table.list.dates tfoot th.quantity').map ->
return parseInt $(this).html().replace(' ', '')
$('tfoot .sparkline').sparkline vals,
type: 'bar'
height: '3em'
barWidth: '100%'
barColor: '#9CC5EE'

View File

@ -22,6 +22,9 @@ p.full_address
span:last-child:after span:last-child:after
content: '' content: ''
.calendar-header, .month
text-transform: capitalize
body.events.index table body.events.index table
width: 90% width: 90%
max-width: 100% max-width: 100%

View File

@ -1,5 +1,8 @@
@import compass @import compass
.quantity
text-align: right
table table
margin: 1em auto margin: 1em auto
border-spacing: 2px border-spacing: 2px
@ -16,8 +19,6 @@ table
font-size: larger font-size: larger
td td
padding: 0.2em padding: 0.2em
&.quantity
text-align: right
dl dl
margin: 1em auto margin: 1em auto
@ -32,7 +33,6 @@ dl
padding: 0.2em 1em padding: 0.2em 1em
text-align: left text-align: left
&.quantity &.quantity
text-align: right
padding-right: 16em padding-right: 16em
h3 h3
display: inline display: inline

View File

@ -33,3 +33,6 @@
body.stats h3 body.stats h3
text-align: center text-align: center
.sparkline
padding: 0

View File

@ -6,6 +6,12 @@ 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
# .group('strftime("%Y", start_time)')
@year_events = Event
.group('extract(year from start_time)')
.count
# Used in sqlite # Used in sqlite
# .group('strftime("%Y", start_time)') # .group('strftime("%Y", start_time)')
# .group('strftime("%m", start_time)') # .group('strftime("%m", start_time)')

View File

@ -9,7 +9,39 @@
%dt=t '.allModeration' %dt=t '.allModeration'
%dd.quantity= number_with_delimiter Event.unscoped.where(moderated: 0).count() %dd.quantity= number_with_delimiter Event.unscoped.where(moderated: 0).count()
%h3=t '.regional' %h3
%em.fa.fa-calendar
=t '.dates'
%table.list.dates
%thead
%tr
%th/
- @year_events.each do |year|
%th= year[0]
%tbody
- (1..12).each do |m|
%tr
%td.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
%td.sparkline/
%tfoot
%tr
%th=t '.total'
- @year_events.each do |year|
%th.quantity= number_with_delimiter year[1]
%tr
%th/
%td.sparkline(colspan="#{@year_events.size}")/
%h3
%em.fa.fa-shield
=t '.regional'
%dl %dl
- @region_events.each do |region| - @region_events.each do |region|
@ -25,13 +57,6 @@
%dt.item= city[0] %dt.item= city[0]
%dd.quantity= number_with_delimiter city[1] %dd.quantity= number_with_delimiter city[1]
%h3=t '.dates'
%dl
- @month_events.each do |month|
%dt.item= l(Date.new(month[0][0].to_i, month[0][1].to_i), format: :month).capitalize
%dd.quantity= number_with_delimiter month[1]
%h3=t '.web' %h3=t '.web'
:markdown :markdown

View File

@ -1,8 +1,12 @@
development: development_old:
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".

View File

@ -134,11 +134,12 @@ it more readable or agreable.
title: Statistics title: Statistics
all: Validated events all: Validated events
allModeration: Events waiting for validation allModeration: Events waiting for validation
dates: Per date
regional: Per region regional: Per region
city: Per city city: Per city
city_conditions: Only cities where more than 3 events have been organised city_conditions: Only cities where more than 3 events have been organised
are displayed. are displayed.
dates: Per date total: Total
web: Web statistics web: Web statistics
webalizer: Statistics generated by Webalizer [are webalizer: Statistics generated by Webalizer [are
available](http://agendadulibre.org/stats/). They are protected by available](http://agendadulibre.org/stats/). They are protected by

View File

@ -132,11 +132,12 @@ fr:
title: Statistiques title: Statistiques
all: Événements validés all: Événements validés
allModeration: Événements en cours de modération allModeration: Événements en cours de modération
dates: Par date
regional: Par région regional: Par région
city: Par ville city: Par ville
city_conditions: Seules les villes où plus de trois événements ont été city_conditions: Seules les villes où plus de trois événements ont été
organisés sont mentionnées. organisés sont mentionnées.
dates: Par date total: Total
web: Statistiques Web web: Statistiques Web
webalizer: Des statistiques Web générées par Webalizer [sont webalizer: Des statistiques Web générées par Webalizer [sont
disponibles](http://agendadulibre.org/stats/). Elles sont protégées par disponibles](http://agendadulibre.org/stats/). Elles sont protégées par