2016-09-10 16:54:59 +02:00
|
|
|
//
|
|
|
|
// This script processes a CSV file that contains
|
|
|
|
// ICAO addresses (column 'icao24') and registrations
|
|
|
|
// (column 'r')
|
|
|
|
//
|
2019-08-16 09:16:55 +02:00
|
|
|
// It replaces all registration entries that exactly match
|
|
|
|
// what dump1090 would have computed from the hexid anyway
|
|
|
|
// with the special value "-COMPUTED-"; these values are
|
|
|
|
// removed from the final data when csv-to-json.py writes
|
|
|
|
// the json database, reducing the size of the database
|
|
|
|
// in the cases where the two approaches match.
|
|
|
|
//
|
|
|
|
// It does a similar transformation on 'desc' (aircraft type
|
|
|
|
// description) and 'wtc' (wake turbulence categogy) based
|
|
|
|
// on the aircraft type designator in 't', if provided.
|
2016-09-10 16:54:59 +02:00
|
|
|
//
|
|
|
|
// 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');
|
2016-09-14 20:06:51 +02:00
|
|
|
var actypes = require('../public_html/db/aircraft_types/icao_aircraft_types.json');
|
2016-09-10 16:54:59 +02:00
|
|
|
var csv = require('csv');
|
|
|
|
|
|
|
|
var parser = csv.parse({columns: true});
|
|
|
|
var writer = csv.stringify({header: true});
|
|
|
|
var transformer = csv.transform(function (record, callback) {
|
2016-09-14 20:06:51 +02:00
|
|
|
if ('icao24' in record) {
|
|
|
|
if ('r' in record && record.r != '') {
|
|
|
|
var computed = reglookup(record.icao24);
|
|
|
|
if (computed === record.r) {
|
2019-08-16 09:16:55 +02:00
|
|
|
record.r = '-COMPUTED-';
|
2016-09-14 20:06:51 +02:00
|
|
|
} else if (computed !== null) {
|
|
|
|
console.warn(record.icao24 + " computed registration " + computed + " but CSV data had " + record.r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('t' in record && record.t in actypes) {
|
|
|
|
if ('desc' in record && record.desc != '') {
|
|
|
|
var computed_desc = actypes[record.t].desc;
|
|
|
|
if (computed_desc === record.desc) {
|
2019-08-16 09:16:55 +02:00
|
|
|
record.desc = '-COMPUTED-';
|
2016-09-14 20:06:51 +02:00
|
|
|
} else if (computed_desc !== undefined) {
|
|
|
|
// too noisy, the icao descriptors are very coarse and reality often disagrees
|
|
|
|
//console.warn(record.icao24 + " (" + record.t + "): computed type description " + computed_desc + " but CSV data had " + record.desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('wtc' in record && record.wtc != '') {
|
|
|
|
var computed_wtc = actypes[record.t].wtc;
|
|
|
|
if (computed_wtc === record.wtc) {
|
2019-08-16 09:16:55 +02:00
|
|
|
record.wtc = '-COMPUTED-';
|
2016-09-14 20:06:51 +02:00
|
|
|
} else if (computed_desc !== undefined) {
|
|
|
|
//console.warn(record.icao24 + " (" + record.t + "): computed type WTC " + computed_wtc + " but CSV data had " + record.wtc);
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 16:54:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null, record);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.stdin.pipe(parser).pipe(transformer).pipe(writer).pipe(process.stdout);
|