Commit 5022baef authored by Jérome Perrin's avatar Jérome Perrin

draw moving entities

parent ee443529
...@@ -277,32 +277,98 @@ ...@@ -277,32 +277,98 @@
} }
}); });
// XXX create socket on click ?
var webSocket = new WebSocket("ws://localhost:5000/api");
webSocket.onmessage = function(e) {
var message = JSON.parse(e.data)
$.each(message.update_gui || [], function(i, msg){ // display entities in a station
if (msg.action === "update_queue_stat"){ function displayEntities(element_id, node_id) {
dream_instance.updateElementData(msg.node, var node = $("#" + element_id);
{status: msg.capacity}); var node_position = node.position();
var entities = $(".in_" + node_id);
var offset = 0;
if (entities.length > 4) {
entities.hide();
dream_instance.updateElementData(node_id,
{status: entities.length});
}
entities.each(
function (idx, entity) {
entity = $(entity)
entity.css({top: node_position.top +
node.height() -
(idx * entity.height()) -
(entity.height() / 2),
left: node_position.left +
node.width() -
entity.width()})
} }
if (msg.action === "update_machine_status"){ )
dream_instance.updateElementData(msg.node, }
{status: msg.status});
// move an entity from source to destination
function moveEntity(message, queue) {
var size = 20 * dream_instance.getData().preference.zoom_level;
var entity = $("#" + message.entity);
var source = dream_instance.getElementId(message.source);
var destination = dream_instance.getElementId(message.destination);
// XXX do we need a getElementId for edges ? for entities ?
var edge = $("#" + message.edge);
var win_offset = $('#main').offset()
var path = edge.find("path")[1]
var offset = edge.find("path:nth(1)").offset();
var path_length = path.getTotalLength()
var percent = 100;
if (!entity.length) {
var d= $("<div class='entity' id='" + message.entity + "'>"
+ message.entity + "</div>").css(
{"width": size,
"height": size,
"position": "absolute",
"border-radius": size / 2,
"background": "red"} // TODO: random color ?
).appendTo($("#main"));
entity = $("#" + message.entity);
} }
});
if (message['now']) {
$("#now").text(message['now']);
}
if (message['success']) { // XXX at this point the entity does not have the class yet
entity.removeClass("in_"+ message.source)
displayEntities(source, message.source);
$("#now").text(message.time.toFixed(2));
var timer;
( function calc() {
percent -= Math.min(dream_instance.getData().general.animationSpeed, 100);
if (percent < 0) {
percent = 0;
}
timer = setTimeout(calc, 10)
var point = path.getPointAtLength(percent*path_length/100);
var c = { 'z-index':100,
position:"absolute",
top:(offset.top + point.y - win_offset.top) + "px",
left:(offset.left + point.x - win_offset.left) + "px" }
entity.css(c)
if (percent == 0){
clearTimeout(timer)
$(queue).dequeue()
entity.removeClass("in_"+ message.source)
entity.addClass("in_"+ message.destination)
displayEntities(source, message.source);
displayEntities(destination, message.destination);
}
})()
}
function notifyEndSimulation(message){
$("#json_result").val(JSON.stringify(message['success'], $("#json_result").val(JSON.stringify(message['success'],
undefined, " ")); undefined, " "));
$("#loading_spinner").hide(); $("#loading_spinner").hide();
$("#run_simulation").button('enable'); $("#run_simulation").button('enable');
$("#result_zone").show(); $("#result_zone").show();
$(".entity").remove();
$('#result_list').empty(); $('#result_list').empty();
$('.window > .status').remove(); $('.window > .status').remove();
$.each(message['success'], function (idx, obj) { $.each(message['success'], function (idx, obj) {
...@@ -316,12 +382,31 @@ ...@@ -316,12 +382,31 @@
}); });
dream_instance.displayResult(0); dream_instance.displayResult(0);
} }
}
function onWebSocketMessage(e) {
var message = JSON.parse(e.data)
if (message.action === "move_entity"){
$("#main").queue(function() {
moveEntity(message, this);
})
}
if (message['success']) {
$("#main").queue(function() {
notifyEndSimulation(message, this);
})
}
};
var webSocket = new WebSocket("ws://localhost:5000/api");
// TODO reorganise
$("#run_simulation").button().on('click', function(e) { $("#run_simulation").button().on('click', function(e) {
// TODO: we need to update global properties dream_instance.readGeneralPropertiesDialog()
$("#loading_spinner").show(); $("#loading_spinner").show();
$("#run_simulation").button('disable'); $("#run_simulation").button('disable');
webSocket.onmessage = onWebSocketMessage
var msg = JSON.stringify(dream_instance.getData()); var msg = JSON.stringify(dream_instance.getData());
webSocket.send(msg); webSocket.send(msg);
return false; return false;
......
{ {
"edges": { "edges": {
"con_10": [ "con_10": [
"M2",
"E1",
{}
],
"con_15": [
"S1", "S1",
"M1", "M1",
{} {}
], ],
"con_20": [ "con_15": [
"Q1", "Q1",
"M3", "M3",
{} {}
], ],
"con_25": [ "con_20": [
"M3", "M3",
"Q2", "Q2",
{} {}
], ],
"con_30": [ "con_25": [
"Q2", "Q2",
"M2", "M2",
{} {}
], ],
"con_5": [ "con_30": [
"M1", "M1",
"Q1", "Q1",
{} {}
],
"con_5": [
"M2",
"E1",
{}
] ]
}, },
"general": { "general": {
"animationSpeed": 15,
"confidenceLevel": 0.5, "confidenceLevel": 0.5,
"currentDate": "2014/03/01", "currentDate": "2014/03/01",
"maxSimTime": 200, "ke_url": "http://git.erp5.org/gitweb/dream.git/blob_plain/HEAD:/dream/KnowledgeExtraction/Mockup_ProcessingTimes.xls",
"maxSimTime": 30,
"numberOfReplications": 1, "numberOfReplications": 1,
"processTimeout": 10, "processTimeout": 10,
"seed": "",
"trace": "Yes" "trace": "Yes"
}, },
"nodes": { "nodes": {
...@@ -53,7 +56,6 @@ ...@@ -53,7 +56,6 @@
"failureDistribution": "No", "failureDistribution": "No",
"repairman": "None" "repairman": "None"
}, },
"name": "M1: working",
"processingTime": { "processingTime": {
"distributionType": "Normal", "distributionType": "Normal",
"max": 3.9, "max": 3.9,
...@@ -71,7 +73,6 @@ ...@@ -71,7 +73,6 @@
"failureDistribution": "No", "failureDistribution": "No",
"repairman": "None" "repairman": "None"
}, },
"name": "M2: working",
"processingTime": { "processingTime": {
"distributionType": "Normal", "distributionType": "Normal",
"max": 3, "max": 3,
...@@ -82,14 +83,13 @@ ...@@ -82,14 +83,13 @@
}, },
"M3": { "M3": {
"_class": "Dream.Machine", "_class": "Dream.Machine",
"element_id": "DreamNode_8", "element_id": "DreamNode_4",
"failures": { "failures": {
"MTTF": 40, "MTTF": 40,
"MTTR": 10, "MTTR": 10,
"failureDistribution": "No", "failureDistribution": "No",
"repairman": "None" "repairman": "None"
}, },
"name": "M3: working",
"processingTime": { "processingTime": {
"distributionType": "Normal", "distributionType": "Normal",
"max": 4, "max": 4,
...@@ -101,27 +101,22 @@ ...@@ -101,27 +101,22 @@
"Q1": { "Q1": {
"_class": "Dream.Queue", "_class": "Dream.Queue",
"capacity": 100, "capacity": 100,
"element_id": "DreamNode_4", "element_id": "DreamNode_5",
"isDummy": "0",
"name": "Q1: 3",
"schedulingRule": "FIFO" "schedulingRule": "FIFO"
}, },
"Q2": { "Q2": {
"_class": "Dream.Queue", "_class": "Dream.Queue",
"capacity": 130, "capacity": 130,
"element_id": "DreamNode_7", "element_id": "DreamNode_6",
"isDummy": "0",
"name": "Q2: 4",
"schedulingRule": "FIFO" "schedulingRule": "FIFO"
}, },
"QS1": { "QS1": {
"_class": "Dream.EventGenerator", "_class": "Dream.EventGenerator",
"argumentDict": "{}", "argumentDict": "{}",
"duration": 10, "duration": 10,
"element_id": "DreamNode_5", "element_id": "DreamNode_7",
"interval": 10, "interval": 10,
"method": "Globals.countQueueMetrics", "method": "Globals.countQueueMetrics",
"name": "Queue Statistics",
"start": 1, "start": 1,
"stop": -1 "stop": -1
}, },
...@@ -129,22 +124,20 @@ ...@@ -129,22 +124,20 @@
"_class": "Dream.EventGenerator", "_class": "Dream.EventGenerator",
"argumentDict": "{}", "argumentDict": "{}",
"duration": 10, "duration": 10,
"element_id": "DreamNode_9", "element_id": "DreamNode_8",
"interval": 1, "interval": 1,
"method": "Globals.updateGui", "method": "Globals.updateGui",
"name": "Queue Statistics",
"start": 1, "start": 1,
"stop": -1 "stop": -1
}, },
"S1": { "S1": {
"_class": "Dream.Source", "_class": "Dream.Source",
"element_id": "DreamNode_6", "element_id": "DreamNode_9",
"entity": "Dream.Part", "entity": "Dream.Part",
"interarrivalTime": { "interarrivalTime": {
"distributionType": "Fixed", "distributionType": "Fixed",
"mean": 0.3 "mean": 0.3
}, }
"name": "S1"
} }
}, },
"preference": { "preference": {
...@@ -178,15 +171,15 @@ ...@@ -178,15 +171,15 @@
"top": 0.85818653664461 "top": 0.85818653664461
}, },
"QS2": { "QS2": {
"left": 0.9756195021428015, "left": 0.9755049855975303,
"top": 0.2783826573008243 "top": 0.277996584331602
}, },
"S1": { "S1": {
"left": 0.053173574761337515, "left": 0.053173574761337515,
"top": 0.10367354133961731 "top": 0.10367354133961731
} }
}, },
"zoom_level": 1.1111 "zoom_level": 0.8999280025199498
}, },
"shift_spreadsheet": [ "shift_spreadsheet": [
[ [
......
...@@ -161,6 +161,14 @@ schema = { ...@@ -161,6 +161,14 @@ schema = {
"_default": "_default":
"http://git.erp5.org/gitweb/dream.git/blob_plain/HEAD:/dream/KnowledgeExtraction/Mockup_Processingtimes.xls", "http://git.erp5.org/gitweb/dream.git/blob_plain/HEAD:/dream/KnowledgeExtraction/Mockup_Processingtimes.xls",
}, },
"animationSpeed": {
"id": "animationSpeed",
"type": "number",
"name": "Animation Speed",
"description": "Speed of animation (0..100)",
"_class": "Dream.Property",
"_default": 5,
},
"batchNumberOfUnits": { "batchNumberOfUnits": {
"id": "batchNumberOfUnits", "id": "batchNumberOfUnits",
"type": "number", "type": "number",
...@@ -336,6 +344,7 @@ class Simulation(object): ...@@ -336,6 +344,7 @@ class Simulation(object):
schema["trace"], schema["trace"],
schema["seed"], schema["seed"],
schema["ke_url"], schema["ke_url"],
schema["animationSpeed"],
], ],
"gui": { "gui": {
'debug_json': 1, 'debug_json': 1,
......
...@@ -271,30 +271,7 @@ def getConfidenceIntervals(value_list): ...@@ -271,30 +271,7 @@ def getConfidenceIntervals(value_list):
'ub': ub, 'ub': ub,
'avg': numpy.mean(value_list) } 'avg': numpy.mean(value_list) }
from Queue import Queue
from Machine import Machine
def updateGui(argumentDict={}):
message_list = []
for obj in G.ObjList:
if isinstance(obj, Queue):
message_list.append({'node': obj.id,
'action': 'update_queue_stat',
'capacity': len(obj.Res.activeQ),
})
if isinstance(obj, Machine):
message_list.append({'node': obj.id,
'action': 'update_machine_status',
'debug': repr(obj.Res.activeQ),
'status': obj.status,
})
import Globals
Globals.ws.send(json.dumps({'update_gui': message_list, 'now': now()}))
import time
time.sleep(0.08)
def send(msg): def send(msg):
import Globals import Globals
Globals.ws.send(json.dumps(msg)) Globals.ws.send(json.dumps(msg))
import time
time.sleep(0.02)
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