Created
March 28, 2015 03:22
-
-
Save scottlingran/1f1104c068309768b3f6 to your computer and use it in GitHub Desktop.
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 'json' | |
require 'time' | |
require 'csv' | |
file = File.open("messages.json").read | |
messages = JSON.parse(file) | |
# consolidate | |
# Sort | |
analytics = messages.map do |message| | |
puts message["contact"] | |
{ | |
contact: message["contact"], | |
last_message: Time.at(message["messages"][0]["timestamp"]), | |
count: message["messages"].count, | |
} | |
end | |
analytics.sort! {|a, b| b[:count] <=> a[:count]} | |
csv = CSV.open("analysis.csv", "w+") | |
analytics.each do |a| | |
csv << [a[:contact], a[:count], a[:last_message]] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment