Created
April 5, 2023 03:22
-
-
Save radius/7d4475b78ac8cca34002f71fa94fb82f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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