Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save all4miller/335fda0d2d6fd227c285e2b3d4c35ae3 to your computer and use it in GitHub Desktop.
Save all4miller/335fda0d2d6fd227c285e2b3d4c35ae3 to your computer and use it in GitHub Desktop.
def average_time_in_hours_to_2_or_more_view
businesses = Businesss.where.not(date_achieved_2_views: nil)
hours_sum = 0
businesses.map do |business|
hours_sum += TimeDifference.between(business.created_at, business.date_achieved_2_views).in_hours
end
return nil if hours_sum.blank? || businesses.count.blank?
hours_sum / businesses.count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment