Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Last active January 12, 2018 13:58
Show Gist options
  • Save PrimeTimeTran/a7e61f503c5c4f44f9cbefd86e3cf829 to your computer and use it in GitHub Desktop.
Save PrimeTimeTran/a7e61f503c5c4f44f9cbefd86e3cf829 to your computer and use it in GitHub Desktop.
def five_minute_prices
time = Time.zone.now.end_of_day
first_price = Price.first.created_at
prices = {}
while first_price < time
earlier_time = time - 300
later_time = time
prices[time] = []
r = Range.new(earlier_time, later_time)
Price.all.each do |price|
prices[time] << price if r.cover?(price.created_at)
end
time -= 300
end
prices.reject { |key,value| value.empty? }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment