Skip to content

Commit

Permalink
Merge 20d5fe3 into 3e8be2c
Browse files Browse the repository at this point in the history
  • Loading branch information
henare committed Oct 17, 2016
2 parents 3e8be2c + 20d5fe3 commit 8e60804
Show file tree
Hide file tree
Showing 18 changed files with 584 additions and 274 deletions.
24 changes: 0 additions & 24 deletions app/assets/stylesheets/responsive/_public_body_stats_layout.scss

This file was deleted.

82 changes: 82 additions & 0 deletions app/assets/stylesheets/responsive/_statistics_layout.scss
@@ -0,0 +1,82 @@
/* Layout for statistics page */
.public-body-ranking {
margin-bottom: 40px;
}

.public-body-ranking-title {
margin-top: 25px;
margin-bottom: 10px;
}

.public-body-ranking table {
margin-top: 20px;
margin-left: 30px;
}

.public-body-ranking td, th {
border: 0px;
padding: 5px;
padding-right: 20px;
}

.public-body-ranking td.statistic {
text-align: center;
}

.leaderboard-block {
margin: 0 0 4em;
@include respond-min( 35em ) {
display: flex;
justify-content: space-between;
}
}

.leaderboard-item {
@include respond-min( 35em ) {
width: 45%;
}
}

.leaderboard-people {
padding: 0;
}

.leaderboard-person {
margin: 0 0 1em;
display: flex;
justify-content: space-between;
align-items: flex-start;

img,
.leaderboard-person-initial {
margin: 0 1rem 0 0;
width: 3rem;
height: 3rem;
}

.u-name {
font-size: 1.125em;
margin: 0 0 .5em;
}
}

.leaderboard-person-initial {
padding: .6rem;
font-size: 1.5em;
}

a.leaderboard-person-details {
display: flex;
justify-content: flex-start;
align-items: flex-start;

p {
margin: 0;
}
}

.leaderboard-count {
margin: 0;
font-size: 1.125em;
padding: 0 0 1em 1em;
}
@@ -1,4 +1,4 @@
/* Style for public body stats page */
/* Style for statistics page */
.public-body-ranking .axisLabels {
/* Justification for using !important here: the axis label color is
set in the style attribute in Flot's Javascript to the same
Expand All @@ -9,3 +9,12 @@
the axes black rather than transparent grey for the moment: */
color: #000 !important;
}

.leaderboard-people {
list-style: none;
}

.leaderboard-person-initial {
text-align: center;
background: lighten(desaturate(#2688dc, 50), 40);
}
4 changes: 2 additions & 2 deletions app/assets/stylesheets/responsive/all.scss
Expand Up @@ -62,8 +62,8 @@
@import "_public_body_layout";
@import "_public_body_style";

@import "_public_body_stats_layout";
@import "_public_body_stats_style";
@import "_statistics_layout";
@import "_statistics_style";

@import "_sidebar_layout";
@import "_sidebar_style";
Expand Down
115 changes: 0 additions & 115 deletions app/controllers/public_body_controller.rb
Expand Up @@ -5,7 +5,6 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/

require 'confidence_intervals'
require 'tempfile'

class PublicBodyController < ApplicationController
Expand Down Expand Up @@ -298,120 +297,6 @@ def list_all_csv
: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 = 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
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

if data
@graph_list.push simplify_stats_for_graphs(data,
column,
percentages,
graph_properties)
end
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
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/statistics_controller.rb
@@ -0,0 +1,20 @@
class StatisticsController < ApplicationController
def index
unless AlaveteliConfiguration::public_body_statistics_page
raise ActiveRecord::RecordNotFound.new("Page not enabled")
end

@public_bodies = Statistics.public_bodies
@users = Statistics.users

respond_to do |format|
format.html
format.json do
render json: {
public_bodies: @public_bodies,
users: Statistics.user_json_for_api(@users)
}
end
end
end
end
1 change: 1 addition & 0 deletions app/models/public_body.rb
Expand Up @@ -30,6 +30,7 @@
require 'csv'
require 'securerandom'
require 'set'
require 'confidence_intervals'

class PublicBody < ActiveRecord::Base
include AdminColumn
Expand Down

0 comments on commit 8e60804

Please sign in to comment.