Public
Edited
Apr 24, 2023
Insert cell
Insert cell
Insert cell
message
Insert cell
Insert cell
viewof recordingDuration = Inputs.range([2, 100], {label: "Recording duratation", step: 1, value: 20})
Insert cell
viewof classes = Inputs.text({label: "All classes", value: "neutral,breath"})
Insert cell
viewof selectedClass = Inputs.select(classes.split(","), {label: "Select a Class"})
Insert cell
viewof sampleIdx = Inputs.button(`collect samples for ${recordingDuration}s`)
Insert cell
Insert cell
mutable logClasses = []
Insert cell
logClasses
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
record = {
sampleIdx;
yield true;
await Promises.delay(recordingDuration*1000)
yield false
}
Insert cell
recorder = {
if(record){
mutable logClasses.push({...message, selectedClass, sampleIdx})
return "recording"
}
return "idle"
}
Insert cell
// rename header step to heater
Insert cell
Insert cell
dataGrouped = d3.group(logClasses, d => d.selectedClass, d => d.sampleIdx, d => d.idx)
Insert cell
dataGrouped
Insert cell
formatedGas = {
let arr = []
for (const [selectedClass, samples] of dataGrouped) {
//yield sensors
for (const [sampleIdx, sensorSamples] of samples) {
const gasConcated = [0,1,2,3,4,5,6,7].map(sensorIdx => [
`sensor${sensorIdx}`,
sensorSamples.get(sensorIdx).map(d => parseInt(d.gas_resistance)).join(",")
])
arr.push({
selectedClass,
...Object.fromEntries(gasConcated)
})
}
}
return arr
}
Insert cell
formatedGas
Insert cell
createdFile = {
const z = zip();
for (const [i, row] of formatedGas.entries()) {
const csvText = d3.dsvFormat(",").format([row])
z.file(`${row.selectedClass}.${i}.csv`, csvText);
}
return z.generateAsync({ type: "blob" });
}
Insert cell
Insert cell
Insert cell
Insert cell
import {viewof port, message} from "@cpietsch/webserial-with-bme688-dev-board"
Insert cell
import {zip, zipreader} from "@fil/jszip"
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