diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/configuration.rb | 1 | ||||
-rw-r--r-- | lib/date_quarter.rb | 22 | ||||
-rw-r--r-- | lib/mail_handler/backends/mail_extensions.rb | 8 | ||||
-rw-r--r-- | lib/tasks/stats.rake | 55 |
4 files changed, 86 insertions, 0 deletions
diff --git a/lib/configuration.rb b/lib/configuration.rb index bd705b777..d525bf712 100644 --- a/lib/configuration.rb +++ b/lib/configuration.rb @@ -58,6 +58,7 @@ module AlaveteliConfiguration :RECAPTCHA_PUBLIC_KEY => 'x', :REPLY_LATE_AFTER_DAYS => 20, :REPLY_VERY_LATE_AFTER_DAYS => 40, + :RESPONSIVE_STYLING => false, :SITE_NAME => 'Alaveteli', :SKIP_ADMIN_AUTH => false, :SPECIAL_REPLY_VERY_LATE_AFTER_DAYS => 60, diff --git a/lib/date_quarter.rb b/lib/date_quarter.rb new file mode 100644 index 000000000..ac159b420 --- /dev/null +++ b/lib/date_quarter.rb @@ -0,0 +1,22 @@ +module DateQuarter + extend self + + def quarters_between(start_at, finish_at) + results = [] + + quarter_start = start_at.beginning_of_quarter + quarter_end = start_at.end_of_quarter + + while quarter_end <= finish_at.end_of_quarter do + # Collect these + results << [quarter_start, quarter_end] + + # Update dates + quarter_start = quarter_end + 1.second + quarter_end = quarter_start.end_of_quarter + end + + results + end + +end diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index 87af526bf..f778cbc14 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -1,4 +1,5 @@ require 'mail/message' +require 'mail/part' require 'mail/fields/common/parameter_hash' module Mail class Message @@ -9,6 +10,12 @@ module Mail attr_accessor :count_first_uudecode_count end + class Part < Message + def inline? + header[:content_disposition].disposition_type == 'inline' if header[:content_disposition] rescue false + end + end + # A patched version of the parameter hash that handles nil values without throwing # an error. class ParameterHash < IndifferentHash @@ -95,4 +102,5 @@ module Mail end end + end diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index 38eb15996..f09594529 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -97,6 +97,61 @@ namespace :stats do end end + desc <<-DESC +Prints the per-quarter number of created FOI Requests made to each Public Body found by the query. +Specify the search query as QUERY='london school' +DESC + task :number_of_requests_created => :environment do + query = ENV['QUERY'] + start_at = PublicBody.minimum(:created_at) + finish_at = PublicBody.maximum(:created_at) + public_bodies = PublicBody.search(query) + quarters = DateQuarter.quarters_between(start_at, finish_at) + + # Headers + headers = ['Body'] + quarters.map { |date_tuple| date_tuple.join('~') } + puts headers.join(",") + + public_bodies.each do |body| + stats = quarters.map do |quarter| + conditions = ['created_at >= ? AND created_at < ?', quarter[0], quarter[1]] + count = body.info_requests.count(:conditions => conditions) + count ? count : 0 + end + + row = [body.name] + stats + puts row.join(",") + end + end + + desc <<-DESC +Prints the per-quarter number of successful FOI Requests made to each Public Body found by the query. +Specify the search query as QUERY='london school' +DESC + task :number_of_requests_successful => :environment do + query = ENV['QUERY'] + start_at = PublicBody.minimum(:created_at) + finish_at = PublicBody.maximum(:created_at) + public_bodies = PublicBody.search(query) + quarters = DateQuarter.quarters_between(start_at, finish_at) + + # Headers + headers = ['Body'] + quarters.map { |date_tuple| date_tuple.join('~') } + puts headers.join(",") + + public_bodies.each do |body| + stats = quarters.map do |quarter| + conditions = ['created_at >= ? AND created_at < ? AND described_state = ?', + quarter[0], quarter[1], 'successful'] + count = body.info_requests.count(:conditions => conditions) + count ? count : 0 + end + + row = [body.name] + stats + puts row.join(",") + end + end + desc 'Update statistics in the public_bodies table' task :update_public_bodies_stats => :environment do verbose = ENV['VERBOSE'] == '1' |