Public
Edited
Nov 25, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
filtered = {
const minDate = new Date(2000, 0, 1);
const arr = [];
for (const o of locations) {
if (o.accuracy < 40 && o.timestamp > minDate) {
//if (o.timestamp > minDate) {
const d = distance(o, center);
if (d < 0.6) {
arr.push({ ...o, distance: d });
}
}
}
return arr;
}
Insert cell
days = {
const s = new Set();
for (const o of filtered) {
const d = o.timestamp;
s.add(
[d.getFullYear(), d.getMonth() + 1, d.getDate()]
.map((d) => String(d).padStart(2, "0"))
.join("-")
);
}

return Array.from(s)
.map((s) => {
if (s.length === 10) {
const [yyyy, mm, dd] = [
s.slice(0, 4),
s.slice(5, 7),
s.slice(8, 10)
].map((s) => +s);
return new Date(Date.UTC(yyyy, mm - 1, dd));
}
return null;
})
.sort();
}
Insert cell
days.length
Insert cell
Calendar(days, { date: (o) => o, value: (o) => 1 })
Insert cell
Insert cell
Insert cell
function distance(
{ latitude: latitude0, longitude: longitude0 },
{ latitude: latitude1, longitude: longitude1 }
) {
var R = 6371;
var dLat = deg2rad((latitude1 - latitude0) / 1e7);
var dLon = deg2rad((longitude1 - longitude0) / 1e7);
var a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(latitude0 / 1e7)) *
Math.cos(deg2rad(latitude1 / 1e7)) *
Math.sin(dLon / 2) *
Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d;
}
Insert cell
function deg2rad(deg) {
return deg * (Math.PI/180)
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more