Commit 27a151096a291d1e70bc252d067a918c79bbc697

Authored by Luke Baker
1 parent 5b567ac7

convert to rate and add documentation note

app/controllers/questions_controller.rb
... ... @@ -229,9 +229,9 @@ class QuestionsController < InheritedResources::Base
229 229 end
230 230 end
231 231  
232   - def upload_to_participation_ratio
  232 + def upload_to_participation_rate
233 233 @question = current_user.questions.find(params[:id])
234   - response = {:uploadparticipationratio => @question.upload_to_participation_ratio}
  234 + response = {:uploadparticipationrate => @question.upload_to_participation_rate}
235 235 respond_to do |format|
236 236 format.xml { render :xml => response.to_xml and return}
237 237 end
... ...
app/models/question.rb
... ... @@ -693,7 +693,7 @@ class Question < ActiveRecord::Base
693 693 "), true) || nil
694 694 end
695 695  
696   - def upload_to_participation_ratio
  696 + def upload_to_participation_rate
697 697 swp = sessions_with_participation
698 698 return nil if swp == 0
699 699 sessions_with_uploaded_ideas.to_f / swp.to_f
... ... @@ -709,6 +709,8 @@ class Question < ActiveRecord::Base
709 709  
710 710 # total sessions with at least one vote, skip, or uploaded idea
711 711 def sessions_with_participation
  712 + # only select votes that are valid because wikipedia project has new votes
  713 + # marked as invalid and we want that to be effectively closed to updating this value.
712 714 Question.connection.select_one("
713 715 SELECT COUNT(*) FROM (
714 716 (SELECT DISTINCT(skipper_id) vid FROM skips WHERE question_id = #{id})
... ...
config/routes.rb
... ... @@ -10,7 +10,7 @@ ActionController::Routing::Routes.draw do |map|
10 10 :vote_rate => :get,
11 11 :median_responses_per_session => :get,
12 12 :votes_per_uploaded_choice => :get,
13   - :upload_to_participation_ratio => :get,
  13 + :upload_to_participation_rate => :get,
14 14 :export => :post} ,
15 15 :collection => {:all_num_votes_by_visitor_id => :get,
16 16 :all_object_info_totals_by_date => :get,
... ...
spec/integration/questions_spec.rb
... ... @@ -297,13 +297,13 @@ describe "Questions" do
297 297 end
298 298 end
299 299  
300   - describe "GET 'upload_to_participation_ratio'" do
  300 + describe "GET 'upload_to_participation_rate'" do
301 301 before(:all) { truncate_all }
302   - it "should return the proper upload:participation ratio" do
  302 + it "should return the proper upload:participation rate" do
303 303 q = Factory.create(:aoi_question, :site => @api_user)
304   - get_auth upload_to_participation_ratio_question_path(q, :format => 'xml')
  304 + get_auth upload_to_participation_rate_question_path(q, :format => 'xml')
305 305 response.should be_success
306   - response.body.should have_tag("uploadparticipationratio[nil=true]", :text => "")
  306 + response.body.should have_tag("uploadparticipationrate[nil=true]", :text => "")
307 307  
308 308 # 10 voting only sessions
309 309 10.times { Factory.create(:vote_new_user, :question => q) }
... ... @@ -323,9 +323,9 @@ describe "Questions" do
323 323 # 5 users who only added ideas
324 324 5.times { Factory.create(:choice_new_user, :question => q) }
325 325  
326   - get_auth upload_to_participation_ratio_question_path(q, :format => 'xml')
  326 + get_auth upload_to_participation_rate_question_path(q, :format => 'xml')
327 327 response.should be_success
328   - response.body.should have_tag("uploadparticipationratio", :text => "0.555555555555556")
  328 + response.body.should have_tag("uploadparticipationrate", :text => "0.555555555555556")
329 329 end
330 330 end
331 331  
... ...