Commit 0aa75809a7280e8b64f82f0e39f5b48b54880ff6

Authored by Pius Uzamere
1 parent c61d3c6b

adding api level voting to clickstream

app/controllers/prompts_controller.rb
... ... @@ -49,8 +49,11 @@ class PromptsController < InheritedResources::Base
49 49 authenticate
50 50  
51 51 logger.info "#{current_user.inspect} is voting #{direction} at #{Time.now}."
  52 + p = params[:click].except(:sid).merge(:visitor_id => current_user.visitors.find_or_create_by_identifier(params[:click][:sid]).id)
  53 +
52 54 @question = Question.find(params[:question_id])
53 55 @prompt = @question.prompts.find(params[:id])
  56 +
54 57 case direction
55 58 when :left
56 59 successful = c = current_user.record_vote(params['params']['auto'], @prompt, 0)
... ...
app/models/user.rb
... ... @@ -30,6 +30,8 @@ class User < ActiveRecord::Base
30 30 end
31 31  
32 32 def record_vote(visitor_identifier, prompt, ordinality)
  33 + @click = Click.new(:what_was_clicked => 'on the API level, inside record_vote' + " with prompt id #{prompt.id}, ordinality #{ordinality.to_s}")
  34 + @click.save!
33 35 visitor = visitors.find_or_create_by_identifier(visitor_identifier)
34 36 visitor.vote_for!(prompt, ordinality)
35 37 #prompt.choices.each {|c| c.compute_score; c.save!}
... ...
app/models/visitor.rb
... ... @@ -21,10 +21,12 @@ class Visitor < ActiveRecord::Base
21 21 choices = prompt.choices
22 22 choice = choices[ordinality] #we need to guarantee that the choices are in the right order (by position)
23 23 prompt_vote = votes.create!(:voteable => prompt)
24   - logger.info "Visitor: #{self.inspect} voted for Prompt: #{prompt.inspect}"
  24 + logger.info "Visitor: voted for Prompt: #{prompt.id.to_s}"
  25 + @click = Click.new(:what_was_clicked => "on the API level, inside visitor#vote_for! with prompt id #{prompt.id}, ordinality #{ordinality.to_s}, choice: #{choice.item.data} (id: #{choice.id})")
  26 + @click.save!
25 27  
26 28 choice_vote = votes.create!(:voteable => choice)
27   - logger.info "Visitor: #{self.inspect} voted for Choice: #{choice.inspect}"
  29 + logger.info "Visitor: voted for Prompt: #{prompt.id.to_s} for choice #{choice.item.data}"
28 30 choice.save!
29 31 choice.score = choice.compute_score
30 32 logger.info "Just computed the score for that choice and it's apparently #{choice.score}"
... ...