Created
February 12, 2015 22:46
-
-
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
This file contains hidden or 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
| 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