Last active
January 12, 2018 13:58
-
-
Save PrimeTimeTran/a7e61f503c5c4f44f9cbefd86e3cf829 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 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