-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (43 loc) · 1.41 KB
/
app.js
File metadata and controls
47 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const lineReader = require('linebyline');
const Node = require('./node');
const Edge = require('./edge');
const Graph = require('./graph');
const helper = require('./helper');
const edges = [];
const cables = [];
let graph = new Graph();
let root = new Node('root', 'central');
graph.addNode(root);
lr = lineReader('./cable_table.csv');
lr.on('line', (line, lineCount) => {
if (lineCount > 1) {
let cableInfo = line.split(',');
let source = new Node(cableInfo[2], cableInfo[3]);
let target = new Node(cableInfo[4], cableInfo[5]);
let edge = new Edge(cableInfo[0], cableInfo[1], source.id, target.id);
edges.push(edge);
// cable object used to find root nodes that should be replaced by the real root (central)
let cable = {
id: cableInfo[0],
length: cableInfo[1],
startNodeId: cableInfo[2],
startNodeType: cableInfo[3],
endNodeId: cableInfo[4],
endNodeType: cableInfo[5]
};
cables.push(cable);
}
})
.on('close', () => {
// helper function for finding the nodes that should be replaced by central root
// and insert nodes and edges to the graph
helper.findRootNodes(root, edges, cables, graph);
let topology = {
nodes: graph.getNodes(),
edges: graph.getEdges()
};
console.log(topology);
})
.on('error', (err) => {
console.log(err.message);
});