Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement GET DIRECT DATA for CSV #82

Merged
merged 13 commits into from
Jul 26, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
build: replace dynamic requires for genhtml (#75)
ToddFincannon committed Jul 9, 2021
commit d43e4ef9c98cdcd4eb3164870543baa1e5d13705
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SDEverywhere Guide

Revised: 2020-04-06
Revised: 2021-07-08

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -73,7 +73,7 @@ Using SDEverywhere requires the macOS operating system and the free [Xcode](http

### Install Node.js

Install [Node.js](https://nodejs.org/) version 8.9.4 LTS or later. This will also install the `npm` Node Package Manager.
Install [Node.js](https://nodejs.org/) version 14 or later. This will also install the `npm` Node Package Manager.

### Install SDEverywhere

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using SDEverywhere to Make a Vensim Model into a Web Application

Revised: 2019-07-24
Revised: 2021-07-08

This tutorial shows you how to take your Vensim model and turn it into an interactive web application using the open-source SDEverywhere toolkit. SDEverywhere currently requires the macOS operating system in development, but the resulting web app can be run on any web server, or even offline using the Firefox browser.

@@ -10,13 +10,21 @@ This tutorial shows you how to take your Vensim model and turn it into an intera

First install SDEverywhere using the instructions in the "Installing" section of the README.

### Install Browserify

HTML generation uses [Browserify](http://browserify.org) to bundle the web app. The `browserify` package is not included with SDEverywhere by default, so you will need to install it first as a dev dependency.

```
npm install --save-dev browserify
```

### Install Emscripten

The [Emscripten toolchain](https://emscripten.org/) converts the C code generated by SDEverywhere into JavaScript, and then compiles it into WebAssembly that runs in a browser.

1. Install the Java JDK. Emscripten uses Java to run the Google Closure compiler, which shrinks generated JavaScript code size considerably. Download and install the JDK from the [Oracle download page](https://www.oracle.com/technetwork/java/javase/downloads/index.html). Be sure to install the JDK and not the JRE.

2. Install Python 3. The easiest way to get the necessary SSL certificates for downloading Emscripten tools from GitHub using the Emscripten SDK is to install Python 3 with the [pyenv Python version manager](https://github.com/pyenv/pyenv). Follow the instructions for installing pyenv using Homebrew.
2. Install Python 3. This is now the default on recent versions of macOS. Check with `python --version`. If you need to install Python 3, the easiest way is to use the [pyenv Python version manager](https://github.com/pyenv/pyenv). Follow the instructions for installing pyenv using Homebrew.

3. Clone the Emscripten SDK from GitHub.

@@ -70,7 +78,7 @@ sde test -p 1e-3 {model}

## Designing your web app

SDEverywhere generates a web application based on a standard template merged with app configuration in CSV files. Refer to the *SDEverywhere Web App Configuration Reference* document for details. There is a fully worked-out example in the `models/sir` directory.
SDEverywhere generates a web application based on a standard template merged with app configuration in CSV files. Refer to the *SDEverywhere Web App Configuration Reference* document for details. There is a fully worked-out example in the `models/sir/model` directory.

Copy the `config` directory from the `notes` directory to your model directory. This will give you empty CSV files with the proper headers.

Binary file not shown.
6 changes: 6 additions & 0 deletions src/MakeConfig.js
Original file line number Diff line number Diff line change
@@ -352,6 +352,12 @@ export let makeModelConfig = () => {
console.error(e.stack)
}
}
export let readModelConfig = () => {
// Evaluate the model config file into an app object. Resolve the exports.
let cfg = B.read(cfgPathname)
cfg = `let exports = {}; ${cfg}; return exports`
return Function(cfg)()
}
export let makeChartData = async () => {
// Read the dat files given in graph config and extract data to a JS file.
// Skip this if the chart_data.js file already exists, since it normally only needs
31 changes: 16 additions & 15 deletions src/sde-generate.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import {
readDat,
readXlsx
} from './Helpers.js'
import { initConfig, makeModelSpec, makeModelConfig, makeChartData } from './MakeConfig.js'
import { initConfig, makeModelSpec, makeModelConfig, makeChartData, readModelConfig } from './MakeConfig.js'
import Model from './Model.js'
import { printSubscripts, yamlSubsList } from './Subscript.js'

@@ -216,8 +216,7 @@ let copyTemplate = buildDirname => {
let customizeApp = (modelDirname, webDirname) => {
try {
// Read the newly generated model config to customize app files.
let cfgPathname = `${webDirname}/appcfg`
const { app } = require(cfgPathname)
let app = readModelConfig().app
if (app && app.logo) {
let logoPathname = `${modelDirname}/${app.logo}`
sh.cp('-f', logoPathname, webDirname)
@@ -236,23 +235,25 @@ let customizeApp = (modelDirname, webDirname) => {
}
}
let packApp = webDirname => {
const browserify = require('browserify')
// Concatenate JS source files for the browser.
let sourcePathname = path.join(webDirname, 'index.js')
let minPathname = path.join(webDirname, 'index.min.js')
// Resolve module imports against the SDEverywhere node_modules.
let nodePath = path.join(new URL('..', import.meta.url).pathname, 'node_modules')
let b = browserify(sourcePathname, { paths: nodePath })
let writable = fs.createWriteStream(minPathname)
b.bundle()
.pipe(writable)
.on('finish', error => {
// Remove JavaScript source files.
if (!RETAIN_GENERATED_SOURCE_FILES) {
let sourceFiles = filesExcept(`${webDirname}/*.js`, name => name.endsWith('index.min.js') || name.endsWith('model_sde.js'))
sh.rm(sourceFiles)
}
})
// Browserify is an optional install that we only import when generating HTML.
import('browserify').then(browserify => {
let b = browserify.default(sourcePathname, { paths: nodePath })
let writable = fs.createWriteStream(minPathname)
b.bundle()
.pipe(writable)
.on('finish', error => {
// Remove JavaScript source files.
if (!RETAIN_GENERATED_SOURCE_FILES) {
let sourceFiles = filesExcept(`${webDirname}/*.js`, name => name.endsWith('index.min.js') || name.endsWith('model_sde.js'))
sh.rm(sourceFiles)
}
})
})
}
let parseModel = input => {
// Read the model text and return a parse tree.