aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/public_body_controller.rb62
-rw-r--r--app/controllers/track_controller.rb3
2 files changed, 51 insertions, 14 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 1f7032eed..9c3e46ded 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -196,12 +196,56 @@ class PublicBodyController < ApplicationController
:disposition =>'attachment', :encoding => 'utf8')
end
+
+ # This is a helper method to take data returned by the PublicBody
+ # model's statistics-generating methods, and converting them to
+ # simpler data structure that can be rendered by a Javascript
+ # graph library. (This could be a class method except that we need
+ # access to the URL helper public_body_path.)
+ def simplify_stats_for_graphs(data,
+ column,
+ percentages,
+ graph_properties)
+ # Copy the data, only taking known-to-be-safe keys:
+ result = Hash.new { |h, k| h[k] = [] }
+ result.update Hash[data.select do |key, value|
+ ['y_values',
+ 'y_max',
+ 'totals',
+ 'cis_below',
+ 'cis_above'].include? key
+ end]
+
+ # Extract data about the public bodies for the x-axis,
+ # tooltips, and so on:
+ data['public_bodies'].each_with_index do |pb, i|
+ result['x_values'] << i
+ result['x_ticks'] << [i, pb.name]
+ result['tooltips'] << "#{pb.name} (#{result['totals'][i]})"
+ result['public_bodies'] << {
+ 'name' => pb.name,
+ 'url' => public_body_path(pb)
+ }
+ end
+
+ # Set graph metadata properties, like the title, axis labels, etc.
+ graph_id = "#{column}-"
+ graph_id += graph_properties[:highest] ? 'highest' : 'lowest'
+ result.update({
+ 'id' => graph_id,
+ 'x_axis' => _('Public Bodies'),
+ 'y_axis' => graph_properties[:y_axis],
+ 'errorbars' => percentages,
+ 'title' => graph_properties[:title]
+ })
+ end
+
def statistics
unless AlaveteliConfiguration::public_body_statistics_page
raise ActiveRecord::RecordNotFound.new("Page not enabled")
end
- per_graph = 8
+ per_graph = 10
minimum_requests = AlaveteliConfiguration::minimum_requests_for_statistics
# Make sure minimum_requests is > 0 to avoid division-by-zero
minimum_requests = [minimum_requests, 1].max
@@ -251,20 +295,12 @@ class PublicBodyController < ApplicationController
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] }
+ @graph_list.push simplify_stats_for_graphs(data,
+ column,
+ percentages,
+ graph_properties)
end
-
- @graph_list.push data_to_draw
end
end
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index 40fa69290..72c092221 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_controller.rb
@@ -181,7 +181,8 @@ class TrackController < ApplicationController
if new_medium == 'delete'
track_thing.destroy
flash[:notice] = _("You are no longer following {{track_description}}.", :track_description => track_thing.params[:list_description])
- redirect_to params[:r]
+ redirect_to URI.parse(params[:r]).path
+
# Reuse code like this if we let medium change again.
#elsif new_medium == 'email_daily'
# track_thing.track_medium = new_medium