Skip to content

Instantly share code, notes, and snippets.

@daylen
Last active February 14, 2022 07:58
Show Gist options
  • Save daylen/1c3880c86d829ff7fe2fcd6e68f82f20 to your computer and use it in GitHub Desktop.
Save daylen/1c3880c86d829ff7fe2fcd6e68f82f20 to your computer and use it in GitHub Desktop.
google location history miles traveled
import pandas as pd
from collections import Counter
months = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER']
timelines = []
for month in months:
timelines.append(pd.read_json('2021_' + month + '.json')['timelineObjects'])
dist_by_travel_method = Counter()
for k in range(len(months)):
timeline = timelines[k]
for i in range(len(timeline)):
timeline_object = timeline[i]
if 'activitySegment' in timeline_object:
segment = timeline_object['activitySegment']
activity_type = segment['activityType']
dist_by_travel_method[activity_type] += segment['distance']
print('==== 2021 miles by vehicle type ====')
for k, v in dict(sorted(dist_by_travel_method.items(), key=lambda item: item[1])).items():
print(k, ':', int(v / 1609.0), 'miles')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment