From 2a4379011dfec7d77df3a6908ad82aff360cff1e Mon Sep 17 00:00:00 2001 From: Dhruv Kapadia Date: Thu, 11 Mar 2010 10:53:55 -0500 Subject: [PATCH] Adding min and max date of votes to requests for graph data --- app/controllers/questions_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+), 0 deletions(-) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 0e44dbc..75bc574 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -170,6 +170,12 @@ class QuestionsController < InheritedResources::Base hash = Choice.count(:include => 'item', :conditions => "choices.question_id = #{@question.id} AND items.creator_id <> #{@question.creator_id}", :group => "date(choices.created_at)") + # we want graphs to go from date of first vote -> date of last vote, so adding those two boundries here. + mindate = Vote.minimum('date(created_at)', :conditions => {:question_id => @question.id}) + maxdate = Vote.maximum('date(created_at)', :conditions => {:question_id => @question.id}) + + hash[mindate] = 0 if !hash.include?(mindate) + hash[maxdate] = 0 if !hash.include?(maxdate) elsif object_type == 'user_sessions' # little more work to do here: result = Vote.find(:all, :select => 'date(created_at) as date, voter_id, count(*) as vote_count', -- libgit2 0.21.2