enable input of entire pnp csv file

This commit is contained in:
Morgan 'ARR\!' Allen 2017-04-09 20:28:23 -07:00
parent 87a00b0ef9
commit 817ef57379
4 changed files with 72 additions and 29 deletions

View file

@ -4,26 +4,66 @@ var fs = require("fs");
var through = require("through2");
module.exports = function(input, output, feedFile, opts) {
var data = "";
async.waterfall([function(next) {
var feeds = {};
var buf = "";
fs.createReadStream(feedFile).pipe(csv())
.on("data", function(data){
feeds[data[6]] = {
x: data[3],
y: data[4],
feed: data[5],
slot: data[2]
var section = -1;
var sections = [[], [], [], []];
console.log("processing sections");
fs.createReadStream(feedFile)
.on("data", function(data) {
buf += data.toString();
var lines = buf.split("\n");
buf = lines.pop();
for(var i = 0; i < lines.length; i++) {
let line = lines[i].replace(/[\r\n]+$/, "");
if(line.length === 0) continue;
if(line.slice(0, 2) === "%,") {
section++;
continue;
}
if(section === -1) { // input can be either just the CSV section or the entire pnp file
sections[1].push(line);
} else {
sections[section].push(line);
}
}
})
.on("end", function() {
next(null, feeds)
});
.on("end", function() {
next(null, sections);
})
}, function(sections, next) {
console.log("associating parts");
var components = [];
var len = sections[1].length;
for(var i = 0; i < len; i++) {
let section = sections[1][i].split(",");
components[section[6]] = {
x: section[3],
y: section[4],
feed: section[5],
slot: section[2]
}
}
next(null, components);
}, function(feeds, next) {
var rs = fs.createReadStream(input);
var ws = fs.createWriteStream(output);
var wsCsv = csv.createWriteStream();
var data = "";
var seq = 0;
var tr = through.obj(function(chunk, enc, done) {
@ -50,14 +90,13 @@ module.exports = function(input, output, feedFile, opts) {
var feed = feeds[p];
this.push([ 0, seq++, feed.slot, x, y, r ]);
this.push([ 0, seq++, feed.slot, x, y, r ].join(",") + "\n");
};
done();
});
rs.pipe(tr);
tr.pipe(wsCsv);
wsCsv.pipe(ws);
tr.pipe(ws);
}]);
}

View file

@ -1,5 +1,12 @@
65535,1,1,0.00,0.00,4.00,2.2n
65535,1,2,0.00,0.00,4.00,10uF
65535,1,3,-0.25,0.00,4.00,10nF
65545,1,4,-0.25,0.00,4.00,100nF
65535,1,5,-0.25,0.00,4.00,27nF
%,section 1
65535,0,0.00,0.00
%,section 2
65535,1,1,0.00,0.00,4.00,100nF,
65535,1,3,-0.25,0.00,4.00,0.1uF,
%,section 3
65535,3,0.00,0.00,
%,section 4
0,1,3,102.73,27.88,90,0.50,0,100,,,

1 65535 %,section 1 1 1 0.00 0.00 4.00 2.2n
2 65535 65535,0,0.00,0.00 1 2 0.00 0.00 4.00 10uF
3 65535 %,section 2 1 3 -0.25 0.00 4.00 10nF
4 65545 65535,1,1,0.00,0.00,4.00,100nF, 1 4 -0.25 0.00 4.00 100nF
5 65535 65535,1,3,-0.25,0.00,4.00,0.1uF, 1 5 -0.25 0.00 4.00 27nF
6 %,section 3
7 65535,3,0.00,0.00,
8 %,section 4
9 0,1,3,102.73,27.88,90,0.50,0,100,,,
10
11
12

View file

@ -1,9 +1,6 @@
0,0,1,248.2850,-101.2190,0.0000
0,1,3,237.9000,-99.6500,270.0000
0,2,4,237.8710,-103.0732,270.0000
0,3,4,213.8680,-99.4156,270.0000
0,4,2,238.7600,-106.2990,180.0000
0,5,2,228.6000,-76.6572,0.0000
0,6,3,228.1961,-58.5445,270.0000
0,7,2,218.4908,-51.4071,225.0000
0,8,2,217.2284,-50.6171,250.0000
0,0,1,237.8710,-103.0732,270.0000
0,1,1,213.8680,-99.4156,270.0000
0,2,3,219.3061,-52.4408,210.0000
0,3,3,219.9640,-55.0062,180.0000
0,4,3,223.6470,-55.5840,90.0000
0,5,3,214.8840,-60.2615,90.0000

1 0 0 1 248.2850 237.8710 -101.2190 -103.0732 0.0000 270.0000
2 0 1 3 1 237.9000 213.8680 -99.6500 -99.4156 270.0000 270.0000
3 0 2 4 3 237.8710 219.3061 -103.0732 -52.4408 270.0000 210.0000
4 0 3 4 3 213.8680 219.9640 -99.4156 -55.0062 270.0000 180.0000
5 0 4 2 3 238.7600 223.6470 -106.2990 -55.5840 180.0000 90.0000
6 0 5 2 3 228.6000 214.8840 -76.6572 -60.2615 0.0000 90.0000
0 6 3 228.1961 -58.5445 270.0000
0 7 2 218.4908 -51.4071 225.0000
0 8 2 217.2284 -50.6171 250.0000

View file

@ -22,7 +22,7 @@ cp.stderr.on("data", function(d) {
cp.on("close", function() {
test(function(t) {
t.deepEqual(fs.readFileSync(output), fs.readFileSync(fixture), "output correct");
t.deepEqual(fs.readFileSync(output).toString(), fs.readFileSync(fixture).toString(), "output correct");
t.end();
});