Skip to content

Instantly share code, notes, and snippets.

@vasi
Created May 25, 2017 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 vasi/5193f48a6ef8635982539bc882b07f33 to your computer and use it in GitHub Desktop.
Save vasi/5193f48a6ef8635982539bc882b07f33 to your computer and use it in GitHub Desktop.
Mac browser market share in last year, from Wikipedia
#!/usr/bin/env ruby
require 'csv'
require 'open-uri'
url = "https://analytics.wikimedia.org/datasets/periodic/reports/metrics/browser/all_sites_by_os_and_browser.tsv"
csv = CSV.new(open(url), col_sep: "\t", headers: true)
cutoff = Date.today.prev_year
counts = {}
counts.default = 0
csv.each do |r|
next unless r['os_family'] == 'Mac OS X'
next unless Date.parse(r['date']) > cutoff
counts[r['browser_family']] += r['view_count'].to_i
end
total = counts.values.reduce(:+).to_f
counts.sort_by { |k,v| -v }.each do |k,v|
puts "%-15s %5.1f" % [k, 100 * v / total]
end
Safari 47.5
Chrome 40.6
Firefox 8.9
AppleMail 2.6
Other 0.3
PhantomJS 0.0
Camino 0.0
WebKit Nightly 0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment