Skip to content

Instantly share code, notes, and snippets.

@akinsgre
Created January 25, 2012 15:15
Show Gist options
  • Save akinsgre/1676729 to your computer and use it in GitHub Desktop.
Save akinsgre/1676729 to your computer and use it in GitHub Desktop.
#starting at line 243
def feeds_into_timescales(feeds)
# convert timescale (minutes) into seconds
seconds = params[:timescale].to_i * 60
# get floored time ranges
logger.info "Original Start time is " + feeds.first.created_at.to_s
logger.info "Original End time is " + feeds.last.created_at.to_s
start_time = get_floored_time(feeds.first.created_at, seconds)
end_time = get_floored_time(feeds.last.created_at, seconds)
logger.info "start_time = " + start_time.to_s + " & end_time is " + end_time.to_s
logger.info "if start_time is greater than end_time, an error will occur"
# create empty array with appropriate size
timeslices = Array.new(((end_time - start_time) / seconds).floor)
# create a blank clone of the first feed so that we only get the necessary attributes
empty_feed = create_empty_clone(feeds.first)
# add feeds to array
feeds.each do |f|
i = ((f.created_at - start_time) / seconds).floor
f.created_at = start_time + i * seconds
timeslices[i] = f if timeslices[i].nil?
end
Original Start time is 2012-01-25 15:11:08 UTC
Original End time is 2012-01-25 15:00:33 UTC
start_time = 2012-01-25 15:10:00 UTC & end_time is 2012-01-25 15:00:00 UTC
if start_time is greater than end_time, an error will occur
Completed in 169ms
ArgumentError (negative array size):
app/controllers/feed_controller.rb:254:in `initialize'
app/controllers/feed_controller.rb:254:in `new'
app/controllers/feed_controller.rb:254:in `feeds_into_timescales'
app/controllers/feed_controller.rb:39:in `index'
Rendered /Users/gakins/.rvm/gems/ruby-1.9.2-p290@rails309/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /Users/gakins/.rvm/gems/ruby-1.9.2-p290@rails309/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.5ms)
Rendered /Users/gakins/.rvm/gems/ruby-1.9.2-p290@rails309/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.6ms)
Original Start time is 2012-01-25 15:11:08 UTC
Original End time is 2012-01-25 15:00:33 UTC
start_time = 2012-01-25 15:10:00 UTC & end_time is 2012-01-25 15:00:00 UTC
if start_time is greater than end_time, an error will occur
Completed in 169ms
ArgumentError (negative array size):
app/controllers/feed_controller.rb:254:in `initialize'
app/controllers/feed_controller.rb:254:in `new'
app/controllers/feed_controller.rb:254:in `feeds_into_timescales'
app/controllers/feed_controller.rb:39:in `index'
Rendered /Users/gakins/.rvm/gems/ruby-1.9.2-p290@rails309/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /Users/gakins/.rvm/gems/ruby-1.9.2-p290@rails309/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.5ms)
Rendered /Users/gakins/.rvm/gems/ruby-1.9.2-p290@rails309/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.6ms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment