Created
February 19, 2019 00:48
-
-
Save austindoeswork/3c03a2e91be35fde8a432b766da25f32 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
# get data with | |
# curl -vX POST https://mandrillapp.com/api/1.0/messages/search.json -d @search.json --header "Content-Type: application/json" > test.json | |
# | |
# example search.json: | |
# | |
# { | |
# "key": "<CHECK CREDSTASH", | |
# "query": "coaching session with", | |
# "date_from": "2018-12-15", | |
# "date_to": "2019-02-18", | |
# "limit": 10000 | |
# } | |
data = JSON.parse(File.read('/tmp/test.json')) | |
company_map = Hash.new{|h,k| h[k] = { | |
count: 0, | |
viewed: 0, | |
}} | |
data.each do |d| | |
email = d["email"] | |
u = User.find_by(email: email) | |
if !u.role.include?(100) | |
next | |
end | |
company_map[u.company_id][:count] += 1 | |
company_map[u.company_id][:viewed] += 1 if d["opens"] > 0 | |
end | |
puts company_map | |
# data = {37=>{:count=>23, :viewed=>2}, 49=>{:count=>57, :viewed=>10}, 47=>{:count=>50, :viewed=>46}, 55=>{:count=>64, :viewed=>57}, 64=>{:count=>1, :viewed=>0}, 7=>{:count=>1, :viewed=>0}, 26=>{:count=>1, :viewed=>1}} | |
# data = data.to_a.sort | |
# puts "company id, company name, count, % viewed" | |
# data.each do |co_id, val| | |
# puts "#{co_id}, #{Company.find(co_id).name}, #{val[:count]}, #{val[:viewed].to_f / val[:count].to_f}" | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment