diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/admin_general_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 11 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 80 |
4 files changed, 84 insertions, 14 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 0bccd3358..f5191504e 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -17,7 +17,7 @@ class AdminController < ApplicationController end # Always give full stack trace for admin interface - def local_request? + def show_rails_exceptions? true end diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb index ec5f95eda..196616ed6 100644 --- a/app/controllers/admin_general_controller.rb +++ b/app/controllers/admin_general_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminGeneralController < AdminController - skip_before_filter :authenticate, :only => :admin_js def index # ensure we have a trailing slash @@ -142,9 +141,5 @@ class AdminGeneralController < AdminController @request_env = request.env end - # TODO: Remove this when support for proxy admin interface is removed - def admin_js - render :layout => false, :content_type => "application/javascript" - end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 88b107861..2ce44011f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -119,12 +119,9 @@ class ApplicationController < ActionController::Base end def render_exception(exception) - - # In development, or the admin interface, or for a local request, let Rails handle the exception - # with its stack trace templates. Local requests in testing are a special case so that we can - # test this method - there we use consider_all_requests_local to control behaviour. - if Rails.application.config.consider_all_requests_local || local_request? || - (request.local? && !Rails.env.test?) + # In development or the admin interface let Rails handle the exception + # with its stack trace templates + if Rails.application.config.consider_all_requests_local || show_rails_exceptions? raise exception end @@ -150,7 +147,7 @@ class ApplicationController < ActionController::Base end end - def local_request? + def show_rails_exceptions? false end diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 374866eda..9f692c5ba 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -6,6 +6,7 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ require 'fastercsv' +require 'confidence_intervals' class PublicBodyController < ApplicationController # XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL @@ -149,6 +150,84 @@ class PublicBodyController < ApplicationController :disposition =>'attachment', :encoding => 'utf8') end + def statistics + unless AlaveteliConfiguration::public_body_statistics_page + raise ActiveRecord::RecordNotFound.new("Page not enabled") + end + + per_graph = 8 + minimum_requests = AlaveteliConfiguration::minimum_requests_for_statistics + # Make sure minimum_requests is > 0 to avoid division-by-zero + minimum_requests = [minimum_requests, 1].max + total_column = 'info_requests_count' + + @graph_list = [] + + [[total_column, + [{ + :title => 'Public bodies with the most requests', + :y_axis => 'Number of requests', + :highest => true}]], + ['info_requests_successful_count', + [{ + :title => 'Public bodies with the most successful requests', + :y_axis => 'Percentage of total requests', + :highest => true}, + { + :title => 'Public bodies with the fewest successful requests', + :y_axis => 'Percentage of total requests', + :highest => false}]], + ['info_requests_overdue_count', + [{ + :title => 'Public bodies with most overdue requests', + :y_axis => 'Percentage of requests that are overdue', + :highest => true}]], + ['info_requests_not_held_count', + [{ + :title => 'Public bodies that most frequently replied with "Not Held"', + :y_axis => 'Percentage of total requests', + :highest => true}]]].each do |column, graphs_properties| + + graphs_properties.each do |graph_properties| + + percentages = (column != total_column) + highest = graph_properties[:highest] + + data = nil + if percentages + data = PublicBody.get_request_percentages(column, + per_graph, + highest, + minimum_requests) + else + data = PublicBody.get_request_totals(per_graph, + highest, + minimum_requests) + end + + data_to_draw = { + 'id' => "#{column}-#{highest ? 'highest' : 'lowest'}", + 'x_axis' => 'Public Bodies', + 'y_axis' => graph_properties[:y_axis], + 'errorbars' => percentages, + 'title' => graph_properties[:title]} + + if data + data_to_draw.update(data) + data_to_draw['x_values'] = data['public_bodies'].each_with_index.map { |pb, i| i } + data_to_draw['x_ticks'] = data['public_bodies'].each_with_index.map { |pb, i| [i, pb.name] } + end + + @graph_list.push data_to_draw + end + end + + respond_to do |format| + format.html { render :template => "public_body/statistics" } + format.json { render :json => @graph_list } + end + end + # Type ahead search def search_typeahead # Since acts_as_xapian doesn't support the Partial match flag, we work around it @@ -158,4 +237,3 @@ class PublicBodyController < ApplicationController render :partial => "public_body/search_ahead" end end - |