+
+ def get_votes_per_interval_data(election)
+ labels_hash = Hash.new
+ buckets = Hash.new
+ total_per_interval = Array.new
+
+ starttime = election.startdate
+ timedelta = Time.now - starttime
+ numcols = 10
+ interval_length = timedelta/numcols
+
+ # Make a hash, buckets, indexed by time intervals and containing empty arrays
+ # The time object must come first in addition!
+ # i would start at 0, i+1 goes from 0 up till numcols
+ numcols.times {|i| buckets[starttime + ((i+1)*interval_length)] = []}
+
+ # Put votes into bucket according to the time interval to which they belong,
+ # referenced by their key
+ # Will build a graph over time, as each successive interval wil lhave more
+ # vote objects
+ election.votes.each do |vote|
+ buckets.keys.sort.each do |inter|
+ if vote.time < inter
+ buckets[inter] << vote
+ end
+ end
+ end
+
+ total_per_interval = buckets.keys.sort.collect {|key| buckets[key].size}
+
+ # Create the hash for the labels. Each graph has ten columns, and three
+ # will be labeled
+ if timedelta < 2.hours #under two hours use minutes for labels
+ labels_hash[0] = starttime.min.to_s
+ labels_hash[(numcols/2)-1] = (starttime + (timedelta/2)).min.to_s
+ labels_hash[numcols-1] = Time.now.min.to_s
+ elsif timedelta < 2.days #more than 2 hours means use hours for labels
+ labels_hash[0] = starttime.hour.to_s
+ labels_hash[(numcols/2)-1] = (starttime + (timedelta/2)).hour.to_s
+ labels_hash[numcols-1] = Time.now.hour.to_s
+ else #more than 2 days means use dates for labels
+ labels_hash[0] = (Date.parse(starttime.to_s)).to_s
+ labels_hash[(numcols/2)-1] = (Date.parse(starttime + (timedelta/2))).to_s
+ labels_hash[numcols-1] = (Date.today).to_s
+ end
+
+ # Make sure to return an array for data and hash for labels
+ return total_per_interval, labels_hash
+ end