Created
March 12, 2009 02:51
-
-
Save csexton/77882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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