Skip to content

Instantly share code, notes, and snippets.

@DavidEdwards1
Last active January 24, 2018 16:00
Show Gist options
  • Save DavidEdwards1/1d0ff05b70bdc7d43e3b1cfa2c981d82 to your computer and use it in GitHub Desktop.
Save DavidEdwards1/1d0ff05b70bdc7d43e3b1cfa2c981d82 to your computer and use it in GitHub Desktop.
Gist to calculate (roughly) the number of account managers who logged in the last year
switch_to_slave_db
PRACTICES_TO_IGNORE = %w[
12506
17
13699
11040
13952
68
18555
768
16860
].map(&:to_i)
practice_id_list = AccountancyPractice.joins(:fapd_sale).
where("fapd_sales.status IN (?)", [PracticeSaleStatus::ACTIVE, PracticeSaleStatus::INTERNAL]).
where("accountancy_practices.salesforce_key != '' AND accountancy_practices.id NOT IN (?)", PRACTICES_TO_IGNORE).
pluck(:id)
account_managers = AccountManager.
where('accountancy_practice_id IN (?)',practice_id_list).
where('last_logged_in_at > (?)',1.years.ago).
pluck(:id,:accountancy_practice_id,:last_logged_in_at)
account_practices = Set[]
account_managers.each{ |x| account_practices.add(x[1]) }
puts practice_id_list.count
puts account_managers.count
puts account_practices.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment