Published
Edited
May 26, 2021
Insert cell
Insert cell
Insert cell
full_data = [].concat(...array_of_full_datasets)
Insert cell
array_of_full_datasets = add_metadata_to_datasets(array_of_datasets, array_of_metadata)
Insert cell
function add_metadata_to_datasets(arr_datasets, arr_metadata) {
const new_datasets = [];
for (var i = 0; i < arr_datasets.length; i++) {
const dataset = arr_datasets[i];
const dataset2 = [];
const metadata = arr_metadata[i];
for (var j = 0; j < dataset.length; j++) {
const object = dataset[j];
for (const key in metadata) {
object[key] = metadata[key]
}
const particle_size = object["Particle size"];
if (["5nm", "20nm", "40nm", "60nm", "100nm"].includes(particle_size)) {
object["Sample type"] = "calibration"
object["Particle size (nm)"] = parseFloat(particle_size.replace("nm", ""))
} else {
object["Sample type"] = "test"
object["Particle size (nm)"] = "unknown"
}
dataset2.push(object);
}
new_datasets.push(dataset2);
}
return new_datasets;
}
Insert cell
array_of_metadata = Promise.all(meta_promises)
Insert cell
array_of_datasets = Promise.all(promises)
Insert cell
meta_promises = dataset_ids.map(id => {
const url = api_url + id + "/versions/latest/metadata";
return fetch_metadata(url) })
Insert cell
promises = dataset_ids.map(id => {
const url = api_url + id + "/versions/latest/data";
return fetch_dataset_to_array(url, {}) })
Insert cell
function fetch_metadata(dataset_url) {
return fetch(dataset_url).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();}
);
}
Insert cell
function fetch_dataset_to_array(dataset_url, query_options) {
return fetch(dataset_url, query_options).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();}).then(json => json.results.map(x => x.data));
}
Insert cell
dataset_ids = [
'b430f68d-5456-4a17-ba48-24322e0452b9',
'8161f39d-2577-43be-8330-46a6f6472dad'
]
Insert cell
api_url = "https://data.acenano.douglasconnect.com/datasets/"
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {Select, Range, Toggle} from "@observablehq/inputs"
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