Public
Edited
Aug 16, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
goldStandardWIP
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
goldStandard = generateGoldStandardLabels(
await gsData.labels1.json(),
await gsData.labels2.json()
)
Insert cell
Insert cell
openai = {
const openai = await import("https://cdn.skypack.dev/openai@4.47.1?min");
return new openai.OpenAI({
apiKey: openaiAPIKey,
dangerouslyAllowBrowser: true
});
}
Insert cell
localforage = import("https://cdn.skypack.dev/localforage@1.10.0?min")
Insert cell
import { guard } from "@mootari/inputs-submit"
Insert cell
Insert cell
Insert cell
function getType(value) {
if (value === null) return "null";
if (Array.isArray(value)) return "array";
return typeof value;
}
Insert cell
function valuesMatch(valueA, valueB, type) {
if (valueA === null && valueB === null) return true;

if (Array.isArray(valueB)) {
if (valueB.length === 0) {
return valueA === null;
}
return valueB.includes(valueA);
}

if (type === "number") return Math.abs(valueA - valueB) < 1e-2;
return valueA === valueB;
}
Insert cell
getTypeFromSchema = (schema) => {
return schema.hasOwnProperty("type")
? Array.isArray(schema.type)
? schema.type[0]
: schema.type
: null;
}
Insert cell
Insert cell
Insert cell
Insert cell
displayChoices = async (divID, type, options) => {
return new Promise((resolve, reject) => {
const container = document.getElementById(divID);
container.innerHTML = "";

const submitButton = document.createElement("button");
submitButton.textContent = "Submit";
submitButton.type = "button";

if (type === "string") {
// String
if (options === null) {
// Text input field when no options are available
const inputField = document.createElement("input");
inputField.type = "text";
inputField.placeholder = "Enter a string";

container.appendChild(inputField);
container.appendChild(submitButton);

submitButton.addEventListener("click", () => {
const value = inputField.value;
resolve(value === "" ? null : value);
});
} else {
// Radio buttons when options are available
options.forEach((option) => {
const radioContainer = document.createElement("div");
const radioButton = document.createElement("input");
radioButton.type = "radio";
radioButton.name = "choice";
radioButton.value = option === null ? "null" : option;

const label = document.createElement("label");
label.textContent = option === null ? "null" : option;

radioContainer.appendChild(radioButton);
radioContainer.appendChild(label);
container.appendChild(radioContainer);
});

container.appendChild(submitButton);

submitButton.addEventListener("click", () => {
const selectedOption = document.querySelector(
`input[name="choice"]:checked`
);
if (selectedOption) {
resolve(
selectedOption.value === "null" ? null : selectedOption.value
);
} else {
alert("Please select an option");
}
});
}
} else if (type === "boolean") {
["true", "false"].forEach((option) => {
const radioContainer = document.createElement("div");
const radioButton = document.createElement("input");
radioButton.type = "radio";
radioButton.name = "choice";
radioButton.value = option;

const label = document.createElement("label");
label.textContent = option;

radioContainer.appendChild(radioButton);
radioContainer.appendChild(label);
container.appendChild(radioContainer);
});

container.appendChild(submitButton);

submitButton.addEventListener("click", () => {
const selectedOption = document.querySelector(
`input[name="choice"]:checked`
);
if (selectedOption) {
resolve(selectedOption.value === "true");
} else {
alert("Please select an option");
}
});
} else if (type === "integer") {
const inputField = document.createElement("input");
inputField.type = "number";
inputField.step = "1";
inputField.placeholder = "Enter an integer value";

container.appendChild(inputField);
container.appendChild(submitButton);

submitButton.addEventListener("click", () => {
const value = inputField.value;
if (value === "") {
resolve(null);
} else {
resolve(parseInt(value, 10));
}
});
} else if (type === "number") {
const inputField = document.createElement("input");
inputField.type = "number";
inputField.placeholder = "Enter a number";

container.appendChild(inputField);
container.appendChild(submitButton);

submitButton.addEventListener("click", () => {
const value = inputField.value;
if (value === "") {
resolve(null);
} else {
resolve(parseFloat(value));
}
});
} else {
// Text input field when no options are available and the type is none of the above
const inputField = document.createElement("input");
inputField.type = "text";
inputField.placeholder = "Enter a string";

container.appendChild(inputField);
container.appendChild(submitButton);

submitButton.addEventListener("click", () => {
const value = inputField.value;
resolve(value === "" ? null : value);
});
}
});
}
Insert cell
Insert cell
Insert cell
Insert cell
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