Simple server to locally serve and simulate Stock-and-Flow models. It is just a demonstration of potential server functionality.
Pre-requisites:
- Build and install Poietic Tool. See the instructions contained in the project.
- Build the server:
swift build
Run the following script (description follows) to prepare a library from examples repository:
git clone https://github.com/OpenPoiesis/poietic-examples
./create-examples-library PoieticExamplesThe above script will:
- Download Flows examples from Poietic Examples.
- Search recursively for
*.poieticframein the downloaded directory - Creates a new design file for each frame.
- Creates a library
poietic-library.jsonin the current directory.
Start the server:
swift run poietic-serverOpen the file Demo/index.html in your browser and explore.
The server requires a design library file. The file can be created using the
Poietic tool command poietic create-library, see
poietic create-library --help for more information about the command.
Endpoints:
GET /models: get list of all models from the library.GET /models/:name: Get model details.GET /models/:name/run: Run the simulation and get the results.
Response: JSON array of objects with the following keys:
title: Model title to be displayed to the username: Model name that is used for model requests
Get more information about the model.
Response is a JSON dictionary with the following keys:
format_version: Version of the response format.info: Design info as described by theDesignInfoobject type, typically contains keys such astitle,abstract,author,licenseobjects: List of objectsid: Object IDtype: Object type namestructure: Structural type of the object:node,edge,unstructuredorigin: Origin ID if the object is an edgetarget: Target ID if the object is an edgeparent: Parent ID if the object is part of parent-child hierarchyattributes: Object-type specific attributes of the object.
nodes: List of IDs of objects representing nodesedges: List of IDs of objects representing edgesstate_variables: List of simulation state variables in the output:index: Index of the state variable in the output state.type: Type of the state variable:builtinorobjectvalue_type: Type of the value.name: Variable name.id: Optional Object ID if the variable represents an object. Seeobjects.
simulation_objects: List of objects that are used during simulation.id: ID of the simulation object (in theobjectslist)type: Type of the simulation object, how the simulation was performedvariable_index: Index of the variable that contains value of the object
parameter_controls: List of controls for simulation parameters.control_node_id: Object ID for the node representing the control.variable_index: Index of the variable of parameter.variable_name: Name of the parameter variable the control refers to.variable_node_id: ID of the variable node the control controls.value: Initial value of the parameter.
time_variable_index: Index of the variable in the state which contains time value.
Note: To learn more about possible object types and their attributes, use the
poietic metamodel command. See poietic metamodel --help for more
information.
Run the simulation and get the results.
Response is a JSON object with the following keys:
time_points: Array of time points (double values) for the simulation run. This is a convenience (redundant) result, data is contained in thedataat indextime_variable_indexdata: Array of arrays of simulation variables. Each item is a simulation state. Within the state the elements represent simulation variables as defined in thestate_variablesof the model.charts: Convenience (extracted, redundant) result with data for charts:id: Chart object IDseries: Array of chart series data:id: Series Object IDindex: Variable index of the series variable.data: Time series of the chart series.
controls: Values of control parameters as a dictionary. The keys are control IDs and values are the parameter values. This is an extracted convenience information.
- API might, and will likely change.
- Some responses might contain more information than necessary. Treat it as development-stage, debugging responses.