Published
Edited
Dec 1, 2019
Insert cell
md`# Chain`
Insert cell
Insert cell
Insert cell
settings = ({
time_resolution: 10000,
space_resolution: 0.001
})
Insert cell
viewof data = {return html `<textarea>`}
Insert cell
chain = ({
blocks: [{hash:"0"}],
time_indexed: [],
space_indexed: {}
})
Insert cell
flow = ({now:{}})
Insert cell
reset = {
chain.blocks=[{hash:"0"}]
}
Insert cell
index_time = function(block, ts, data){
if (!chain.time_indexed[ts.year()]) chain.time_indexed[ts.year()]=[]
if (!chain.time_indexed[ts.year()][ts.month()]) chain.time_indexed[ts.year()][ts.month()]=[]
if (!chain.time_indexed[ts.year()][ts.month()][ts.date()]) chain.time_indexed[ts.year()][ts.month()][ts.date()]=[]
chain.time_indexed[ts.year()][ts.month()][ts.date()][ts.hour()+":"+ts.minute()+":"+ts.second()] = [block, data]
}
Insert cell
count = {
let ts = now
if (!chain.last) chain.last = ts
let m = moment(ts)
let dt = ""
//console.log(ts,data)
if (ts-chain.last > settings.time_resolution){
if (chain.lastdata != data) {
dt = data
index_time(chain.blocks.length, m, dt)
}
let b = crypto_js.SHA256(""+chain.blocks[chain.blocks.length-1].hash+ts+dt).toString()
mutable time = m.format()
mutable space = [position.coords.longitude,
position.coords.latitude
]
chain.blocks.push({hash: b, ts: ts})
chain.last= ts
chain.lastdata = data
}
}
Insert cell
Insert cell
moment = require('https://momentjs.com/downloads/moment-timezone-with-data.js')
Insert cell
mapboxgl = {
const gl = await require("mapbox-gl@0.49");
if (!gl.accessToken) {
gl.accessToken =
"pk.eyJ1IjoidG1jdyIsImEiOiJjamN0Z3ZiOXEwanZkMnh2dGFuemkzemE3In0.gibebYiJ5TEdXvwjpCY0jg";
const href = await require.resolve("mapbox-gl@0.49/dist/mapbox-gl.css");
document.head.appendChild(html`<link href=${href} rel=stylesheet>`);
}
return gl;
}
Insert cell
position = new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
position => { resolve(position) },
error => { reject(error) }
)
}).catch(error => error)
Insert cell
crypto_js = require("https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js")
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