Created
March 28, 2018 06:26
-
-
Save apeckham/2f38d31da52c51ded282436d002ef542 to your computer and use it in GitHub Desktop.
count useragents with specific versions
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
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