-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoGen.js
70 lines (60 loc) · 1.54 KB
/
autoGen.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const { allLines } = require("./src/rawInput");
const git = require("./src/git");
const { traverse } = require("./src/graph");
const { Node } = require("./src/Node");
// which lines are connected to this station
/*
{
"A": ["U2","U3"],
"B": ["U1","U2"],
}
*/
let stationToLines = {};
// which stations are connected to this station
/*
{
"A": [Node("B", trainLine)],
"A": [Node("B", trainLine)],
"A": [Node("B", trainLine)],
}
*/
let adj = {};
function preProcess(trainlines) {
function addNewLineToStation(line, station) {
if (!stationToLines[station]) {
stationToLines[station] = [];
}
stationToLines[station].push(line);
}
function addNewAdjStationToStation(fromStation, toStation) {
if (!adj[fromStation.stationName]) {
adj[fromStation.stationName] = [];
}
adj[fromStation.stationName].push(toStation);
}
// making edges
//
Object.values(trainlines).forEach((trainline) => {
const { name } = trainline;
let prevNode = null;
trainline.stations.forEach((station) => {
addNewLineToStation(name, station.name);
let currentNode = new Node(station.name, name, station.imoji);
if (prevNode) {
addNewAdjStationToStation(prevNode, currentNode);
}
prevNode = currentNode;
});
});
}
preProcess(allLines);
git.init();
traverse(
stationToLines,
adj,
Object.values(allLines).map(
(line) => new Node(line.stations[0].name, line.name, line.stations[0].imoji)
)
);
git.pushAllRemote();
console.log(`\x1b[32mGit Network generated Successfully!!\x1b[0m`);