Skip to content

Instantly share code, notes, and snippets.

@arfon
Created June 10, 2012 11:31
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 arfon/2905029 to your computer and use it in GitHub Desktop.
Save arfon/2905029 to your computer and use it in GitHub Desktop.
Supernova classification exporter
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "",
:database => "super"
)
class Asset < ActiveRecord::Base
has_many :asset_classifications
has_many :classifications, :through => :asset_classifications
end
class Classification < ActiveRecord::Base
has_many :asset_classifications, :dependent => :destroy
has_many :assets, :through => :asset_classifications
def asset
assets.first
end
end
class AssetClassification < ActiveRecord::Base
belongs_to :classification
belongs_to :asset
end
outfile = File.new('classifications.csv', 'w')
count = 0
outfile.puts "classification_id,user_id,asset_id,asset_average_score,asset_external_ref,asset_location,classification_created_at,classification_score"
Classification.find_each do |c|
count += 1
outfile.puts "#{c.id},#{c.zooniverse_user_id},#{c.asset.id},#{c.asset.average_score},#{c.asset.external_ref},#{c.asset.location},#{c.created_at},#{c.total_score}"
puts count if count % 1000 == 0
end
outfile.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment