Skip to content

Instantly share code, notes, and snippets.

@radius
Created April 5, 2023 03:22
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 radius/7d4475b78ac8cca34002f71fa94fb82f to your computer and use it in GitHub Desktop.
Save radius/7d4475b78ac8cca34002f71fa94fb82f to your computer and use it in GitHub Desktop.
user_data = XFlow::User.all.map do |u|
name = u.name
email = u.email
num_graphs = XFlow::Graph.user(u).count
num_watchlists = 0
XFlow::Chain.xflow_supported_chains.each do |c|
num_watchlists += XFlow::Watchlist.chain(c).where(user: u).count
end
[name, email, num_graphs, num_watchlists]
end
headers = ['Name', 'Email', 'Number of graphs', 'Number of watchlists']
# Open a new CSV object and convert the data to a string
csv_string = CSV.generate do |csv|
csv << headers
# Loop through each contact in the address book and write it to the CSV object
user_data.each do |user|
csv << [user[0], user[1], user[2], user[3]]
end
end
csv_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment