From 27a151096a291d1e70bc252d067a918c79bbc697 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Mon, 2 Apr 2012 15:35:29 -0400 Subject: [PATCH] convert to rate and add documentation note --- app/controllers/questions_controller.rb | 4 ++-- app/models/question.rb | 4 +++- config/routes.rb | 2 +- spec/integration/questions_spec.rb | 12 ++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index d2ee388..2ad3caf 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -229,9 +229,9 @@ class QuestionsController < InheritedResources::Base end end - def upload_to_participation_ratio + def upload_to_participation_rate @question = current_user.questions.find(params[:id]) - response = {:uploadparticipationratio => @question.upload_to_participation_ratio} + response = {:uploadparticipationrate => @question.upload_to_participation_rate} respond_to do |format| format.xml { render :xml => response.to_xml and return} end diff --git a/app/models/question.rb b/app/models/question.rb index 9406624..08141c4 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -693,7 +693,7 @@ class Question < ActiveRecord::Base "), true) || nil end - def upload_to_participation_ratio + def upload_to_participation_rate swp = sessions_with_participation return nil if swp == 0 sessions_with_uploaded_ideas.to_f / swp.to_f @@ -709,6 +709,8 @@ class Question < ActiveRecord::Base # total sessions with at least one vote, skip, or uploaded idea def sessions_with_participation + # only select votes that are valid because wikipedia project has new votes + # marked as invalid and we want that to be effectively closed to updating this value. Question.connection.select_one(" SELECT COUNT(*) FROM ( (SELECT DISTINCT(skipper_id) vid FROM skips WHERE question_id = #{id}) diff --git a/config/routes.rb b/config/routes.rb index fde3e18..0bb7bd7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ ActionController::Routing::Routes.draw do |map| :vote_rate => :get, :median_responses_per_session => :get, :votes_per_uploaded_choice => :get, - :upload_to_participation_ratio => :get, + :upload_to_participation_rate => :get, :export => :post} , :collection => {:all_num_votes_by_visitor_id => :get, :all_object_info_totals_by_date => :get, diff --git a/spec/integration/questions_spec.rb b/spec/integration/questions_spec.rb index 17a00c1..e710261 100644 --- a/spec/integration/questions_spec.rb +++ b/spec/integration/questions_spec.rb @@ -297,13 +297,13 @@ describe "Questions" do end end - describe "GET 'upload_to_participation_ratio'" do + describe "GET 'upload_to_participation_rate'" do before(:all) { truncate_all } - it "should return the proper upload:participation ratio" do + it "should return the proper upload:participation rate" do q = Factory.create(:aoi_question, :site => @api_user) - get_auth upload_to_participation_ratio_question_path(q, :format => 'xml') + get_auth upload_to_participation_rate_question_path(q, :format => 'xml') response.should be_success - response.body.should have_tag("uploadparticipationratio[nil=true]", :text => "") + response.body.should have_tag("uploadparticipationrate[nil=true]", :text => "") # 10 voting only sessions 10.times { Factory.create(:vote_new_user, :question => q) } @@ -323,9 +323,9 @@ describe "Questions" do # 5 users who only added ideas 5.times { Factory.create(:choice_new_user, :question => q) } - get_auth upload_to_participation_ratio_question_path(q, :format => 'xml') + get_auth upload_to_participation_rate_question_path(q, :format => 'xml') response.should be_success - response.body.should have_tag("uploadparticipationratio", :text => "0.555555555555556") + response.body.should have_tag("uploadparticipationrate", :text => "0.555555555555556") end end -- libgit2 0.21.2