tweak: Slight tweaks to allow for use in observable

This commit is contained in:
NunoSempere 2022-04-22 15:17:33 -04:00
parent 7b0352660e
commit 068ee6dfec
5 changed files with 46 additions and 4 deletions

View File

@ -25,6 +25,8 @@ It may be useful for testing correctness of limited features of the full Squiggl
### Installation ### Installation
#### For command line usage
``` ```
git clone https://github.com/quantified-uncertainty/simple-squiggle.git git clone https://github.com/quantified-uncertainty/simple-squiggle.git
cd simple-squiggle cd simple-squiggle
@ -33,8 +35,16 @@ cd simple-squiggle
The last line is not necessary, since I'm saving node_packages in the repository. The last line is not necessary, since I'm saving node_packages in the repository.
#### For use inside another node program
```
npm install @forecasting/simple-squiggle
```
## Usage ## Usage
### General usage
Consider a squiggle model which only uses lognormals: Consider a squiggle model which only uses lognormals:
``` ```
@ -63,6 +73,10 @@ It can be simplified to the following simple squiggle model:
I provide both an exportable library and a command line interface (cli). The cli can be run with `npm run cli`, which produces a prompt: I provide both an exportable library and a command line interface (cli). The cli can be run with `npm run cli`, which produces a prompt:
### Command line
After cloning this repository through github (see installation section):
``` ```
> npm run cli > npm run cli
@ -104,6 +118,28 @@ For ease of representation, the intermediary outputs are printed only to two dec
You can also run tests with `npm run test` You can also run tests with `npm run test`
### Exportable library
I also provide an exportable library. After installing it with npm (see installation section), you can call it with:
```
import { transformer } from "@forecasting/simple-squiggle";
// Helpers
let printer = (_) => null;
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
] */
```
## Roadmap ## Roadmap
I consider this repository to be feature complete. As such, I may tinker with the code which wraps around the core logic, but I don't really intend to add further functionality. I consider this repository to be feature complete. As such, I may tinker with the code which wraps around the core logic, but I don't really intend to add further functionality.

2
node_modules/.package-lock.json generated vendored
View File

@ -1,5 +1,5 @@
{ {
"name": "squiggle-simplex", "name": "@forecasting/simple-squiggle",
"version": "1.0.0", "version": "1.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,

4
package-lock.json generated
View File

@ -1,11 +1,11 @@
{ {
"name": "squiggle-simplex", "name": "@forecasting/simple-squiggle",
"version": "1.0.0", "version": "1.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "squiggle-simplex", "name": "@forecasting/simple-squiggle",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {

View File

@ -1,5 +1,5 @@
{ {
"name": "squiggle-simplex", "name": "@forecasting/simple-squiggle",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",

6
src/example-import.js Normal file
View File

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