Skip to content

Instantly share code, notes, and snippets.

@khannotations
Last active December 27, 2016 22:46
Show Gist options
  • Save khannotations/ed595eea8269519c7f2fe2ef16264a93 to your computer and use it in GitHub Desktop.
Save khannotations/ed595eea8269519c7f2fe2ef16264a93 to your computer and use it in GitHub Desktop.
# heroku run rails c -a ixjourney | tee file_to_export_to.csv
require 'csv'
ActiveRecord::Base.logger.level = 1
puts; puts;
puts "iX ID, first name, last name, email, phone, current city, university, graduation year, facebook, signed up at, state, references"
csv_string = CSV.generate do |csv|
User.applicants.includes(:university, { referred_by_references: :linkable }).order(:created_at).each do |applicant|
state = if applicant.applicant_valid_as?(User::AsInterviewedApplicant)
"Video submitted"
elsif applicant.applicant_valid_as?(User::AsSubmittedApplicant)
"Written submitted"
elsif applicant.applicant_valid_as?(User::AsStartedApplicant)
"Written started"
elsif applicant.applicant_valid_as?(User::AsProfile)
"Profile completed"
else
"Signed up"
end
references = applicant.referred_by_references.map(&:display_name).join(" and ")
references = "None" if references.blank?
csv << [
applicant.ix_id,
applicant.first_name,
applicant.last_name,
applicant.email,
applicant.phone,
applicant.current_city,
applicant.university.try(:name),
applicant.graduation_year,
applicant.facebook_url,
applicant.created_at.to_s(:long),
state,
references,
applicant.parent_first_name,
applicant.parent_last_name,
applicant.parent_email
]
print "."
end;nil
end
puts csv_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment