Skip to content

Commit

Permalink
Merge branch 'release/0.22.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Aug 13, 2015
2 parents 67a00ba + 322a368 commit cb404da
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 19 deletions.
22 changes: 16 additions & 6 deletions app/controllers/general_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,22 @@ def not_found

def version
respond_to do |format|
format.json { render :json => {
:alaveteli_git_commit => alaveteli_git_commit,
:alaveteli_version => ALAVETELI_VERSION,
:ruby_version => RUBY_VERSION,
:visible_request_count => InfoRequest.visible.count,
:confirmed_user_count => User.where(:email_confirmed => true).count
format.json {
render :json => {
:alaveteli_git_commit => alaveteli_git_commit,
:alaveteli_version => ALAVETELI_VERSION,
:ruby_version => RUBY_VERSION,
:visible_public_body_count => PublicBody.visible.count,
:visible_request_count => InfoRequest.visible.count,
:confirmed_user_count => User.where(:email_confirmed => true).count,
:visible_comment_count => Comment.visible.count,
:track_thing_count => TrackThing.count,
:widget_vote_count => WidgetVote.count,
:public_body_change_request_count => PublicBodyChangeRequest.count,
:request_classification_count => RequestClassification.count,
:visible_followup_message_count =>
OutgoingMessage.where(:prominence => 'normal',
:message_type => 'followup').count
}}
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/info_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class InfoRequestEvent < ActiveRecord::Base
belongs_to :incoming_message
belongs_to :comment

has_one :request_classification

has_many :user_info_request_sent_alerts
has_many :track_things_sent_emails

Expand Down
1 change: 1 addition & 0 deletions app/models/request_classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class RequestClassification < ActiveRecord::Base
belongs_to :user
belongs_to :info_request_event

# return classification instances representing the top n
# users, with a 'cnt' attribute representing the number
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/alaveteli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
load "util.rb"

# Application version
ALAVETELI_VERSION = '0.22.2.0'
ALAVETELI_VERSION = '0.22.3.0'

# Add new inflection rules using the following format
# (all these examples are active by default):
Expand Down
11 changes: 11 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# develop

## Highlighted Features

# Version 0.22.3.0

* Added additional transaction stats to /version.json endpoint (Gareth Rees).
* Added additional transaction stats to stats:show rake task (Gareth Rees).

## Upgrade Notes

* There should be no action necessary.

# Version 0.22.2.0

## Highlighted Features
Expand Down
70 changes: 58 additions & 12 deletions lib/tasks/stats.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,92 @@ namespace :stats do
start_month = (ENV['START_MONTH'] || 1).to_i
end_year = (ENV['END_YEAR'] || Time.now.year).to_i
end_month = (ENV['END_MONTH'] || Time.now.month).to_i

month_starts = (Date.new(start_year, start_month)..Date.new(end_year, end_month)).select { |d| d.day == 1 }

headers = ['Period',
'Requests sent',
'Annotations added',
'Visible comments',
'Track this request email signups',
'Comments on own requests',
'Follow up messages sent']
'Follow up messages sent',
'Confirmed users',
'Request classifications',
'Public body change requests',
'Widget votes',
'Total tracks']
puts headers.join("\t")

month_starts.each do |month_start|
month_end = month_start.end_of_month
period = "#{month_start}-#{month_end}"

date_conditions = ['created_at >= ?
AND created_at < ?',
month_start, month_end+1]
request_count = InfoRequest.count(:conditions => date_conditions)
comment_count = Comment.count(:conditions => date_conditions)

request_count = InfoRequest.where(date_conditions).count
visible_comments_count = Comment.visible.where(date_conditions).count

track_conditions = ['track_type = ?
AND track_medium = ?
AND created_at >= ?
AND created_at < ?',
'request_updates', 'email_daily', month_start, month_end+1]
email_request_track_count = TrackThing.count(:conditions => track_conditions)
'request_updates',
'email_daily',
month_start,
month_end + 1]
email_request_track_count = TrackThing.where(track_conditions).count

comment_on_own_request_conditions = ['comments.user_id = info_requests.user_id
AND comments.created_at >= ?
AND comments.created_at < ?',
month_start, month_end+1]
comment_on_own_request_count = Comment.count(:conditions => comment_on_own_request_conditions,
:include => :info_request)

comment_on_own_request_count =
Comment.
includes(:info_request).
where(comment_on_own_request_conditions).
count

followup_conditions = ['message_type = ?
AND prominence = ?
AND created_at >= ?
AND created_at < ?',
'followup', month_start, month_end+1]
follow_up_count = OutgoingMessage.count(:conditions => followup_conditions)
'followup',
'normal',
month_start,
month_end + 1]
follow_up_count = OutgoingMessage.where(followup_conditions).count

confirmed_users_count =
User.
where(:email_confirmed => true).
where(date_conditions).
count

request_classifications_count =
RequestClassification.where(date_conditions).count

public_body_change_requests_count =
PublicBodyChangeRequest.where(date_conditions).count

widget_votes_count = WidgetVote.where(date_conditions).count

total_tracks_count = TrackThing.where(date_conditions).count


puts [period,
request_count,
comment_count,
visible_comments_count,
email_request_track_count,
comment_on_own_request_count,
follow_up_count].join("\t")
follow_up_count,
confirmed_users_count,
request_classifications_count,
public_body_change_requests_count,
widget_votes_count,
total_tracks_count].join("\t")
end
end

Expand Down
74 changes: 74 additions & 0 deletions spec/controllers/general_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,80 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fakeweb'

describe GeneralController do

describe 'GET version' do

it 'renders json stats about the install' do
# Clean up fixtures
InfoRequest.find_each(&:fully_destroy)
Comment.find_each(&:fully_destroy)
PublicBody.find_each(&:destroy)
TrackThing.find_each(&:destroy)
User.find_each(&:destroy)

# Create some constant God models for other factories
user = FactoryGirl.create(:user)
body = FactoryGirl.create(:public_body)
info_request = FactoryGirl.create(:info_request,
:user => user, :public_body => body)
default_args = { :info_request => info_request,
:public_body => body,
:user => user }

# Create the other data we're checking
FactoryGirl.create(:info_request, :user => user,
:public_body => body,
:prominence => 'hidden')
FactoryGirl.create(:user, :email_confirmed => false)
FactoryGirl.create(:visible_comment,
default_args.dup.slice!(:public_body))
FactoryGirl.create(:hidden_comment,
default_args.dup.slice!(:public_body))
FactoryGirl.create(:search_track, :tracking_user => user)
FactoryGirl.create(:widget_vote,
default_args.dup.slice!(:user, :public_body))
FactoryGirl.create(:internal_review_request,
default_args.dup.slice!(:user, :public_body))
FactoryGirl.create(:internal_review_request,
:info_request => info_request, :prominence => 'hidden')
FactoryGirl.create(:add_body_request,
default_args.dup.slice!(:info_request))
event = FactoryGirl.create(:info_request_event,
default_args.dup.slice!(:user, :public_body))
FactoryGirl.create(:request_classification, :user => user,
:info_request_event => event)

mock_git_commit = Digest::SHA1.hexdigest(Time.now.to_s)

ApplicationController.
any_instance.
stub(:alaveteli_git_commit).
and_return(mock_git_commit)

expected = { :alaveteli_git_commit => mock_git_commit,
:alaveteli_version => ALAVETELI_VERSION,
:ruby_version => RUBY_VERSION,
:visible_public_body_count => 1,
:visible_request_count => 1,
:confirmed_user_count => 1,
:visible_comment_count => 1,
:track_thing_count => 1,
:widget_vote_count => 1,
:public_body_change_request_count => 1,
:request_classification_count => 1,
:visible_followup_message_count => 1 }

get :version, :format => :json

parsed_body = JSON.parse(response.body).symbolize_keys
expect(parsed_body).to eq(expected)
end

end

end

describe GeneralController, "when trying to show the blog" do
before (:each) do
FakeWeb.clean_registry
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/request_classifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- encoding : utf-8 -*-
FactoryGirl.define do

factory :request_classification do
user
info_request_event
end

end

0 comments on commit cb404da

Please sign in to comment.