Commit eb3d6ea717632e1ce5cce70f4b76c1d03dea743b

Authored by Dhruv Kapadia
1 parent 4b729ebe

Number of choice appearances by choice creation date

Showing 1 changed file with 14 additions and 0 deletions   Show diff stats
app/controllers/questions_controller.rb
... ... @@ -207,6 +207,20 @@ class QuestionsController < InheritedResources::Base
207 207 result.each do |r|
208 208 hash[r.date]+=1
209 209 end
  210 +
  211 + elsif object_type == 'appearances_by_creation_date'
  212 +
  213 + hash = Hash.new()
  214 + @question.choices.find(:all, :order => :created_at).each do |c|
  215 + relevant_prompts = c.prompts_on_the_left.find(:all, :select => 'id') + c.prompts_on_the_right.find(:all, :select => 'id')
  216 +
  217 + appearances = Appearance.count(:conditions => {:prompt_id => relevant_prompts, :question_id => @question.id})
  218 +
  219 + #initialize key to list if it doesn't exist
  220 + (hash[c.created_at.to_date] ||= []) << { :data => c.data, :appearances => appearances}
  221 + end
  222 +
  223 +
210 224 end
211 225  
212 226 respond_to do |format|
... ...