Skip to content

Instantly share code, notes, and snippets.

@csexton

csexton/gist:77882

Created Mar 12, 2009
Embed
What would you like to do?
def self.fill_in_the_gaps(date_array,value_array,num_of_values)
#out of 2 arrays, one
date_value_array = []
date_array.length.times do
date_value_array << [[Time.parse(date_array.pop.to_s).strftime("%Y-%m-%d")],[value_array.pop]]
end
# fill in the gaps with zeros
val_index = 0
dates = []
values = []
num_of_values += 1
num_of_values.times do |i|
dates << i.days.ago.to_date
#puts "date1 = #{dates[i]} and date2 = #{date_value_array[val_index][0]}"
if val_index < date_value_array.length and dates[i].to_s == date_value_array[val_index][0].to_s
values << date_value_array[val_index][1].to_s.to_f
val_index += 1
else
values << 0.0
end
end
values.reverse!
dates.reverse!
return dates, values
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.