hierarchical-estimates-visu.../packages/webpage-refactor/lib/squiggleCalculations.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-06-17 18:47:10 +00:00
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;
}
}
2022-06-18 03:20:44 +00:00
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;
}
}