From eb3d6ea717632e1ce5cce70f4b76c1d03dea743b Mon Sep 17 00:00:00 2001 From: Dhruv Kapadia Date: Wed, 7 Apr 2010 13:29:10 -0400 Subject: [PATCH] Number of choice appearances by choice creation date --- app/controllers/questions_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+), 0 deletions(-) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index b34cf0e..2dc8f7a 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -207,6 +207,20 @@ class QuestionsController < InheritedResources::Base result.each do |r| hash[r.date]+=1 end + + elsif object_type == 'appearances_by_creation_date' + + hash = Hash.new() + @question.choices.find(:all, :order => :created_at).each do |c| + relevant_prompts = c.prompts_on_the_left.find(:all, :select => 'id') + c.prompts_on_the_right.find(:all, :select => 'id') + + appearances = Appearance.count(:conditions => {:prompt_id => relevant_prompts, :question_id => @question.id}) + + #initialize key to list if it doesn't exist + (hash[c.created_at.to_date] ||= []) << { :data => c.data, :appearances => appearances} + end + + end respond_to do |format| -- libgit2 0.21.2