tweak: Add lognormal parameters to the output
also change documentation, cli and example files
This commit is contained in:
parent
5306c5a06b
commit
dc863de145
11
README.md
11
README.md
|
@ -132,10 +132,13 @@ let getSimpleSquiggleOutput = (string) => transformer(string, printer);
|
||||||
// Model
|
// 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 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);
|
let result = getSimpleSquiggleOutput(model);
|
||||||
console.log(result); /* [
|
console.log(result); /* {
|
||||||
'lognormal(-0.3465735902799725, 1.1485521838283161)', // lognormal expression
|
squiggleString: 'lognormal(-0.3465735902799725, 1.1485521838283161)',
|
||||||
'~0.10690936969938292 to ~4.676858552304103' // 90% confidence interval expression
|
lognormalParameters: [ -0.3465735902799725, 1.1485521838283161 ],
|
||||||
] */
|
shortGuesstimateString: '0.11 to 4.7',
|
||||||
|
array90CI: [ 0.10690936969938292, 4.676858552304103 ]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -15,8 +15,9 @@ let runTransformer = (string) => {
|
||||||
let result = transformer(string, print);
|
let result = transformer(string, print);
|
||||||
print("");
|
print("");
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
console.log(`=> ${result[0]}`);
|
console.log(`=> ${result.squiggleString}`);
|
||||||
console.log(` ( => ${result[1]} )`);
|
console.log(` ( => ${result.shortGuesstimateString} )`);
|
||||||
|
|
||||||
console.log("");
|
console.log("");
|
||||||
|
|
||||||
print("-".repeat(52));
|
print("-".repeat(52));
|
||||||
|
|
|
@ -2,5 +2,5 @@ import { transformer } from "./index.js";
|
||||||
|
|
||||||
let printer = (_) => null;
|
let printer = (_) => null;
|
||||||
let getSimpleSquiggleOutput = (string) => transformer(string, printer);
|
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);
|
console.log(result);
|
||||||
|
|
13
src/index.js
13
src/index.js
|
@ -205,6 +205,17 @@ let simplePreprocessor = (string) => {
|
||||||
|
|
||||||
// simplePreprocessor("1 to 10 + 1 to 20");
|
// 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) => {
|
let customToStringHandlerTwoDecimals = (node, options) => {
|
||||||
if (node.type == "ConstantNode") {
|
if (node.type == "ConstantNode") {
|
||||||
return node.value.toFixed(2);
|
return node.value.toFixed(2);
|
||||||
|
@ -286,11 +297,13 @@ export function transformer(string, print = console.log) {
|
||||||
stringNew = transformerOutput.toString();
|
stringNew = transformerOutput.toString();
|
||||||
}
|
}
|
||||||
let squiggleString = stringNew;
|
let squiggleString = stringNew;
|
||||||
|
let lognormalParameters = toLognormalParameters(transformerOutput);
|
||||||
let shortGuesstimateString = toShortGuesstimateString(transformerOutput);
|
let shortGuesstimateString = toShortGuesstimateString(transformerOutput);
|
||||||
let array90CI = to90CIArray(transformerOutput);
|
let array90CI = to90CIArray(transformerOutput);
|
||||||
// console.log(transformerOutput);
|
// console.log(transformerOutput);
|
||||||
let result = {
|
let result = {
|
||||||
squiggleString: squiggleString,
|
squiggleString: squiggleString,
|
||||||
|
lognormalParameters: lognormalParameters,
|
||||||
shortGuesstimateString: shortGuesstimateString,
|
shortGuesstimateString: shortGuesstimateString,
|
||||||
array90CI: array90CI,
|
array90CI: array90CI,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user