Add a script that filters redundant registrations from the json db

This commit is contained in:
Oliver Jowett 2016-09-10 15:54:59 +01:00
parent e5912c322f
commit d1a33f4655
3 changed files with 51 additions and 3 deletions

36
tools/filter-regs.js Normal file
View file

@ -0,0 +1,36 @@
//
// This script processes a CSV file that contains
// ICAO addresses (column 'icao24') and registrations
// (column 'r')
//
// It removes all registration entries that exactly match
// what dump1090 would have computed from the hexid anyway,
// reducing the size of the CSV in the cases where the
// two approaches match.
//
// Any additional columns are passed through unchanged.
//
// To run it:
//
// sudo apt-get install nodejs
// sudo apt-get install npm
// npm install csv # must be done in the same dir as this script
// nodejs filter-regs.js <input.csv >output.csv
var reglookup = require('../public_html/registrations.js');
var csv = require('csv');
var parser = csv.parse({columns: true});
var writer = csv.stringify({header: true});
var transformer = csv.transform(function (record, callback) {
if (('icao24' in record) && ('r' in record)) {
var computed = reglookup(record.icao24);
if (computed === record.r) {
record.r = '';
}
}
callback(null, record);
});
process.stdin.pipe(parser).pipe(transformer).pipe(writer).pipe(process.stdout);