Last active
February 3, 2017 17:06
-
-
Save cmorss/44aca4fa0f8d055083e8985cc01c3cc8 to your computer and use it in GitHub Desktop.
This will use Stuart's retention service (which pulls from Redis and stores in Cassandra) to get DAU for the specified dates and apps.
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
require 'faraday' | |
require 'faraday_middleware' | |
require 'active_support/all' | |
def period(app_id, start_date, end_date) | |
date = start_date | |
results = [] | |
while date <= end_date do | |
results << { date: date.strftime("%F"), dau: day(app_id, date) } | |
date = (date + 1) | |
end | |
results | |
end | |
def day(app_id, date) | |
results = get("/api/v1/apps/#{app_id}/active-users", start: date.strftime("%F"), end: date.strftime("%F")) | |
results["active_users"] | |
end | |
def get(path, params = nil) | |
path = "#{path}?#{params.to_param}" if params | |
request(path) | |
end | |
def request(path, params = nil) | |
response = faraday.get(path, params) | |
case response.status | |
when 200..299 | |
JSON.parse(response.body) | |
when 401 | |
{ "error" => "Unauthorized" } | |
else | |
raise ServiceException, "Error making request to EKG: #{response.status}: #{response.body}" | |
end | |
end | |
def faraday | |
@faraday ||= Faraday.new("http://internal-af7ff2860324d11e6b25e0a4adb5302e-1847371008.us-east-1.elb.amazonaws.com/api/v1") do |config| | |
# config.response :json | |
config.adapter Faraday.default_adapter | |
end | |
end | |
start_date = Date.parse("2016-12-01") | |
end_date = Date.parse("2016-12-10") | |
["54233298c74eda808c000434"].each do |app_id| | |
period(app_id, start_date, end_date).each do |datum| | |
puts [app_id, datum[:date], datum[:dau]].join(', ') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment