Skip to content

Instantly share code, notes, and snippets.

@avramd
Created June 20, 2019 19:41
Show Gist options
  • Save avramd/056f485fb1dcfc338b3b3e005821bfdd to your computer and use it in GitHub Desktop.
Save avramd/056f485fb1dcfc338b3b3e005821bfdd to your computer and use it in GitHub Desktop.
map missing accounts
user_cutoff = DateTime.parse("Tue, 18 Jun 2019 01:08:20 UTC +00:00").in_time_zone("Eastern Time (US & Canada)")
ul=User.where('created_at > ?', user_cutoff);ul.count
ul.map{|u| mc=u.marketing_contact; flu=mc.firm_level_user; puts [u.id, u.role, u.full_name_csv, u.email, u.practice_name.to_s.gsub(/,/,"-"), mc.id,mc.full_name_csv, mc.email, flu.id,flu.full_name_csv, flu.email].join(',')};:/
gul = ul.group_by{|u| u.marketing_contact.firm_level_user};gul.size
gul.map{|k,v|[v.size,k.full_name,k.email]}.sort_by(&:first).map{|e| printf("%3s: %32s %s\n", *e)};:/
clients = ul.select{|e|e.role == 'user'}.sort_by{|e|[e.marketing_contact.firm_level_user,e.marketing_contact]}; clients.size
File.open('/tmp/accounts.csv', 'w') do |f|
clients.map do |u|
next if u.full_name == 'Unassigned Accounts'
u.accounts.map do |act|
f.puts [
act.name, act.number, u.full_name, u.email,
(u.marketing_contact.role == 'sub_advisor' ? u.marketing_contact.full_name : '')].join("\t")
end
end
end;:/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment