Commit 91474160 authored by Jérome Perrin's avatar Jérome Perrin

GUI: Return the input json for each scenario

Widgets will use this information instead of reading spreadsheet data
parent 814f9bb4
...@@ -230,32 +230,56 @@ ...@@ -230,32 +230,56 @@
$.each(output_data.elementList, function(idx, obj) { $.each(output_data.elementList, function(idx, obj) {
if (obj._class === 'Dream.Job') { if (obj._class === 'Dream.Job') {
var input_job, input_order, job_index = parseInt(obj["id"]); var input_job = null, input_order = null;
// TODO: do not read spreadsheet, use input JSON to get data // find the input order and order component for this job
// ... afterall why ? for (var node_id in input_data.nodes) {
var node = input_data.nodes[node_id];
input_job = input_data.wip_part_spreadsheet[job_index]; if (node.wip) {
// If this line is an order component, find the order. for (var i=0; i<node.wip.length; i++) {
var i = job_index; var order = node.wip[i];
while (input_data.wip_part_spreadsheet[i][0] === null || if (order.id == obj.id) {
input_data.wip_part_spreadsheet[i][0] === "") { input_job = input_order = order;
i = i-1; }
if (input_job === null) {
for (var j=0; j<order.componentsList.length; j++){
var component = order.componentsList[j];
if (component.id == obj.id){
input_order = order;
input_job = component;
}
}
}
} }
input_order = input_data.wip_part_spreadsheet[i]; }
}
var due_date = new Date(simulation_start_date.getTime() +
input_order.dueDate * 1000 * 3600);
$.each(obj['results']['schedule'], function (i, schedule) { $.each(obj['results']['schedule'], function (i, schedule) {
var entrance_date = new Date(simulation_start_date.getTime() + var entrance_date = new Date(simulation_start_date.getTime() +
// TODO: time unit // TODO: time unit
schedule['entranceTime'] * 1000 * 3600); schedule['entranceTime'] * 1000 * 3600);
var duration = 0;
// Duration is calculated by difference of entranceTime of this
// step and entranceTime of the next step, or completionTime when
// this is the last step
if (i+1 == obj['results']['schedule'].length) {
duration = obj['results']['completionTime'] - schedule['entranceTime'];
} else {
duration = obj['results']['schedule'][i+1]['entranceTime'] - schedule['entranceTime'];
}
spreadsheet_data.push([ spreadsheet_data.push([
input_order[0] + "-" + input_job[4], // XXX this label is incorrect for design step, during design
// phase we still have an order and not an order component.
input_order.name + "-" + input_job.name,
obj['id'], obj['id'],
input_order[3], // operator input_order.manager,
input_order[1], // dueDate moment(due_date).format("YYYY/MM/DD"),
input_order[2], // priority input_order.priority,
moment(entrance_date).format("MMM/DD HH:mm"), moment(entrance_date).format("MMM/DD HH:mm"),
input_job[7].split('-')[i] || 0, // processing time duration,
schedule['stationId'], schedule['stationId'],
i i
]); ]);
...@@ -356,22 +380,34 @@ ...@@ -356,22 +380,34 @@
if (obj._class === 'Dream.Job') { if (obj._class === 'Dream.Job') {
// find the corresponding input // find the corresponding input
var input_job, input_order; var input_job = null, input_order = null;
var job_index = parseInt(obj["id"]); // find the input order and order component for this job
// TODO: do not read spreadsheet, use input JSON to get data for (var node_id in input_data.nodes) {
input_job = input_data.wip_part_spreadsheet[job_index]; var node = input_data.nodes[node_id];
var i = job_index; if (node.wip) {
while (input_data.wip_part_spreadsheet[i][0] === null || for (var i=0; i<node.wip.length; i++) {
input_data.wip_part_spreadsheet[i][0] === "") { var order = node.wip[i];
i = i-1; if (order.id == obj.id) {
input_job = input_order = order;
}
if (input_job === null) {
for (var j=0; j<order.componentsList.length; j++){
var component = order.componentsList[j];
if (component.id == obj.id){
input_order = order;
input_job = component;
}
}
}
}
}
} }
input_order = input_data.wip_part_spreadsheet[i];
var duration = 0; var duration = 0;
if (input_job == input_order) { // if we are on the order definition if (input_job == input_order) { // if we are on the order definition
gantt_data.data.push({ gantt_data.data.push({
id: input_order[0], id: input_order.id,
text: input_order[0], text: input_order.name,
project: 1, project: 1,
open: false, open: false,
parent: "by_order" parent: "by_order"
...@@ -395,24 +431,26 @@ ...@@ -395,24 +431,26 @@
// task_start_date.setDate(task_start_date.getDate() + schedule['entranceTime']); // task_start_date.setDate(task_start_date.getDate() + schedule['entranceTime']);
// for simulation time unit as days hours // for simulation time unit as days hours
task_start_date.setTime(task_start_date.getTime() + schedule['entranceTime']*1000*3600); task_start_date.setTime(task_start_date.getTime() + schedule['entranceTime']*1000*3600);
if (seen_parts[input_job[4] + "." + input_order[0]] === undefined){
var job_full_id = input_job.id + "." + input_order.id;
if (seen_parts[job_full_id] === undefined){
gantt_data.data.push({ gantt_data.data.push({
id: input_job[4] + "." + input_order[0], id: job_full_id,
text: input_job[4], text: input_job.name,
parent: input_order[0] parent: input_order.id
}); });
seen_parts[input_job[4] + "." + input_order[0]] = 1; seen_parts[job_full_id] = 1;
} }
gantt_data.data.push({ gantt_data.data.push({
id: input_order[0] + '.' + idx + '_' + i, id: input_order.id + '.' + idx + '_' + i,
text: schedule['stationId'], text: schedule['stationId'],
start_date: task_start_date, start_date: task_start_date,
duration: duration, duration: duration,
parent: input_job[4] + "." + input_order[0] parent: job_full_id
}); });
gantt_data.data.push({ gantt_data.data.push({
id: 'job.' + obj['id'] + '.' + idx + '_' + i, id: 'job.' + obj['id'] + '.' + idx + '_' + i,
text: input_order[0] + "-" + input_job[4], text: input_order.name + "-" + input_job.name,
start_date: task_start_date, start_date: task_start_date,
duration: duration, duration: duration,
parent: schedule['stationId'], parent: schedule['stationId'],
...@@ -766,10 +804,9 @@ ...@@ -766,10 +804,9 @@
}); });
}; };
that.displayResult = function (idx) { that.displayResult = function (idx, result) {
var active_tab = $("#reports").data("ui-tabs") ? var active_tab = $("#reports").data("ui-tabs") ?
$("#reports").tabs("option", "active") : 0; // XXX should not be 0, but the first enabled one $("#reports").tabs("option", "active") : 0; // XXX should not be 0, but the first enabled one
var result = JSON.parse($("#json_result").val())[idx]['result'];
$('li.result').removeClass('active'); $('li.result').removeClass('active');
$($('li.result')[idx]).addClass('active'); $($('li.result')[idx]).addClass('active');
...@@ -795,7 +832,8 @@ ...@@ -795,7 +832,8 @@
} }
} }
var input = that.getData(); // XXX how to get input json ? var input = result.input;
result = result.result;
// display each of the enabled widget // display each of the enabled widget
if (configuration['Dream-Configuration'].gui.station_utilisation_graph){ if (configuration['Dream-Configuration'].gui.station_utilisation_graph){
......
...@@ -188,15 +188,15 @@ ...@@ -188,15 +188,15 @@
if (data['success']) { if (data['success']) {
$("#json_result").val(JSON.stringify(data.data, undefined, " ")); $("#json_result").val(JSON.stringify(data.data, undefined, " "));
$.each(data['success'], function (idx, obj) { $.each(data.data, function (idx, result) {
$('#result_list').append('<li class="result"></li>'); $('#result_list').append('<li class="result"></li>');
$('#result_list').children().last().text(idx + ' : ' + obj['score'] + ' ' + obj['key']).click( $('#result_list').children().last().text(idx + ' : ' + result['score'] + ' ' + result['key']).click(
function (e) { function (e) {
dream_instance.displayResult(idx); dream_instance.displayResult(idx, result)
} }
); );
}); });
dream_instance.displayResult(0); dream_instance.displayResult(0, data.data[0]);
} else { } else {
$("#reports").hide(); $("#reports").hide();
$("#error").text(data["error"]).show().effect('shake', 50); $("#error").text(data["error"]).show().effect('shake', 50);
......
...@@ -104,6 +104,7 @@ class Simulation(DefaultSimulation): ...@@ -104,6 +104,7 @@ class Simulation(DefaultSimulation):
# TODO: those two steps have to be parallelized # TODO: those two steps have to be parallelized
ant['result'] = DefaultSimulation.runOneScenario(self, ant_data) ant['result'] = DefaultSimulation.runOneScenario(self, ant_data)
ant['input'] = ant_data
ant['score'] = self._calculateAntScore(ant) ant['score'] = self._calculateAntScore(ant)
# remove ants that outputs the same schedules # remove ants that outputs the same schedules
......
...@@ -357,8 +357,7 @@ class Simulation(object): ...@@ -357,8 +357,7 @@ class Simulation(object):
"""Run one scenario. """Run one scenario.
To be reused by subclasses. To be reused by subclasses.
""" """
return json.loads(simulate_line_json( return json.loads(simulate_line_json(input_data=json.dumps(data)))
input_data=json.dumps(self._preprocess(data))))
def _preprocess(self, data): def _preprocess(self, data):
"""Preprocess the data, for instance reading spreadsheet. """Preprocess the data, for instance reading spreadsheet.
...@@ -381,6 +380,8 @@ class Simulation(object): ...@@ -381,6 +380,8 @@ class Simulation(object):
def run(self, data): def run(self, data):
"""Run simulation and return result to the GUI. """Run simulation and return result to the GUI.
""" """
prepocessed_data = self._preprocess(data)
return [{"key": "default", return [{"key": "default",
"score": 0, "score": 0,
"result": self.runOneScenario(data)}] "result": self.runOneScenario(prepocessed_data),
"input": prepocessed_data}]
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