Skip to content

Instantly share code, notes, and snippets.

@scottlingran
Created March 28, 2015 03:22
Show Gist options
  • Save scottlingran/1f1104c068309768b3f6 to your computer and use it in GitHub Desktop.
Save scottlingran/1f1104c068309768b3f6 to your computer and use it in GitHub Desktop.
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