Commit f6919c2a authored by Sebastien Robin's avatar Sebastien Robin

working display of througput recalculation, only issue with last box

parent 06a0511e
......@@ -3,7 +3,9 @@ from flask import request
from crossdomain import crossdomain
from util import deunicodeData
app = Flask(__name__)
global model
global data
data = {'model': None,
'simulation_parameters': {}}
@app.route("/")
def welcome():
......@@ -31,12 +33,11 @@ def someTest():
@app.route("/setModel", methods=["POST", "OPTIONS"])
@crossdomain(origin='*')
def setModel():
global model
app.logger.debug('setModel')
app.logger.debug("request.json: %r" % (request.json,))
#model = deunicodeData(request.json)
model = request.json
app.logger.debug("model: %r" % (model,))
data['model'] = request.json
app.logger.debug("model: %r" % (data['model'],))
return "ok"
@app.route("/setSimulationParameters", methods=["POST", "OPTIONS"])
......@@ -45,11 +46,18 @@ def setSimulationParameters():
app.logger.debug('setSimulationParameters')
parameter_dict = request.json
app.logger.debug("parameter_dict: %r" % (parameter_dict,))
data['simulation_parameters']['available_people'] = parameter_dict
return "ok"
def _simulate():
# Well, it's only dummy code now, but we will have to think about
# running simulation later
box_to_enable_list = [1, 2, 3, 7, 8, 9]
available_people_list = [x for x in parameter_dict if parameter_dict[x]]
people_dict = data['simulation_parameters'].get('available_people', {})
available_people_list = [x for x in people_dict if people_dict[x]]
to_enable = len(available_people_list) >= 6
throughput = None
for box in model["box_list"]:
for box in data['model']["box_list"]:
box["worker"] = None
box["enabled"] = False
if int(box["id"][len("window"):]) in box_to_enable_list:
......@@ -59,17 +67,17 @@ def setSimulationParameters():
if throughput is None:
throughput = box["throughput"]
throughput = min(throughput, box["throughput"])
app.logger.debug('box and throughput : %r, %r' % (box, throughput))
if throughput is None:
throughput = 0
model["throughput"] = throughput
return "ok"
data['model']["throughput"] = throughput
@app.route("/getModel", methods=["GET", "OPTIONS"])
@crossdomain(origin='*')
def getModel():
global model
app.logger.debug('getModel')
return jsonify(model)
_simulate()
return jsonify(data['model'])
if __name__ == "__main__":
main()
......@@ -63,6 +63,8 @@
};
priv.initDialog = function() {
// code to allow changing values on connections. For now we assume
// that it is throughput. But we will need more generic code
var throughput = $( "#throughput" ),
allFields = $( [] ).add( throughput ),
tips = $( ".validateTips" );
......@@ -104,7 +106,7 @@
modal: true,
buttons: {
"Validate": function() {
var bValid = true;
var bValid = true, i, i_length, box;
allFields.removeClass( "ui-state-error" );
console.log("going to check troughput val", throughput.val());
......@@ -113,7 +115,15 @@
if ( bValid ) {
console.log("new value is ok...", throughput.val());
console.log("dialog_connection", priv.dialog_connection);
// Update the model with new value
i_length = model.box_list.length;
for (i = 0; i < i_length; i++) {
box = model.box_list[i];
if (box.id === priv.dialog_connection.sourceId) {
box.throughput = parseInt(throughput.val(), 10);
}
}
priv.setModel();
$( this ).dialog( "close" );
}
},
......
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