Commit 29169e13 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

use the new format in internal data too.

parent a696a08b
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
$("#dialog-fieldset").children().remove(); $("#dialog-fieldset").children().remove();
var element_id_prefix = element_id.split("_")[0]; var element_id_prefix = element_id.split("_")[0];
var property_list = configuration[element_id_prefix].property_list || []; var property_list = configuration[element_id_prefix].property_list || [];
var previous_data = that.getData()["element"]; var previous_data = that.getData()["nodes"];
var element_name = previous_data[element_id]['name'] || element_id; var element_name = previous_data[element_id]['name'] || element_id;
fieldset.append( fieldset.append(
...@@ -241,28 +241,25 @@ ...@@ -241,28 +241,25 @@
priv.formatForManpy = function (data) { priv.formatForManpy = function (data) {
var manpy_dict = {}, nodes = {}, edges = {}, edge_id = 0; var manpy_dict = {}, nodes = {}, edges = {}, edge_id = 0;
$.each(data['element'], function (idx, element) { $.each(data['nodes'], function (idx, node) {
var clone_element = {}; var clone_node = {};
/* clone the element and put content of 'data' at the top level. */ /* clone the node and put content of 'data' at the top level. */
$.each(element, function (k, v) { $.each(node, function (k, v) {
if (k == 'data') { if (k == 'data') {
$.each(v, function (kk, vv) { $.each(v, function (kk, vv) {
clone_element[kk] = vv; clone_node[kk] = vv;
});
} else if (k == 'successorList') {
$.each(v, function (i, successor) {
edges[edge_id] = [clone_element['id'], successor, {}];
edge_id += 1;
}); });
} else if (k == 'id') {
true; // no need to output
} else { } else {
clone_element[k] = v; clone_node[k] = v;
} }
}); });
nodes[clone_element['id']] = clone_element; nodes[node['id']] = clone_node;
}); });
manpy_dict['nodes'] = nodes; manpy_dict['nodes'] = nodes;
manpy_dict['edges'] = edges; manpy_dict['edges'] = data['edges'];
manpy_dict['general'] = data['general']; manpy_dict['general'] = data['general'];
return manpy_dict; return manpy_dict;
}; };
......
...@@ -239,32 +239,31 @@ ...@@ -239,32 +239,31 @@
}, function (err, response) { }, function (err, response) {
if (response !== undefined && response.data !== undefined) { if (response !== undefined && response.data !== undefined) {
// Add all elements // Add all elements
$.each(response.data.element, function (key, value) { $.each(response.data.nodes, function (key, value) {
var preference_data = response.data.preference !== undefined ? var preference_data = response.data.preference !== undefined ?
response.data.preference[value.id] : {}; response.data.preference[key] : {};
$.each(preference_data, function (preference_key, $.each(preference_data, function (preference_key,
preference_value) { preference_value) {
value[preference_key] = preference_value; value[preference_key] = preference_value;
}); });
dream_instance.newElement(value); dream_instance.newElement(value);
dream_instance.updateElementData(value.id, { dream_instance.updateElementData(key, {
data: value.data || {} data: value.data || {}
}); });
}); });
$.each(response.data.edges, function (key, value) {
dream_instance.connect(value[0], value[1]);
});
// Now link elements between them and update id_container // Now update id_container
$.each(response.data.element, function (key, value) { $.each(response.data.nodes, function (key, value) {
var element_id = value.id, var element_id = value.id,
prefix, suffix, splitted_element_id, prefix, suffix, splitted_element_id;
successor_list = value.successorList || [];
splitted_element_id = element_id.split("_"); splitted_element_id = element_id.split("_");
prefix = splitted_element_id[0]; prefix = splitted_element_id[0];
suffix = splitted_element_id[1]; suffix = splitted_element_id[1];
id_container[prefix] = Math.max((id_container[prefix] || 0), id_container[prefix] = Math.max((id_container[prefix] || 0),
parseInt(suffix, 10)); parseInt(suffix, 10));
$.each(successor_list, function (idx, successor_value) {
dream_instance.connect(value.id, successor_value);
});
}); });
dream_instance.setGeneralProperties(response.data.general); dream_instance.setGeneralProperties(response.data.general);
dream_instance.initGeneralProperties(); // XXX dream_instance.initGeneralProperties(); // XXX
...@@ -305,19 +304,27 @@ ...@@ -305,19 +304,27 @@
if (obj.results.working_ratio !== undefined) { if (obj.results.working_ratio !== undefined) {
/* when there is only one replication, the ratio is given as a float, /* when there is only one replication, the ratio is given as a float,
otherwise we have a mapping avg, min max */ otherwise we have a mapping avg, min max */
blockage_data.push([counter, obj.results.blockage_ratio if (obj.results.blockage_ratio !== undefined) {
.avg || obj.results.blockage_ratio blockage_data.push([counter, obj.results.blockage_ratio
]); .avg || obj.results.blockage_ratio
]);
} else {
blockage_data.push([counter, 0.0]);
}
waiting_data.push([counter, obj.results.waiting_ratio.avg || waiting_data.push([counter, obj.results.waiting_ratio.avg ||
obj.results.waiting_ratio obj.results.waiting_ratio
]); ]);
failure_data.push([counter, obj.results.failure_ratio.avg || if (obj.results.failure_ratio !== undefined) {
obj.results.failure_ratio failure_data.push([counter, obj.results.failure_ratio
]); .avg || obj.results.failure_ratio
]);
} else {
failure_data.push([counter, 0.0]);
}
working_data.push([counter, obj.results.working_ratio.avg || working_data.push([counter, obj.results.working_ratio.avg ||
obj.results.working_ratio obj.results.working_ratio
]); ]);
ticks.push([counter, dream_instance.getData().element[ ticks.push([counter, dream_instance.getData().nodes[
obj.id].name || obj.id]); obj.id].name || obj.id]);
counter++; counter++;
} }
......
...@@ -91,14 +91,14 @@ ...@@ -91,14 +91,14 @@
}); });
var updateConnectionData = function (connection, remove) { var updateConnectionData = function (connection, remove) {
var source_element;
source_element = priv.node_container[connection.sourceId];
source_element.successorList = source_element.successorList || [];
if (remove) { if (remove) {
source_element.successorList.splice(source_element.successorList.indexOf( delete(priv.edge_container[connection.id]);
connection.targetId));
} else { } else {
source_element.successorList.push(connection.targetId); priv.edge_container[connection.id] = [
connection.sourceId,
connection.targetId,
{}
];
} }
priv.onDataChange(); priv.onDataChange();
}; };
...@@ -176,7 +176,8 @@ ...@@ -176,7 +176,8 @@
priv.getData = function () { priv.getData = function () {
return { return {
"element": priv.node_container, "nodes": priv.node_container,
"edges": priv.edge_container,
"preference": priv.preference_container, "preference": priv.preference_container,
"general": priv.general_container "general": priv.general_container
}; };
...@@ -200,6 +201,7 @@ ...@@ -200,6 +201,7 @@
that.start = function () { that.start = function () {
priv.node_container = {}; priv.node_container = {};
priv.edge_container = {};
priv.preference_container = {}; priv.preference_container = {};
priv.general_container = {}; priv.general_container = {};
priv.initJsPlumb(); priv.initJsPlumb();
......
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