Created
April 1, 2021 16:29
-
-
Save all4miller/335fda0d2d6fd227c285e2b3d4c35ae3 to your computer and use it in GitHub Desktop.
This file contains 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 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