Skip to content

Instantly share code, notes, and snippets.

@terrhorn
Created February 12, 2015 22:46
Show Gist options
  • Select an option

  • Save terrhorn/59a89b1b3a4e460639dc to your computer and use it in GitHub Desktop.

Select an option

Save terrhorn/59a89b1b3a4e460639dc to your computer and use it in GitHub Desktop.
Counts the total number of events in each collections for a given Project
require 'dotenv'
require 'keen'
Dotenv.load
# allow timeframe to be specified via the command line
# usage: ruby collection_counts.rb previous_7_days
if !ARGV[0].nil?
timeframe = ARGV[0]
end
# iterates over collections and counts the total number of events in each
# assumes you have your Keen credentials in .env
Keen.event_collections.each {|collection|
collection = collection["name"]
# count
if timeframe.nil?
results = Keen.count(collection)
else
results = Keen.count(collection,
:timeframe => timeframe
)
end
puts "#{collection}\t#{results}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment