Commit 1bf68a013766fd06c4e671b25994fd08f8b54763

Authored by Luke Baker
1 parent bc10fdca

add valid field to CSV output of votes and non-votes

Showing 2 changed files with 14 additions and 6 deletions   Show diff stats
app/models/question.rb
@@ -510,14 +510,14 @@ class Question < ActiveRecord::Base @@ -510,14 +510,14 @@ class Question < ActiveRecord::Base
510 when 'votes' 510 when 'votes'
511 outfile = "ideamarketplace_#{self.id}_votes.csv" 511 outfile = "ideamarketplace_#{self.id}_votes.csv"
512 512
513 - headers = ['Vote ID', 'Session ID', 'Question ID','Winner ID', 'Winner Text', 'Loser ID', 'Loser Text', 'Prompt ID', 'Left Choice ID', 'Right Choice ID', 'Created at', 'Updated at', 'Appearance ID', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier'] 513 + headers = ['Vote ID', 'Session ID', 'Question ID','Winner ID', 'Winner Text', 'Loser ID', 'Loser Text', 'Prompt ID', 'Left Choice ID', 'Right Choice ID', 'Created at', 'Updated at', 'Appearance ID', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier', 'Valid']
514 514
515 when 'ideas' 515 when 'ideas'
516 outfile = "ideamarketplace_#{self.id}_ideas.csv" 516 outfile = "ideamarketplace_#{self.id}_ideas.csv"
517 headers = ['Ideamarketplace ID','Idea ID', 'Idea Text', 'Wins', 'Losses', 'Times involved in Cant Decide', 'Score', 'User Submitted', 'Session ID', 'Created at', 'Last Activity', 'Active', 'Appearances on Left', 'Appearances on Right'] 517 headers = ['Ideamarketplace ID','Idea ID', 'Idea Text', 'Wins', 'Losses', 'Times involved in Cant Decide', 'Score', 'User Submitted', 'Session ID', 'Created at', 'Last Activity', 'Active', 'Appearances on Left', 'Appearances on Right']
518 when 'non_votes' 518 when 'non_votes'
519 outfile = "ideamarketplace_#{self.id}_non_votes.csv" 519 outfile = "ideamarketplace_#{self.id}_non_votes.csv"
520 - headers = ['Record Type', 'Record ID', 'Session ID', 'Question ID','Left Choice ID', 'Left Choice Text', 'Right Choice ID', 'Right Choice Text', 'Prompt ID', 'Appearance ID', 'Reason', 'Created at', 'Updated at', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier'] 520 + headers = ['Record Type', 'Record ID', 'Session ID', 'Question ID','Left Choice ID', 'Left Choice Text', 'Right Choice ID', 'Right Choice Text', 'Prompt ID', 'Appearance ID', 'Reason', 'Created at', 'Updated at', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier', 'Valid']
521 else 521 else
522 raise "Unsupported export type: #{type}" 522 raise "Unsupported export type: #{type}"
523 end 523 end
@@ -530,7 +530,8 @@ class Question < ActiveRecord::Base @@ -530,7 +530,8 @@ class Question < ActiveRecord::Base
530 case type 530 case type
531 when 'votes' 531 when 'votes'
532 532
533 - self.votes.find_each(:include => [:prompt, :choice, :loser_choice, :voter]) do |v| 533 + Vote.find_each_without_default_scope(:conditions => {:question_id => self}, :include => [:prompt, :choice, :loser_choice, :voter]) do |v|
  534 + valid = v.valid_record ? "TRUE" : "FALSE"
534 prompt = v.prompt 535 prompt = v.prompt
535 # these may not exist 536 # these may not exist
536 loser_data = v.loser_choice.nil? ? "" : v.loser_choice.data.strip 537 loser_data = v.loser_choice.nil? ? "" : v.loser_choice.data.strip
@@ -541,7 +542,7 @@ class Question < ActiveRecord::Base @@ -541,7 +542,7 @@ class Question < ActiveRecord::Base
541 542
542 csv << [ v.id, v.voter_id, v.question_id, v.choice_id, v.choice.data.strip, v.loser_choice_id, loser_data, 543 csv << [ v.id, v.voter_id, v.question_id, v.choice_id, v.choice.data.strip, v.loser_choice_id, loser_data,
543 v.prompt_id, left_id, right_id, v.created_at, v.updated_at, v.appearance_id, 544 v.prompt_id, left_id, right_id, v.created_at, v.updated_at, v.appearance_id,
544 - time_viewed, v.missing_response_time_exp , v.voter.identifier] 545 + time_viewed, v.missing_response_time_exp , v.voter.identifier, valid]
545 end 546 end
546 547
547 when 'ideas' 548 when 'ideas'
@@ -568,14 +569,15 @@ class Question &lt; ActiveRecord::Base @@ -568,14 +569,15 @@ class Question &lt; ActiveRecord::Base
568 if a.answerable.class == Skip 569 if a.answerable.class == Skip
569 # If this appearance belongs to a skip, show information on the skip instead 570 # If this appearance belongs to a skip, show information on the skip instead
570 s = a.answerable 571 s = a.answerable
  572 + valid = s.valid_record ? 'TRUE' : 'FALSE'
571 time_viewed = s.time_viewed.nil? ? "NA": s.time_viewed.to_f / 1000.0 573 time_viewed = s.time_viewed.nil? ? "NA": s.time_viewed.to_f / 1000.0
572 prompt = s.prompt 574 prompt = s.prompt
573 - csv << [ "Skip", s.id, s.skipper_id, s.question_id, s.prompt.left_choice.id, s.prompt.left_choice.data.strip, s.prompt.right_choice.id, s.prompt.right_choice.data.strip, s.prompt_id, s.appearance_id, s.skip_reason, s.created_at, s.updated_at, time_viewed , s.missing_response_time_exp, s.skipper.identifier] 575 + csv << [ "Skip", s.id, s.skipper_id, s.question_id, s.prompt.left_choice.id, s.prompt.left_choice.data.strip, s.prompt.right_choice.id, s.prompt.right_choice.data.strip, s.prompt_id, s.appearance_id, s.skip_reason, s.created_at, s.updated_at, time_viewed , s.missing_response_time_exp, s.skipper.identifier,valid]
574 576
575 else 577 else
576 # If no skip and no vote, this is an orphaned appearance 578 # If no skip and no vote, this is an orphaned appearance
577 prompt = a.prompt 579 prompt = a.prompt
578 - csv << [ "Orphaned Appearance", a.id, a.voter_id, a.question_id, a.prompt.left_choice.id, a.prompt.left_choice.data.strip, a.prompt.right_choice.id, a.prompt.right_choice.data.strip, a.prompt_id, 'N/A', 'N/A', a.created_at, a.updated_at, 'N/A', '', a.voter.identifier] 580 + csv << [ "Orphaned Appearance", a.id, a.voter_id, a.question_id, a.prompt.left_choice.id, a.prompt.left_choice.data.strip, a.prompt.right_choice.id, a.prompt.right_choice.data.strip, a.prompt_id, 'N/A', 'N/A', a.created_at, a.updated_at, 'N/A', '', a.voter.identifier, 'N/A']
579 end 581 end
580 end 582 end
581 end 583 end
app/models/vote.rb
@@ -31,6 +31,12 @@ class Vote &lt; ActiveRecord::Base @@ -31,6 +31,12 @@ class Vote &lt; ActiveRecord::Base
31 end 31 end
32 end 32 end
33 33
  34 + def self.find_each_without_default_scope(*args, &block)
  35 + with_exclusive_scope() do
  36 + find_each(*args, &block)
  37 + end
  38 + end
  39 +
34 def update_winner_choice 40 def update_winner_choice
35 choice.reload # make sure we're using updated counter values 41 choice.reload # make sure we're using updated counter values
36 choice.compute_score! 42 choice.compute_score!