Published
Edited
Jul 27, 2020
Importers
Insert cell
Insert cell
reportOptions = async api => {
const allTrackers = await api.request('tracker/list', null, 'list')
const now = dayjs()
const datefmt = date => date.format('YYYY-MM-DD HH:mm:ss')
return form(html`<form>
<h3>Params</h3>
<p>
<select name="tracker">${allTrackers.map(tracker => `
<option value=${tracker.id}>${tracker.label}</option>`).join("")}
</select>
</p>
<p><input name="from" value="${datefmt(now.subtract(1, 'days'))}"></p>
<p><input name="to" value="${datefmt(now)}"></p>
</form>`)
}
Insert cell
detectParkings = (points, parkingThreshold) => {
const latlngEq = (p1, p2) => p1.lat === p2.lat && p1.lng === p2.lng
if (!(points instanceof Array)) {
return points
}
const { parkings } = points.reduce((cursor, pt) => {
if (cursor.last) {
const interval = dayjs(pt.get_time).diff(dayjs(cursor.last.get_time))
if (interval > Number(parkingThreshold) * 60 * 1000) {
cursor.parkings.push({ ...cursor.last, interval })
}
}
if (!cursor.last || !latlngEq(cursor.last, pt)) {
cursor.last = pt
}
return cursor
}, { last: null, parkings: [] })
return parkings
}
Insert cell
Insert cell
import {form} from '@mbostock/form-input'
Insert cell
dayjs = require('dayjs')
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