Skip to content

Instantly share code, notes, and snippets.

@criess
Last active February 26, 2019 17:35
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 criess/aaeb5761043e3fe5b5722d56094c7a3d to your computer and use it in GitHub Desktop.
Save criess/aaeb5761043e3fe5b5722d56094c7a3d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
ActiveRecord::Base.logger = nil
where_after_date = begin
Time.iso8601(ARGV[0])
rescue
Date.new(2018,10,30).end_of_day
end
set = BuyingProfile.where('created_at > ?', where_after_date).where('id::varchar NOT LIKE ?', '00000000-0000-0000-0000-%').where(import_id: nil)
people = Person.where('created_at > ?', where_after_date).where('id::varchar NOT LIKE ?', '00000000-0000-0000-0000-%').where(import_id: nil)
companies = Company.where('created_at > ?', where_after_date).where('id::varchar NOT LIKE ?', '00000000-0000-0000-0000-%').where(import_id: nil)
ret = {'bp': set.to_a}
ret[:bp_industries] = set.inject({}) do |hash, b_prof|
hash[b_prof.id] = b_prof.industries.map(&:id)
hash
end
ret[:bp_regions] = set.inject({}) do |hash, b_prof|
hash[b_prof.id] = b_prof.regions.map(&:id)
hash
end
ret[:bp_transaction_types] = set.inject({}) do |hash, b_prof|
hash[b_prof.id] = b_prof.transaction_types.map(&:code)
hash
end
ret[:bp_people] = set.inject({}) do |hash, b_prof|
hash[b_prof.id] = b_prof.people.map(&:id)
hash
end
ret[:people] = people.to_a
ret[:companies] = companies.to_a
ret[:companies_people] = ret[:companies].inject({}) do |hash, company|
hash[company.id] = company.people.map(&:id)
hash
end
ret[:companies_investment_backgrounds] = ret[:companies].inject({}) do |hash, company|
hash[company.id] = company.investment_backgrounds.map(&:code)
hash
end
ret[:people_investment_backgrounds] = ret[:people].inject({}) do |hash, person|
hash[person.id] = person.investment_backgrounds.map(&:code)
hash
end
ret[:addresses] = (ret[:people] + ret[:companies]).inject([]) do |arr, linker|
arr << linker.address unless linker.address.nil?
arr
end
puts ret.to_yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment