Commit 4832eb568aa692d4f66b59494b04f07ec5851e62
1 parent
74081666
Exists in
master
and in
1 other branch
Improvements to density generation code
Showing
2 changed files
with
19 additions
and
5 deletions
Show diff stats
db/migrate/20100517230848_add_question_index_to_appearances_table.rb
0 → 100644
lib/tasks/test_api.rake
@@ -46,15 +46,20 @@ namespace :test_api do | @@ -46,15 +46,20 @@ namespace :test_api do | ||
46 | 46 | ||
47 | start_date = Vote.find(:all, :conditions => 'loser_choice_id IS NOT NULL', :order => :created_at, :limit => 1).first.created_at.to_date | 47 | start_date = Vote.find(:all, :conditions => 'loser_choice_id IS NOT NULL', :order => :created_at, :limit => 1).first.created_at.to_date |
48 | start_date.upto(Date.today) do |the_date| | 48 | start_date.upto(Date.today) do |the_date| |
49 | - questions = Question.find(:all) | 49 | + questions = Question.find(:all, :conditions => ['created_at < ?', the_date]) |
50 | 50 | ||
51 | print the_date.to_s | 51 | print the_date.to_s |
52 | questions.each do |q| | 52 | questions.each do |q| |
53 | - relevant_votes = q.votes.find(:all, :conditions => ['loser_choice_id IS NOT NULL AND created_at < ?', the_date]) | 53 | + puts q.id |
54 | relevant_choices = q.choices.find(:all, :conditions => ['created_at < ?', the_date]) | 54 | relevant_choices = q.choices.find(:all, :conditions => ['created_at < ?', the_date]) |
55 | 55 | ||
56 | seed_choices = 0 | 56 | seed_choices = 0 |
57 | 57 | ||
58 | + if relevant_choices == 0 | ||
59 | + next | ||
60 | + #this question had not been created yet | ||
61 | + end | ||
62 | + | ||
58 | relevant_choices.each do |c| | 63 | relevant_choices.each do |c| |
59 | if !c.user_created | 64 | if !c.user_created |
60 | seed_choices+=1 | 65 | seed_choices+=1 |
@@ -74,9 +79,9 @@ namespace :test_api do | @@ -74,9 +79,9 @@ namespace :test_api do | ||
74 | nonseed_seed_sum= 0 | 79 | nonseed_seed_sum= 0 |
75 | nonseed_nonseed_sum= 0 | 80 | nonseed_nonseed_sum= 0 |
76 | 81 | ||
77 | - relevant_votes.each do |v| | 82 | + q.appearances.find_each(:conditions => ['prompt_id IS NOT NULL AND created_at < ?', the_date]) do |a| |
78 | 83 | ||
79 | - p = v.prompt | 84 | + p = a.prompt |
80 | if p.left_choice.user_created == false && p.right_choice.user_created == false | 85 | if p.left_choice.user_created == false && p.right_choice.user_created == false |
81 | seed_seed_sum += 1 | 86 | seed_seed_sum += 1 |
82 | elsif p.left_choice.user_created == false && p.right_choice.user_created == true | 87 | elsif p.left_choice.user_created == false && p.right_choice.user_created == true |
@@ -100,7 +105,7 @@ namespace :test_api do | @@ -100,7 +105,7 @@ namespace :test_api do | ||
100 | d.question_id = q.id | 105 | d.question_id = q.id |
101 | d.prompt_type = type.to_s | 106 | d.prompt_type = type.to_s |
102 | d.value = average.nan? ? nil : average | 107 | d.value = average.nan? ? nil : average |
103 | - d.save! | 108 | + d.save! |
104 | end | 109 | end |
105 | 110 | ||
106 | puts "Seed_seed sum: #{seed_seed_sum}, seed_seed total num: #{seed_seed_total}" | 111 | puts "Seed_seed sum: #{seed_seed_sum}, seed_seed total num: #{seed_seed_total}" |