Therefore, each section is graded with a pass /fail. All of this information is organized into a hierarchical structure of many beadChips with many Sections with many section values.
Using the whole async approach, I am able to load and process approx 54 files over smbfs in seconds and then run queries against it using a web front end.
Here is the gist for populating the available metric file array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var populateMetrics = function() { | |
metricsFiles = []; | |
var addMetric = function(file, callback) { | |
fs.stat(path + '/' + file, function(err, stats) { | |
if(stats.isDirectory()) { | |
fs.stat(path + '/' + file + '/Metrics.txt', function(err, stats) { | |
if(err) { | |
callback(); | |
} else { | |
metricsFiles.push(path + '/' + file + '/Metrics.txt'); | |
callback(); | |
} | |
}) | |
} else callback(); | |
}); | |
}; | |
fs.readdir(path, function(err, files) { | |
if(err) console.log(err); | |
async.forEach(files, addMetric, function(err) { | |
if(err) console.log(err); | |
console.log('************************\n' + metricsFiles.length + ' metric files found'); | |
scanMetrics(); | |
}); | |
}); | |
}; |
Once we have the list of metrics files, we create beadChip objects:
for each metrics file
new beadchip(file);
The object automatically calls its init script, which uses async to build the object's information from the log file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beadChip.prototype.init = function(file) { | |
// Localize beadChip members | |
var build = this.buildBeadChip; | |
var rows = this.rows; | |
var sections = this.sections; | |
var pass = this.pass; | |
var fail = this.fail; | |
var metricStream = fs.createReadStream(file, { | |
flags: 'r', | |
encoding: 'utf8', | |
mode: 0666 | |
}); | |
// Open file and stream data out | |
var allData = ""; | |
metricStream.on('open', function(fd) { | |
metricStream.on('data', function(data) { | |
allData += data; | |
}); | |
metricStream.on('error', function(err) { | |
console.log(err); | |
}); | |
// When EOF, split string on newline | |
metricStream.on('end', function() { | |
var eachRow = function(row, callback) { | |
rows.push(row); | |
callback(); | |
}; | |
async.forEach(allData.split('\n'), eachRow, function(err) { | |
if(err) console.log(err); | |
build(rows, sections, pass, fail); | |
}); | |
}); | |
}); | |
}; |
Finally, here is the forEach async function used in building the beadChip:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sectionObject = { | |
date: sectionArray[0], | |
beadChip: sectionArray[1], | |
section: sectionArray[2], | |
focusGrn: Number(sectionArray[3]), | |
regGrn: Number(sectionArray[4]), | |
p05Grn: Number(sectionArray[5]), | |
p95Grn: Number(sectionArray[6]), | |
focusRed: Number(sectionArray[7]), | |
regRed: Number(sectionArray[8]), | |
p05Red: Number(sectionArray[9]), | |
p95Red: Number(sectionArray[10]) | |
}; | |
// Conditions for bad section | |
if(sectionObject.focusGrn < 0.5 || sectionObject.focusRed < 0.5 || | |
sectionObject.p95Red < 10000 || sectionObject.p95Grn < 10000) { | |
fail.push(sectionObject); | |
} else { | |
pass.push(sectionObject); | |
} | |
sections.push(sectionObject); | |
callback(); | |
} | |
callback(); |