Commit 2a4379011dfec7d77df3a6908ad82aff360cff1e

Authored by Dhruv Kapadia
1 parent fa19002c

Adding min and max date of votes to requests for graph data

Showing 1 changed file with 6 additions and 0 deletions   Show diff stats
app/controllers/questions_controller.rb
... ... @@ -170,6 +170,12 @@ class QuestionsController < InheritedResources::Base
170 170 hash = Choice.count(:include => 'item',
171 171 :conditions => "choices.question_id = #{@question.id} AND items.creator_id <> #{@question.creator_id}",
172 172 :group => "date(choices.created_at)")
  173 + # we want graphs to go from date of first vote -> date of last vote, so adding those two boundries here.
  174 + mindate = Vote.minimum('date(created_at)', :conditions => {:question_id => @question.id})
  175 + maxdate = Vote.maximum('date(created_at)', :conditions => {:question_id => @question.id})
  176 +
  177 + hash[mindate] = 0 if !hash.include?(mindate)
  178 + hash[maxdate] = 0 if !hash.include?(maxdate)
173 179 elsif object_type == 'user_sessions'
174 180 # little more work to do here:
175 181 result = Vote.find(:all, :select => 'date(created_at) as date, voter_id, count(*) as vote_count',
... ...