From 72aa3e48bc1e933513608cae585c28b2c7a0d341 Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Thu, 12 Dec 2013 20:26:58 +0000 Subject: [PATCH] Basic stats page Thought this might be useful. --- app/assets/stylesheets/v1.css.erb | 22 +++++++++++++++ app/controllers/stats_controller.rb | 34 +++++++++++++++++++++++ app/views/stats/show.html.erb | 42 +++++++++++++++++++++++++++++ config/routes.rb | 2 ++ 4 files changed, 100 insertions(+) create mode 100644 app/controllers/stats_controller.rb create mode 100644 app/views/stats/show.html.erb diff --git a/app/assets/stylesheets/v1.css.erb b/app/assets/stylesheets/v1.css.erb index 93f89d4..13a72ee 100644 --- a/app/assets/stylesheets/v1.css.erb +++ b/app/assets/stylesheets/v1.css.erb @@ -1460,6 +1460,28 @@ table.plaque_list td.geo {} margin-bottom: 8px; } +.stats { + max-width: 400px; + margin: 0 auto; +} + +.stats .figure { + display: inline-block; + font-size: 50px; + font-weight: bold; + vertical-align: middle; + padding-right: 10px; + width: 200px; + text-align: right; +} + +.stats .description { + font-size: 20px; + font-weight: bold; + vertical-align: middle; + +} + /*********/ .alternate_formats {font-size: .8em; text-align: center; color: #888; margin-top: 2em; margin-bottom: 1em;} diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb new file mode 100644 index 0000000..d6ec1fa --- /dev/null +++ b/app/controllers/stats_controller.rb @@ -0,0 +1,34 @@ +class StatsController < ApplicationController + + def show + + @plaques_count = Plaque.count + @people_count = Person.count + @countries_count = Area.count('country_id', :distinct => true) + @places_count = Area.count + @languages_count = Plaque.count('language_id', :distinct => true) + @organisations_count = Organisation.count + @photos_count = Photo.count + @users_count = User.count + + respond_to do |format| + format.html + format.json { + render :json => { + 'stats' => { + 'plaques_count' => @plaques_count, + 'people_count' => @people_count, + 'countries_count' => @countries_count, + 'places_count' => @places_count, + 'languages_count' => @languages_count, + 'organisations_count' => @organisations_count, + 'photos_count' => @photos_count, + 'users_count' => @users_count + } + } + } + end + + end + +end diff --git a/app/views/stats/show.html.erb b/app/views/stats/show.html.erb new file mode 100644 index 0000000..82312ce --- /dev/null +++ b/app/views/stats/show.html.erb @@ -0,0 +1,42 @@ +
+
+

Open Plaques stats

+
+ +
+
+ <%= @plaques_count %> + Total plaques +
+
+ <%= @people_count %> + People mentioned +
+
+ <%= @organisations_count %> + Organisations +
+
+ <%= @countries_count %> + Countries +
+
+ <%= @places_count %> + Cities and towns +
+
+ <%= @photos_count %> + Photos +
+
+ <%= @users_count %> + Contributors +
+
+ <%= @languages_count %> + Languages +
+ +
+ +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1de04e6..cf2f05d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -108,6 +108,8 @@ resource :contribute, :controller => :pages, :id => "contribute", :as => "contribute", :only => :show resource :explore, :controller => :explore, :only => :show + resource :stats, :controller => :stats, :only => :show + # Generic resource for all pages resources :pages