Commit 3d6819741510d3ba7622e4e034989edbb77ae9ec

Authored by Luke Baker
1 parent 810b7114

add appearance id to votes and nonvote csv

votes file gets additional column: Record ID
nonvotes file has Record ID column removed and Appearance ID and Skip ID added
Showing 1 changed file with 7 additions and 6 deletions   Show diff stats
app/models/question.rb
@@ -574,14 +574,14 @@ class Question < ActiveRecord::Base @@ -574,14 +574,14 @@ class Question < ActiveRecord::Base
574 when 'votes' 574 when 'votes'
575 outfile = "ideamarketplace_#{self.id}_votes" 575 outfile = "ideamarketplace_#{self.id}_votes"
576 576
577 - headers = ['Vote ID', 'Session ID', 'Ideamarketplace ID','Winner ID', 'Winner Text', 'Loser ID', 'Loser Text', 'Prompt ID', 'Left Choice ID', 'Right Choice ID', 'Created at', 'Updated at', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier', 'Valid'] 577 + headers = ['Vote ID', 'Session ID', 'Ideamarketplace ID','Winner ID', 'Winner Text', 'Loser ID', 'Loser Text', 'Prompt ID', 'Appearance ID', 'Left Choice ID', 'Right Choice ID', 'Created at', 'Updated at', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier', 'Valid']
578 578
579 when 'ideas' 579 when 'ideas'
580 outfile = "ideamarketplace_#{self.id}_ideas" 580 outfile = "ideamarketplace_#{self.id}_ideas"
581 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', 'Session Identifier'] 581 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', 'Session Identifier']
582 when 'non_votes' 582 when 'non_votes'
583 outfile = "ideamarketplace_#{self.id}_non_votes" 583 outfile = "ideamarketplace_#{self.id}_non_votes"
584 - headers = ['Record Type', 'Record ID', 'Session ID', 'Ideamarketplace ID','Left Choice ID', 'Left Choice Text', 'Right Choice ID', 'Right Choice Text', 'Prompt ID', 'Reason', 'Created at', 'Updated at', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier', 'Valid'] 584 + headers = ['Record Type', 'Skip ID', 'Appearance ID', 'Session ID', 'Ideamarketplace ID','Left Choice ID', 'Left Choice Text', 'Right Choice ID', 'Right Choice Text', 'Prompt ID', 'Reason', 'Created at', 'Updated at', 'Response Time (s)', 'Missing Response Time Explanation', 'Session Identifier', 'Valid']
585 else 585 else
586 raise "Unsupported export type: #{type}" 586 raise "Unsupported export type: #{type}"
587 end 587 end
@@ -591,7 +591,7 @@ class Question < ActiveRecord::Base @@ -591,7 +591,7 @@ class Question < ActiveRecord::Base
591 case type 591 case type
592 when 'votes' 592 when 'votes'
593 593
594 - Vote.find_each_without_default_scope(:conditions => {:question_id => self}, :include => [:prompt, :choice, :loser_choice, :voter]) do |v| 594 + Vote.find_each_without_default_scope(:conditions => {:question_id => self}, :include => [:prompt, :choice, :loser_choice, :voter, :appearance]) do |v|
595 valid = v.valid_record ? "TRUE" : "FALSE" 595 valid = v.valid_record ? "TRUE" : "FALSE"
596 prompt = v.prompt 596 prompt = v.prompt
597 # these may not exist 597 # these may not exist
@@ -599,10 +599,11 @@ class Question < ActiveRecord::Base @@ -599,10 +599,11 @@ class Question < ActiveRecord::Base
599 left_id = v.prompt.nil? ? "" : v.prompt.left_choice_id 599 left_id = v.prompt.nil? ? "" : v.prompt.left_choice_id
600 right_id = v.prompt.nil? ? "" : v.prompt.right_choice_id 600 right_id = v.prompt.nil? ? "" : v.prompt.right_choice_id
601 601
  602 + appearance_id = v.appearance.id.nil? ? "NA" : v.appearance.id
602 time_viewed = v.time_viewed.nil? ? "NA": v.time_viewed.to_f / 1000.0 603 time_viewed = v.time_viewed.nil? ? "NA": v.time_viewed.to_f / 1000.0
603 604
604 csv << [ v.id, v.voter_id, v.question_id, v.choice_id, v.choice.data.strip, v.loser_choice_id, loser_data, 605 csv << [ v.id, v.voter_id, v.question_id, v.choice_id, v.choice.data.strip, v.loser_choice_id, loser_data,
605 - v.prompt_id, left_id, right_id, v.created_at, v.updated_at, 606 + v.prompt_id, appearance_id, left_id, right_id, v.created_at, v.updated_at,
606 time_viewed, v.missing_response_time_exp , v.voter.identifier, valid] 607 time_viewed, v.missing_response_time_exp , v.voter.identifier, valid]
607 end 608 end
608 609
@@ -631,7 +632,7 @@ class Question &lt; ActiveRecord::Base @@ -631,7 +632,7 @@ class Question &lt; ActiveRecord::Base
631 valid = s.valid_record ? 'TRUE' : 'FALSE' 632 valid = s.valid_record ? 'TRUE' : 'FALSE'
632 time_viewed = s.time_viewed.nil? ? "NA": s.time_viewed.to_f / 1000.0 633 time_viewed = s.time_viewed.nil? ? "NA": s.time_viewed.to_f / 1000.0
633 prompt = s.prompt 634 prompt = s.prompt
634 - 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.skip_reason, s.created_at, s.updated_at, time_viewed , s.missing_response_time_exp, s.skipper.identifier,valid] 635 + csv << [ "Skip", s.id, s.skipper_id, a.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.skip_reason, s.created_at, s.updated_at, time_viewed , s.missing_response_time_exp, s.skipper.identifier,valid]
635 636
636 else 637 else
637 # If no skip and no vote, this is an orphaned appearance 638 # If no skip and no vote, this is an orphaned appearance
@@ -640,7 +641,7 @@ class Question &lt; ActiveRecord::Base @@ -640,7 +641,7 @@ class Question &lt; ActiveRecord::Base
640 ["voter_id = ? AND question_id = ? AND answerable_type IS NOT ?", 641 ["voter_id = ? AND question_id = ? AND answerable_type IS NOT ?",
641 a.voter_id, a.question_id, nil]) 642 a.voter_id, a.question_id, nil])
642 appearance_type = (action_appearances > 0) ? 'Stopped_Voting_Or_Skipping' : 'Bounce' 643 appearance_type = (action_appearances > 0) ? 'Stopped_Voting_Or_Skipping' : 'Bounce'
643 - csv << [ appearance_type, 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, 'NA', a.created_at, a.updated_at, 'NA', '', a.voter.identifier, 'TRUE'] 644 + csv << [ appearance_type, 'NA', 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, 'NA', a.created_at, a.updated_at, 'NA', '', a.voter.identifier, 'TRUE']
644 end 645 end
645 end 646 end
646 end 647 end