Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created March 28, 2018 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeckham/2f38d31da52c51ded282436d002ef542 to your computer and use it in GitHub Desktop.
Save apeckham/2f38d31da52c51ded282436d002ef542 to your computer and use it in GitHub Desktop.
count useragents with specific versions
hits = 0
total = 0
require 'csv'
CSV.foreach("useragents.csv") do |row|
count = row[0].to_i
total += count
if row[1] !~ /Edge/i && row[1] =~ /Chrome\/([0-9]+)/i
hits += count if $1.to_i > 55
end
if row[1] =~ /Version\/([0-9]+).*Safari\/[0-9]+/i
hits += count if $1.to_i > 6
end
if row[1] =~ /Firefox\/([0-9]+)/i
hits += count if $1.to_i > 56
end
end
p(hits: hits, total: total, percentage: (100 * (hits / total.to_f)).round)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment