2.0.2 • Published 2 years ago

insightmaker v2.0.2

Weekly downloads
153
License
ISC
Repository
github
Last release
2 years ago

InsightMaker

InsightMaker is a library that lets you use the Insight Maker API (https://insightmaker.com) on your Node.js projects. By installing you will be able to execute the IM models and get the results on your server or client-side Node.js project in the same way of Insight Maker (IM) application does.

Installation

npm i insightmaker

Basic Examples

All the API methods are asynchronous.

Exemple using a basic Node script

const Im = require('insightmaker')

const getModelResults = async filePath => {
    try {
        const model = await Im.loadModelFromFile(filePath)
        return await Im.runModel(model)
    } catch (e) {
        console.log(e)
    }
}

getModelResults('./Example.InsightMaker').then(results => {
    console.log(results)
})

Example using async methods when browser file uploaded

// Importing the IM NPM package before using it
import Im from 'insightmaker'

// Loading model by uploaded file via browser
const model = await Im.loadModelFromFile(file)

// Run the model and attibute the results into a constant
const results = await Im.runModel(model)

console.log(results)

Methods

NameParamsTypeDescription
clearModelClean the whole loaded model
createPrimitivename, type, position, sizeintegerCreates a new primitive and adds it to the model. The types can be can be: “Stock”, “Flow”, “Link”, “Text”, “Button”, “Picture”, “Converter”, “Variable” or Array of string.
findAllReturns all primitives of a specific type. They can be: “Stock”, “Flow”, “Link”, “Text”, “Button”, “Picture”, “Converter”, “Variable” or Array of string.
findIDprimitiveIdintegerReturns a primitive by its given ID.
getDataconverterSimpleNodeGiven a converter or an array of Converters, it gets the data of a converter.
getIDimPrimitiveSimpleNodeGiven a primitive, it gets the id of the passed primitive.
getNameimPrimitiveSimpleNodeGiven a primitive, it gets the name of the passed primitive.
getTypeimPrimitiveSimpleNodeGiven a primitive, it gets the type of the passed primitive.
getValueimPrimitiveSimpleNodeGiven a primitive, it gets the value of the passed primitive.
loadModelFromFilefileFile/stringLoads the exported IM models from file (Learn more about export IM files)
loadModelfileContentstringLoads the exported IM models from file content
runModelmodelObject
setValueimPrimitive, valueSimpleNode, anyGiven a primitive, it sets the primitive value.
setTimeLengthtimeLengthintegerSets the length of the simulation.
setTimeSteptimeStepstringSets the time units of the simulation. The units could be: "Seconds", "Minutes", "Days", "Years".
setTimeUnitsunitsintegerThe time step to be used in the simulation.

Exporting IM File

To get the model file from IM website and use it in your project go to Share -> Export -> Download Insight Maker File. The download must be started automatically and you can use by the command loadModelFromFile or get its content and load it by loadModel Note: If you have the file as part of your project and have the Node FS, then you can pass the file path that will be read when loading.

Export file

2.0.2

2 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.9

3 years ago

1.5.8

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago