Created
May 27, 2014 16:39
-
-
Save stuartlynn/51890ceeadda90102b5e to your computer and use it in GitHub Desktop.
Language stats for project
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
require 'mongo' | |
client = Mongo::MongoClient.new | |
db = client["ouroboros"] | |
stats = {} | |
total = db["galaxy_zoo_classifications"].count | |
done = 0 | |
db["galaxy_zoo_classifications"].find.each do |classification| | |
done += 1 | |
puts "done #{done} of #{total}" if done%1000==0 | |
lang = (classification["annotations"].select{|ann| ann.keys.include? "lang"}.first || {"lang" => "en"})["lang"] | |
stats[lang] ||= {logged_in: 0 , logged_out: 0 , user_ids: Set.new, user_ips: Set.new } | |
if classification["user_id"] | |
stats[lang][:logged_in] += 1 | |
stats[lang][:user_ids].add classification["user_id"] | |
else | |
stats[lang][:logged_out] += 1 | |
stats[lang][:user_ips].add classification["user_ip"] | |
end | |
end | |
File.open("galaxy_zoo_lang_stats.dat","w") do |file| | |
stats.each_pair do |lang, s| | |
file.puts [lang, s[:logged_in], s[:logged_out], s[:user_ids].count, s[:user_ips].count].join(", ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment