hierarchical-estimates-visu.../lib/squiggleCalculations.js
NunoSempere 6f91849e4e feat: Get prototype working.
Display still missing, but some core functionality already
works.
2022-06-24 21:38:07 -04:00

58 lines
1.5 KiB
JavaScript

import { run } from "@quri/squiggle-lang";
export async function resolveToNumIfPossible(comparisonString) {
if (!isNaN(comparisonString) && comparisonString != "") {
let response = {
asNum: true,
num: Number(comparisonString),
};
return response;
}
let squiggleMeanCommand = `mean(${comparisonString})`;
let squiggleResponse = await run(squiggleMeanCommand);
console.log(squiggleResponse);
if (squiggleResponse.tag == "Ok") {
let responseAsNumber = squiggleResponse.value.value;
let response = {
asNum: true,
num: Number(responseAsNumber),
};
return response;
} else {
let errorMsg = squiggleResponse.value;
let response = {
asNum: false,
errorMsg: errorMsg,
};
return response;
}
}
export async function getSquiggleSparkline(comparisonString) {
if (!isNaN(comparisonString) && comparisonString != "") {
let response = {
success: true,
sparkline: comparisonString,
};
return response;
}
let squiggleSparklineCommand = `sparkline(${comparisonString}, 20)`;
let squiggleResponse = await run(squiggleSparklineCommand);
console.log(squiggleResponse);
if (squiggleResponse.tag == "Ok") {
let responseAsNumber = squiggleResponse.value.value;
let response = {
success: true,
sparkline: responseAsNumber,
};
return response;
} else {
let errorMsg = squiggleResponse.value;
let response = {
success: false,
errorMsg: errorMsg,
};
return response;
}
}