Commit 647ad8f2 authored by Jérome Perrin's avatar Jérome Perrin

Change the "simulation class" into a configuration class passed at startup time

parent 218f2fbb
......@@ -107,26 +107,44 @@ def runSimulation():
return jsonify(dict(error='Timeout after %s seconds' % timeout))
result = queue.get()
app.logger.debug("resulth:\n%s" % (json.dumps(result,
sort_keys=True, indent=2)))
app.logger.debug("result\n%s" % (json.dumps(result,
sort_keys=True, indent=2)))
return jsonify(result)
def _runSimulation(parameter_dict, queue):
try:
klass_name = 'dream.simulation.%s' % \
parameter_dict['general']['simulationClass']
klass = __import__(klass_name, globals(), {}, klass_name)
result = klass.Simulation(logger=app.logger).run(parameter_dict)
result = getGUIInstance().run(parameter_dict)
queue.put(dict(success=result))
except Exception, e:
tb = traceback.format_exc()
app.logger.error(tb)
queue.put(dict(error=tb))
def getGUIInstance():
# XXX do not instanciate each time!
klass_name = 'dream.simulation.GUI.Default'
if len(sys.argv) > 1:
klass_name = 'dream.simulation.GUI.%s' % sys.argv[1]
klass = __import__(klass_name, globals(), {}, klass_name)
instance = klass.Simulation(logger=app.logger)
return instance
@app.route("/getConfigurationDict")
def getConfigurationDict():
return jsonify(getGUIInstance().getConfigurationDict())
@app.route("/getOutputIdList", methods=["POST", "OPTIONS"])
def getOutputIdList():
return jsonify(getGUIInstance().getOutputIdList())
@app.route("/getInputIdList", methods=["POST", "OPTIONS"])
def getInputIdList():
return jsonify(getGUIInstance().getInputIdList())
def main(*args):
# start the server
file_handler = logging.FileHandler(os.path.join(os.path.dirname(__file__), '..', '..', 'log', 'dream.log'))
file_handler = logging.FileHandler(
os.path.join(os.path.dirname(__file__), '..', '..', 'log', 'dream.log'))
file_handler.setLevel(logging.DEBUG)
app.logger.addHandler(file_handler)
app.run(debug=True)
......@@ -140,7 +158,6 @@ def run(*args):
output_data = queue.get()
print json.dumps(output_data, indent=True)
if __name__ == "__main__":
main()
......@@ -27,198 +27,17 @@
applicationname: "dream"
});
var property_container = {
entity: {
id: "entity",
type: "string",
_class: "Dream.Property",
_default: "Part"
},
// XXX is it possible not to repeat id ?
mean: {
id: "mean",
type: "string",
_class: "Dream.Property",
_default: "0.9"
},
distributionType: {
id: "distributionType",
type: "string",
_class: "Dream.Property",
_default: "Fixed"
},
stdev: {
id: "stdev",
type: "string",
_class: "Dream.Property",
_default: "0.1"
},
min: {
id: "min",
type: "string",
_class: "Dream.Property",
_default: "0.1"
},
max: {
id: "max",
type: "string",
_class: "Dream.Property",
_default: "1"
},
failureDistribution: {
id: "failureDistribution",
type: "string",
_class: "Dream.Property",
_default: "No"
},
MTTF: {
id: "MTTF",
type: "string",
_class: "Dream.Property",
_default: "40"
},
MTTR: {
id: "MTTR",
type: "string",
_class: "Dream.Property",
_default: "10"
},
repairman: {
id: "repairman",
type: "string",
_class: "Dream.Property",
_default: "None"
},
isDummy: {
id: "isDummy",
type: "string",
_class: "Dream.Property",
_default: "0"
},
schedulingRule: {
id: "schedulingRule",
type: "string",
_class: "Dream.Property",
_default: "FIFO"
},
capacity: {
id: "capacity",
type: "string",
_class: "Dream.Property",
_default: "1"
},
simulationClass: {
id: "simulationClass",
type: "string",
_class: "Dream.Property",
_default: "Default"
},
numberOfReplications: {
id: "numberOfReplications",
type: "string",
_class: "Dream.Property",
_default: "10"
},
maxSimTime: {
id: "maxSimTime",
type: "string",
_class: "Dream.Property",
_default: "100"
},
confidenceLevel: {
id: "confidenceLevel",
type: "string",
_class: "Dream.Property",
_default: "0.5"
},
processTimeout: {
id: "processTimeout",
type: "string",
_class: "Dream.Property",
_default: "0.5"
}
};
property_container["interarrivalTime"] = {
id: "interarrivalTime",
property_list: [property_container["mean"], property_container[
"distributionType"]],
_class: "Dream.PropertyList"
};
property_container["processingTime"] = {
id: "processingTime",
property_list: [property_container["mean"], property_container[
"distributionType"],
property_container["stdev"], property_container["min"],
property_container["max"]
],
_class: "Dream.PropertyList"
};
property_container["failures"] = {
id: "failures",
property_list: [property_container["failureDistribution"],
property_container["MTTF"],
property_container["MTTR"], property_container["repairman"]
],
_class: "Dream.PropertyList"
};
var configuration = { };
var configuration = {
"Dream-Source": {
property_list: [property_container["interarrivalTime"],
property_container["entity"]
],
_class: 'Dream.Source'
},
"Dream-Machine": {
property_list: [property_container["processingTime"],
property_container["failures"]
],
_class: 'Dream.Machine'
},
"Dream-Queue": {
property_list: [property_container["capacity"],
property_container["isDummy"],
property_container["schedulingRule"]
],
_class: 'Dream.Queue'
},
"Dream-Exit": {
_class: 'Dream.Exit'
},
"Dream-MachineJobShop": {
property_list: [property_container["processingTime"],
property_container["failures"]
],
_class: 'Dream.MachineJobShop'
},
"Dream-QueueJobShop": {
property_list: [property_container["capacity"],
property_container["isDummy"],
property_container["schedulingRule"]
],
_class: 'Dream.QueueJobShop'
},
"Dream-ExitJobShop": {
_class: 'Dream.ExitJobShop'
},
"Dream-Repairman": {
property_list: [property_container["capacity"]],
_class: 'Dream.Repairman'
},
"Dream-Configuration": {
property_list: [
property_container["simulationClass"],
property_container["numberOfReplications"],
property_container["maxSimTime"],
property_container["confidenceLevel"],
property_container["processTimeout"]
],
_class: 'Dream.Repairman'
}
};
$.ajax(
'/getConfigurationDict', {
success: function (data) {
configuration = $.extend(configuration, data);
console.log(configuration);
dream_instance = Dream(configuration);
dream_instance.start();
$(".tool").draggable({
containment: '#main',
opacity: 0.7,
......@@ -416,11 +235,11 @@
$(window).resize(function () {
dream_instance.redraw();
});
$("#result_zone").hide();
$("#graph_zone").hide();
$("#spreadsheet_output").hide();
$("#gantt_output").hide();
}
});
});
})(jQuery);
import json
from dream.simulation.LineGenerationJSON import main as simulate_line_json
class Simulation:
def __init__(self, logger=None):
self.logger = logger
def run(self, data):
return json.loads(simulate_line_json(input_data=json.dumps(data)))
import json
from dream.simulation.LineGenerationJSON import main as simulate_line_json
schema = {
"entity": {
"id": "entity",
"type": "string",
"_class": "Dream.Property",
"_default": "Part"
},
"mean": {
"id": "mean",
"type": "string",
"_class": "Dream.Property",
"_default": "0.9"
},
"distributionType": {
"id": "distributionType",
"type": "string",
"_class": "Dream.Property",
"_default": "Fixed"
},
"stdev": {
"id": "stdev",
"type": "string",
"_class": "Dream.Property",
"_default": "0.1"
},
"min": {
"id": "min",
"type": "string",
"_class": "Dream.Property",
"_default": "0.1"
},
"max": {
"id": "max",
"type": "string",
"_class": "Dream.Property",
"_default": "1"
},
"failureDistribution": {
"id": "failureDistribution",
"type": "string",
"_class": "Dream.Property",
"_default": "No"
},
"MTTF": {
"id": "MTTF",
"type": "string",
"_class": "Dream.Property",
"_default": "40"
},
"MTTR": {
"id": "MTTR",
"type": "string",
"_class": "Dream.Property",
"_default": "10"
},
"repairman": {
"id": "repairman",
"type": "string",
"_class": "Dream.Property",
"_default": "None"
},
"isDummy": {
"id": "isDummy",
"type": "string",
"_class": "Dream.Property",
"_default": "0"
},
"schedulingRule": {
"id": "schedulingRule",
"type": "string",
"_class": "Dream.Property",
"_default": "FIFO"
},
"capacity": {
"id": "capacity",
"type": "string",
"_class": "Dream.Property",
"_default": "1"
},
"numberOfReplications": {
"id": "numberOfReplications",
"type": "string",
"_class": "Dream.Property",
"_default": "10"
},
"maxSimTime": {
"id": "maxSimTime",
"type": "string",
"_class": "Dream.Property",
"_default": "100"
},
"confidenceLevel": {
"id": "confidenceLevel",
"type": "string",
"_class": "Dream.Property",
"_default": "0.5"
},
"processTimeout": {
"id": "processTimeout",
"type": "string",
"_class": "Dream.Property",
"_default": "0.5"
}
}
schema["interarrivalTime"] = {
"id": "interarrivalTime",
"property_list": [
schema["mean"],
schema["distributionType"]],
"_class": "Dream.PropertyList"
}
schema["processingTime"] = {
"id": "processingTime",
"property_list": [
schema["mean"],
schema["distributionType"],
schema["stdev"],
schema["min"],
schema["max"]
],
"_class": "Dream.PropertyList"
}
schema["failures"] = {
"id": "failures",
"property_list": [
schema["failureDistribution"],
schema["MTTF"],
schema["MTTR"],
schema["repairman"]
],
"_class": "Dream.PropertyList"
}
class Simulation(object):
def __init__(self, logger=None):
self.logger = logger
def getConfigurationDict(self):
"""Returns the possible nodes to use in the graph editor
"""
return {
"Dream-Source": {
"property_list": [
schema["interarrivalTime"],
schema["entity"]
],
"_class": 'Dream.Source'
},
"Dream-Machine": {
"property_list": [
schema["processingTime"],
schema["failures"]
],
"_class": 'Dream.Machine'
},
"Dream-Queue": {
"property_list": [
schema["capacity"],
schema["isDummy"],
schema["schedulingRule"]
],
"_class": 'Dream.Queue'
},
"Dream-Exit": {
"_class": 'Dream.Exit'
},
"Dream-MachineJobShop": {
"property_list": [
schema["processingTime"],
schema["failures"]
],
"_class": 'Dream.MachineJobShop'
},
"Dream-QueueJobShop": {
"property_list": [
schema["capacity"],
schema["isDummy"],
schema["schedulingRule"]
],
"_class": 'Dream.QueueJobShop'
},
"Dream-ExitJobShop": {
"_class": 'Dream.ExitJobShop'
},
"Dream-Repairman": {
"property_list": [schema["capacity"]],
"_class": 'Dream.Repairman'
},
"Dream-Configuration": {
"property_list": [
schema["numberOfReplications"],
schema["maxSimTime"],
schema["confidenceLevel"],
schema["processTimeout"]
],
"_class": 'Dream.Configuration'
},
}
def getOutputIdList(self):
"""Returns the enabled outputs
(the divs ?)
"""
def getInputIdList(self):
"""Returns the enabled inputs
"""
def run(self, data):
return json.loads(simulate_line_json(input_data=json.dumps(data)))
......@@ -4,7 +4,7 @@ import time
import random
import operator
from dream.simulation.Default import Simulation as DefaultSimulation
from dream.simulation.GUI.Default import Simulation as DefaultSimulation
# TODO:
# * this class is not specific to moulding anymore. Reorganize.
......
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment