Created
December 14, 2013 22:19
-
-
Save AVGP/7965687 to your computer and use it in GitHub Desktop.
Get some insights from the location history Google saves from your phone or tablet
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' | |
| data = JSON.parse(File.read("location_history.json")) | |
| num_locations = data["locations"].length | |
| accuracy_sum = 0 | |
| activities = {} | |
| total_activities = 0 | |
| puts "Number of locations: #{num_locations}" | |
| data["locations"].each do |location| | |
| accuracy_sum = accuracy_sum + location["accuracy"] unless location["accuracy"].nil? | |
| if location["activitys"] && location["activitys"][0] | |
| activities[location["activitys"][0]["activities"][0]["type"]] = 0 if activities[location["activitys"][0]["activities"][0]["type"]].nil? | |
| activities[location["activitys"][0]["activities"][0]["type"]] = activities[location["activitys"][0]["activities"][0]["type"]] + 1 | |
| total_activities = total_activities + 1 | |
| end | |
| end | |
| puts "Avg. accuracy: #{accuracy_sum/num_locations}m" | |
| activities.each do |activity, count| | |
| puts "#{activity}: #{((count.to_f / total_activities.to_f) * 100.0).round(2)}%" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment