|
@@ -1,4 +1,19 @@
|
|
|
-{
|
|
|
+const {
|
|
|
+ __errorContinuable,
|
|
|
+ __httpReq,
|
|
|
+ __wHttpReq,
|
|
|
+ __postInternalErrorMsg, __postMessage,
|
|
|
+ __sequenceNumber,
|
|
|
+ __successContinuable,
|
|
|
+ __uri_to_id
|
|
|
+} = require("../__worker");
|
|
|
+
|
|
|
+const _do = require("../___do");
|
|
|
+const _utils = require('../utils');
|
|
|
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
|
|
|
+const _fspp = _do.convert(require('../___fs++'), ['mkdirs']);
|
|
|
+
|
|
|
+module.exports = {
|
|
|
|
|
|
'interfaces': [{'method':'POST', 'url=':'/exportmtoppdevs'}],
|
|
|
'csworker':
|
|
@@ -16,11 +31,11 @@
|
|
|
incoming = {},
|
|
|
outgoing = {};
|
|
|
|
|
|
- file_contents += 'import sys\n'
|
|
|
- file_contents += 'sys.path.append("../../pypdevs/src/")\n\n'
|
|
|
- file_contents += 'from DEVS import *\n'
|
|
|
- file_contents += 'from infinity import INFINITY\n'
|
|
|
- file_contents += 'from util import *\n\n'
|
|
|
+ file_contents += 'import sys\n';
|
|
|
+ file_contents += 'sys.path.append("../../pypdevs/src/")\n\n';
|
|
|
+ file_contents += 'from DEVS import *\n';
|
|
|
+ file_contents += 'from infinity import INFINITY\n';
|
|
|
+ file_contents += 'from util import *\n\n';
|
|
|
|
|
|
for (var key in as.nodes) {
|
|
|
var node = as.nodes[key];
|
|
@@ -47,14 +62,14 @@
|
|
|
for (var e_key in as.edges) {
|
|
|
var e = as.edges[e_key];
|
|
|
if (e['dest'] == key) {
|
|
|
- safe_add(incoming[key], e['src'])
|
|
|
+ safe_add(incoming[key], e['src']);
|
|
|
if (!(e['src'] in outgoing)) {
|
|
|
outgoing[e['src']] = [];
|
|
|
}
|
|
|
safe_add(outgoing[e['src']], key);
|
|
|
}
|
|
|
if (e['src'] == key) {
|
|
|
- safe_add(outgoing[key], e['dest'])
|
|
|
+ safe_add(outgoing[key], e['dest']);
|
|
|
if (!(e['dest'] in incoming)) {
|
|
|
incoming[e['dest']] = [];
|
|
|
}
|
|
@@ -75,64 +90,64 @@
|
|
|
|
|
|
for (var key in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/StateDefinition']) {
|
|
|
var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/StateDefinition'][key],
|
|
|
- list_of_params = ['name=""'].concat(node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
|
|
|
- list_of_param_names = ['name'].concat(node['parameters']['value'].map(function(el) {return el['name']})),
|
|
|
- list_of_attrs = [['name', '']].concat(node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
|
|
|
+ list_of_params = ['name=""'].concat(node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
|
|
|
+ list_of_param_names = ['name'].concat(node['parameters']['value'].map(function(el) {return el['name'];})),
|
|
|
+ list_of_attrs = [['name', '']].concat(node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
|
|
|
file_contents += 'class ' + node['name']['value'] + ':\n';
|
|
|
file_contents += '\tdef __init__(self, ' + list_of_params.join(', ') + '):\n';
|
|
|
- file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1])}).join('\n') + "\n";
|
|
|
- file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n');
|
|
|
+ file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1]);}).join('\n') + "\n";
|
|
|
+ file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\n';
|
|
|
}
|
|
|
|
|
|
for (var key in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Event']) {
|
|
|
var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Event'][key],
|
|
|
- list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
|
|
|
- list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name']})),
|
|
|
- list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
|
|
|
+ list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
|
|
|
+ list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name'];})),
|
|
|
+ list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
|
|
|
file_contents += 'class ' + node['name']['value'] + ':\n';
|
|
|
file_contents += '\tdef __init__(self, ' + list_of_params.join(', ') + '):\n';
|
|
|
- file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1])}).join('\n') + "\n";
|
|
|
- file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n');
|
|
|
+ file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1]);}).join('\n') + "\n";
|
|
|
+ file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\n';
|
|
|
file_contents += '\tdef __str__(self):\n';
|
|
|
- file_contents += '\t\treturn "' + node['name']['value'] + '(" + ' + list_of_attrs.map(function(el) {return 'str(self.' + el[0] + ')'}).join(' + ", " + ') + ' + ")"';
|
|
|
+ file_contents += '\t\treturn "' + node['name']['value'] + '(" + ' + list_of_attrs.map(function(el) {return 'str(self.' + el[0] + ')';}).join(' + ", " + ') + ' + ")"';
|
|
|
file_contents += '\n\n';
|
|
|
}
|
|
|
|
|
|
for (var idx in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/AtomicDEVS']) {
|
|
|
var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/AtomicDEVS'][idx],
|
|
|
- list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
|
|
|
- list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name']})),
|
|
|
- list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
|
|
|
+ list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
|
|
|
+ list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name'];})),
|
|
|
+ list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
|
|
|
file_contents += 'class ' + node['name']['value'] + '(AtomicDEVS):\n';
|
|
|
file_contents += '\tdef __init__(' + (['self', 'name="' + node['name']['value'] + '"'].concat(list_of_params).join(', ')) + '):\n';
|
|
|
file_contents += '\t\tAtomicDEVS.__init__(self, name)\n';
|
|
|
- file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] + ' if ' + el[0] + ' is not None else ' + el[1] : el[1])}).join('\n');
|
|
|
+ file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] + ' if ' + el[0] + ' is not None else ' + el[1] : el[1]);}).join('\n');
|
|
|
file_contents += '\n';
|
|
|
key = type_map_keys['/Formalisms/ParallelDEVS/ParallelDEVS/AtomicDEVS'][idx];
|
|
|
- statedef = as.nodes[outgoing[outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/statedef'})[0]][0]];
|
|
|
- states = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/states'}).map(function(statesid) {return outgoing[statesid][0]}).map(function(sid) {return as.nodes[sid]});
|
|
|
- defstate = states.filter(function(el) {return el['initial']['value']})[0]
|
|
|
- list_of_assigns = ['name="' + defstate['name']['value'] + '"'].concat(statedef['initial_binding']['value'].map(function(el) {return el['name'] + '=' + el['val']}))
|
|
|
+ statedef = as.nodes[outgoing[outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/statedef';})[0]][0]];
|
|
|
+ states = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/states';}).map(function(statesid) {return outgoing[statesid][0];}).map(function(sid) {return as.nodes[sid];});
|
|
|
+ defstate = states.filter(function(el) {return el['initial']['value'];})[0];
|
|
|
+ list_of_assigns = ['name="' + defstate['name']['value'] + '"'].concat(statedef['initial_binding']['value'].map(function(el) {return el['name'] + '=' + el['val'];}));
|
|
|
file_contents += '\t\tself.state = ' + statedef['name']['value'] + '(' + list_of_assigns.join(', ') + ')\n';
|
|
|
- file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n') + "\n";
|
|
|
- ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports'}).map(function(portsid) {return outgoing[portsid][0]}).map(function(pid) {return as.nodes[pid]});
|
|
|
- file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")'}).join(', ') + '}\n\n'
|
|
|
- file_contents += '\tdef timeAdvance(self):\n'
|
|
|
- file_contents += states.map(function(s) {return '\t\tif self.state.name == "' + s['name']['value'] + '":\n' + s['time_advance']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n')}).join('\n')
|
|
|
+ file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n') + "\n";
|
|
|
+ ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports';}).map(function(portsid) {return outgoing[portsid][0];}).map(function(pid) {return as.nodes[pid];});
|
|
|
+ file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")';}).join(', ') + '}\n\n';
|
|
|
+ file_contents += '\tdef timeAdvance(self):\n';
|
|
|
+ file_contents += states.map(function(s) {return '\t\tif self.state.name == "' + s['name']['value'] + '":\n' + s['time_advance']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');}).join('\n');
|
|
|
file_contents += '\n\n';
|
|
|
- file_contents += '\tdef outputFnc(self):\n'
|
|
|
- file_contents += '\t\tdef subfunc(self):\n'
|
|
|
- file_contents += states.map(function(s) {return '\t\t\tif self.state.name == "' + s['name']['value'] + '":\n' + (s['output']['value'] == '' ? ['\t\t\t\treturn {}'] : s['output']['value'].split('\n').map(function(line) {return '\t\t\t\t' + line}).join('\n'))}).join('\n') + "\n";
|
|
|
+ file_contents += '\tdef outputFnc(self):\n';
|
|
|
+ file_contents += '\t\tdef subfunc(self):\n';
|
|
|
+ file_contents += states.map(function(s) {return '\t\t\tif self.state.name == "' + s['name']['value'] + '":\n' + (s['output']['value'] == '' ? ['\t\t\t\treturn {}'] : s['output']['value'].split('\n').map(function(line) {return '\t\t\t\t' + line;}).join('\n'));}).join('\n') + "\n";
|
|
|
file_contents += '\t\treturn {self.my_ports[k]: v for k, v in subfunc(self).iteritems()}\n';
|
|
|
file_contents += '\n\n';
|
|
|
- file_contents += '\tdef intTransition(self):\n'
|
|
|
+ file_contents += '\tdef intTransition(self):\n';
|
|
|
var content = false;
|
|
|
for (var sidx in states) {
|
|
|
s = states[sidx];
|
|
|
if (outgoing[s['$key']]) {
|
|
|
- internals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/InternalTransition'}).map(function(tid) {return as.nodes[tid]});
|
|
|
+ internals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/InternalTransition';}).map(function(tid) {return as.nodes[tid];});
|
|
|
for (var iidx in internals) {
|
|
|
content = true;
|
|
|
internal = internals[iidx];
|
|
@@ -140,9 +155,9 @@
|
|
|
cond_name = 'cond_int_' + s['name']['value'] + '_to_' + target['name']['value'],
|
|
|
action_name = 'action_int_' + s['name']['value'] + '_to_' + target['name']['value'];
|
|
|
file_contents += '\t\t\def ' + cond_name + '():\n';
|
|
|
- file_contents += internal['condition']['value'] == '' ? '\t\t\treturn True' : internal['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += internal['condition']['value'] == '' ? '\t\t\treturn True' : internal['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\t\t\def ' + action_name + '():\n';
|
|
|
- file_contents += internal['action']['value'] == '' ? '\t\t\treturn {}' : internal['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += internal['action']['value'] == '' ? '\t\t\treturn {}' : internal['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\t\tif self.state.name == "' + s['name']['value'] + '" and ' + cond_name + '():\n';
|
|
|
file_contents += '\t\t\treturn ' + statedef['name']['value'] + '(name="' + target['name']['value'] + '", **' + action_name + '())\n\n';
|
|
|
}
|
|
@@ -155,23 +170,23 @@
|
|
|
file_contents += '\t\t\treturn AtomicDEVS.intTransition(self)\n';
|
|
|
}
|
|
|
file_contents += '\n';
|
|
|
- file_contents += '\tdef extTransition(self, my_inputs):\n'
|
|
|
- file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n'
|
|
|
+ file_contents += '\tdef extTransition(self, my_inputs):\n';
|
|
|
+ file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n';
|
|
|
content = false;
|
|
|
for (var sidx in states) {
|
|
|
s = states[sidx];
|
|
|
if (outgoing[s['$key']]) {
|
|
|
- externals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ExternalTransition'}).map(function(tid) {return as.nodes[tid]});
|
|
|
+ let externals = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ExternalTransition';}).map(function(tid) {return as.nodes[tid];});
|
|
|
for (var iidx in externals) {
|
|
|
content = true;
|
|
|
- external = externals[iidx];
|
|
|
- var target = as.nodes[outgoing[external['$key']][0]],
|
|
|
+ let extern = externals[iidx];
|
|
|
+ var target = as.nodes[outgoing[extern['$key']][0]],
|
|
|
cond_name = 'cond_ext_' + s['name']['value'] + '_to_' + target['name']['value'],
|
|
|
action_name = 'action_ext_' + s['name']['value'] + '_to_' + target['name']['value'];
|
|
|
file_contents += '\t\t\def ' + cond_name + '():\n';
|
|
|
- file_contents += external['condition']['value'] == '' ? '\t\t\treturn True' : external['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += extern['condition']['value'] == '' ? '\t\t\treturn True' : extern['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\t\t\def ' + action_name + '():\n';
|
|
|
- file_contents += external['action']['value'] == '' ? '\t\t\treturn {}' : external['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += extern['action']['value'] == '' ? '\t\t\treturn {}' : extern['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\t\tif self.state.name == "' + s['name']['value'] + '" and ' + cond_name + '():\n';
|
|
|
file_contents += '\t\t\treturn ' + statedef['name']['value'] + '(name="' + target['name']['value'] + '", **' + action_name + '())\n\n';
|
|
|
}
|
|
@@ -183,13 +198,13 @@
|
|
|
file_contents += '\t\telse:\n';
|
|
|
file_contents += '\t\t\treturn AtomicDEVS.extTransition(self, my_inputs)\n';
|
|
|
}
|
|
|
- file_contents += '\n'
|
|
|
- file_contents += '\tdef confTransition(self, my_inputs):\n'
|
|
|
- file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n'
|
|
|
+ file_contents += '\n';
|
|
|
+ file_contents += '\tdef confTransition(self, my_inputs):\n';
|
|
|
+ file_contents += '\t\tinputs = {k.getPortName(): v for k, v in my_inputs.iteritems()}\n';
|
|
|
content = false;
|
|
|
for (var sidx in states) {
|
|
|
s = states[sidx];
|
|
|
- confluents = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ConfluentTransition'}).map(function(tid) {return as.nodes[tid]});
|
|
|
+ confluents = outgoing[s['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ConfluentTransition';}).map(function(tid) {return as.nodes[tid];});
|
|
|
for (var iidx in confluents) {
|
|
|
content = true;
|
|
|
confluent = confluents[iidx];
|
|
@@ -197,9 +212,9 @@
|
|
|
cond_name = 'cond_conf_' + s['name']['value'] + '_to_' + target['name']['value'],
|
|
|
action_name = 'action_conf_' + s['name']['value'] + '_to_' + target['name']['value'];
|
|
|
file_contents += '\t\t\def ' + cond_name + '():\n';
|
|
|
- file_contents += confluent['condition']['value'] == '' ? '\t\t\treturn True' : confluent['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += confluent['condition']['value'] == '' ? '\t\t\treturn True' : confluent['condition']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\t\t\def ' + action_name + '():\n';
|
|
|
- file_contents += confluent['action']['value'] == '' ? '\t\t\treturn {}' : confluent['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += confluent['action']['value'] == '' ? '\t\t\treturn {}' : confluent['action']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\t\tif self.state.name == "' + s['name']['value'] + '" and ' + cond_name + '():\n';
|
|
|
file_contents += '\t\t\treturn ' + statedef['name']['value'] + '(name="' + target['name']['value'] + '", **' + action_name + '())\n\n';
|
|
|
}
|
|
@@ -210,35 +225,35 @@
|
|
|
file_contents += '\t\telse:\n';
|
|
|
file_contents += '\t\t\treturn AtomicDEVS.confTransition(self, my_inputs)\n';
|
|
|
}
|
|
|
- file_contents += '\n'
|
|
|
+ file_contents += '\n';
|
|
|
}
|
|
|
|
|
|
for (var idx in type_map['/Formalisms/ParallelDEVS/ParallelDEVS/CoupledDEVS']) {
|
|
|
var node = type_map['/Formalisms/ParallelDEVS/ParallelDEVS/CoupledDEVS'][idx],
|
|
|
- list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None'})),
|
|
|
- list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name']})),
|
|
|
- list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']]}));
|
|
|
+ list_of_params = (node['parameters']['value'].map(function(el) {return el['name'] + '=None';})),
|
|
|
+ list_of_param_names = (node['parameters']['value'].map(function(el) {return el['name'];})),
|
|
|
+ list_of_attrs = (node['attributes']['value'].map(function(el) {return [el['name'], el['default']];}));
|
|
|
file_contents += 'class ' + node['name']['value'] + '(CoupledDEVS):\n';
|
|
|
file_contents += '\tdef __init__(' + (['self', 'name="' + node['name']['value'] + '"'].concat(list_of_params).join(', ')) + '):\n';
|
|
|
file_contents += '\t\tCoupledDEVS.__init__(self, name)\n';
|
|
|
- file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1])}).join('\n') + "\n";
|
|
|
- file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line}).join('\n') + "\n";
|
|
|
+ file_contents += list_of_attrs.map(function(el) {return '\t\tself.' + el[0] + ' = ' + (list_of_param_names.indexOf(el[0]) != -1 ? el[0] : el[1]);}).join('\n') + "\n";
|
|
|
+ file_contents += node['__init__']['value'].split('\n').map(function(line) {return '\t\t' + line;}).join('\n') + "\n";
|
|
|
key = type_map_keys['/Formalisms/ParallelDEVS/ParallelDEVS/CoupledDEVS'][idx];
|
|
|
- ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports'}).map(function(portsid) {return outgoing[portsid][0]}).map(function(pid) {return as.nodes[pid]});
|
|
|
- file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")'}).join(', ') + '}\n'
|
|
|
+ ports = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports';}).map(function(portsid) {return outgoing[portsid][0];}).map(function(pid) {return as.nodes[pid];});
|
|
|
+ file_contents += '\t\tself.my_ports = {' + ports.map(function(el) {return '"' + el['name']['value'] + '": ' + (el['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/OutputPort' ? 'self.addOutPort("' : 'self.addInPort("') + el['name']['value'] + '")';}).join(', ') + '}\n';
|
|
|
file_contents += '\t\tself.submodels = {}\n';
|
|
|
- submodels = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/submodels'}).map(function(submodelsid) {return outgoing[submodelsid][0]}).map(function(mid) {return as.nodes[mid]});
|
|
|
- file_contents += submodels.map(function(m) {return '\t\tself.submodels["' + m['name']['value'] + '"] = self.addSubModel(' + m['devs_type']['value'] + '(' + ['name="' + m['name']['value'] + '"'].concat(m['parameter_binding']['value'].map(function(pb) {return pb['name'] + '=' + pb['val']})).join(', ') + '))'}).join('\n');
|
|
|
+ submodels = outgoing[key].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/submodels';}).map(function(submodelsid) {return outgoing[submodelsid][0];}).map(function(mid) {return as.nodes[mid];});
|
|
|
+ file_contents += submodels.map(function(m) {return '\t\tself.submodels["' + m['name']['value'] + '"] = self.addSubModel(' + m['devs_type']['value'] + '(' + ['name="' + m['name']['value'] + '"'].concat(m['parameter_binding']['value'].map(function(pb) {return pb['name'] + '=' + pb['val'];})).join(', ') + '))';}).join('\n');
|
|
|
file_contents += '\n\n';
|
|
|
- myportkeys = ports.map(function(port) {return port['$key']});
|
|
|
+ myportkeys = ports.map(function(port) {return port['$key'];});
|
|
|
port_to_m = {};
|
|
|
m_to_ports = {};
|
|
|
m_to_ports[key] = ports;
|
|
|
- ports.forEach(function(p) {port_to_m[p['$key']] = node});
|
|
|
+ ports.forEach(function(p) {port_to_m[p['$key']] = node;});
|
|
|
for (var skey in submodels) {
|
|
|
var m = submodels[skey];
|
|
|
m_to_ports[m['$key']] = [];
|
|
|
- ports = outgoing[m['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports'}).map(function(portsid) {return outgoing[portsid][0]}).map(function(pid) {return as.nodes[pid]});
|
|
|
+ ports = outgoing[m['$key']].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/ports';}).map(function(portsid) {return outgoing[portsid][0];}).map(function(pid) {return as.nodes[pid];});
|
|
|
ports.forEach(function(p) {port_to_m[p['$key']] = m; m_to_ports[m['$key']].push(p);});
|
|
|
}
|
|
|
for (var mkey in m_to_ports) {
|
|
@@ -246,7 +261,7 @@
|
|
|
var p = m_to_ports[mkey][pidx],
|
|
|
pkey = p['$key'];
|
|
|
if (pkey in outgoing) {
|
|
|
- var conns = outgoing[pkey].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/channel'}).map(function(channelid) {return as.nodes[channelid]})
|
|
|
+ var conns = outgoing[pkey].filter(function(el) {return as.nodes[el]['$type'] == '/Formalisms/ParallelDEVS/ParallelDEVS/channel';}).map(function(channelid) {return as.nodes[channelid];});
|
|
|
for (var cidx in conns) {
|
|
|
var conn = conns[cidx],
|
|
|
target = as.nodes[outgoing[conn['$key']][0]],
|
|
@@ -255,7 +270,7 @@
|
|
|
toportstr = (port_to_m[target['$key']]['$key'] == key ? 'self' : 'self.submodels["' + port_to_m[target['$key']]['name']['value'] + '"]') + '.my_ports["' + target['name']['value'] + '"]';
|
|
|
if (conn['transfer_function']['value'] != '') {
|
|
|
file_contents += '\t\tdef ' + transfname + '(event):\n';
|
|
|
- file_contents += conn['transfer_function']['value'].split('\n').map(function(line) {return '\t\t\t' + line}).join('\n');
|
|
|
+ file_contents += conn['transfer_function']['value'].split('\n').map(function(line) {return '\t\t\t' + line;}).join('\n');
|
|
|
file_contents += '\n\n';
|
|
|
file_contents += '\t\tself.connectPorts(' + fromportstr + ', ' + toportstr + ', ' + transfname + ')\n\n';
|
|
|
} else {
|
|
@@ -279,7 +294,7 @@
|
|
|
|
|
|
file_contents += 'def termination_condition(time, model, transitioned):\n';
|
|
|
file_contents += '\ttime = time[0]\n';
|
|
|
- file_contents += type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Simulation'][0]['end_condition']['value'].split('\n').map(function(line) {return '\t' + line}).join('\n') + '\n';
|
|
|
+ file_contents += type_map['/Formalisms/ParallelDEVS/ParallelDEVS/Simulation'][0]['end_condition']['value'].split('\n').map(function(line) {return '\t' + line;}).join('\n') + '\n';
|
|
|
|
|
|
_fs.writeFileSync('./exported_to_pypdevs/experiment.py', file_contents);
|
|
|
|
|
@@ -290,7 +305,7 @@
|
|
|
);
|
|
|
},
|
|
|
function(err) {__postInternalErrorMsg(resp, err);}
|
|
|
- )
|
|
|
+ );
|
|
|
},
|
|
|
'asworker':
|
|
|
function(resp, method, uri, reqData, wcontext)
|
|
@@ -299,4 +314,4 @@
|
|
|
{'statusCode': 200,
|
|
|
'respIndex': resp});
|
|
|
}
|
|
|
-}
|
|
|
+};
|