tweak: Add lognormal parameters to the output

also change documentation, cli and example files
This commit is contained in:
NunoSempere 2022-05-03 13:03:08 -04:00
parent 5306c5a06b
commit dc863de145
4 changed files with 24 additions and 7 deletions

View File

@ -132,10 +132,13 @@ let getSimpleSquiggleOutput = (string) => transformer(string, printer);
// Model
let model = "( 2000000000 to 20000000000 ) / ( (1800000 to 2500000) * (0.25 to 0.75) * (0.2 to 5) * (5 to 50) * (0.01 to 0.1) )"
let result = getSimpleSquiggleOutput(model);
console.log(result); /* [
'lognormal(-0.3465735902799725, 1.1485521838283161)', // lognormal expression
'~0.10690936969938292 to ~4.676858552304103' // 90% confidence interval expression
] */
console.log(result); /* {
squiggleString: 'lognormal(-0.3465735902799725, 1.1485521838283161)',
lognormalParameters: [ -0.3465735902799725, 1.1485521838283161 ],
shortGuesstimateString: '0.11 to 4.7',
array90CI: [ 0.10690936969938292, 4.676858552304103 ]
}
*/
```

View File

@ -15,8 +15,9 @@ let runTransformer = (string) => {
let result = transformer(string, print);
print("");
console.groupEnd();
console.log(`=> ${result[0]}`);
console.log(` ( => ${result[1]} )`);
console.log(`=> ${result.squiggleString}`);
console.log(` ( => ${result.shortGuesstimateString} )`);
console.log("");
print("-".repeat(52));

View File

@ -2,5 +2,5 @@ import { transformer } from "./index.js";
let printer = (_) => null;
let getSimpleSquiggleOutput = (string) => transformer(string, printer);
let result = getSimpleSquiggleOutput("(1 to 10)/(1 to 20)").squiggleString;
let result = getSimpleSquiggleOutput("(1 to 10)/(1 to 20)");
console.log(result);

View File

@ -205,6 +205,17 @@ let simplePreprocessor = (string) => {
// simplePreprocessor("1 to 10 + 1 to 20");
let toLognormalParameters = (node) => {
if (isArgLognormal(node)) {
let factors = getFactors(node);
// print(node);
// print(factors);
return [factors[0], factors[1]];
} else {
return null;
}
};
let customToStringHandlerTwoDecimals = (node, options) => {
if (node.type == "ConstantNode") {
return node.value.toFixed(2);
@ -286,11 +297,13 @@ export function transformer(string, print = console.log) {
stringNew = transformerOutput.toString();
}
let squiggleString = stringNew;
let lognormalParameters = toLognormalParameters(transformerOutput);
let shortGuesstimateString = toShortGuesstimateString(transformerOutput);
let array90CI = to90CIArray(transformerOutput);
// console.log(transformerOutput);
let result = {
squiggleString: squiggleString,
lognormalParameters: lognormalParameters,
shortGuesstimateString: shortGuesstimateString,
array90CI: array90CI,
};