Public
Edited
Jun 25, 2023
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
files = zip.file(/\/Semantic Location History\/.*\.json$/)
Insert cell
fileContents = await Promise.all( files.map(f => f.async("string")))
Insert cell
places = fileContents.map(parsePlaces).flat()
Insert cell
/**
* Parse a location history
* @param {String} historyStr: a semantic activity location history .json file
* @return the parsed activities
*/
function parsePlaces(historyStr) {
const history = JSON.parse(historyStr)
if(!history.timelineObjects) { return; }
let places = [];

let days = new Set()

history.timelineObjects.forEach(timelineObject => {
const placeVisit = timelineObject.placeVisit;

if (!placeVisit || !placeVisit.location) { return; }

if (targetAddress.length > 1 && (!placeVisit.location.address || !placeVisit.location.address.match(targetAddress))) { return; }

if (!!startDate && Date.parse(placeVisit.duration.startTimestamp) < startDate) { return; }

if (!!endDate && Date.parse(placeVisit.duration.endTimestamp) > endDate) { return; }

if (days.has(new Date(placeVisit.duration.startTimestamp).toDateString())) { return; }

days.add(new Date(placeVisit.duration.startTimestamp).toDateString())
places.push(placeVisit)
})

return places;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more