chore: change get-data exports

export a function for the specific opensky data, re-org code
This commit is contained in:
2018-11-02 14:09:25 -07:00
parent 96482e9044
commit aca5c03388
3 changed files with 26 additions and 32 deletions

View File

@@ -1,9 +1,8 @@
import elasticsearch from 'elasticsearch';
import logger from './lib/logger.mjs';
import { createIndex, bulkInsert } from './lib/data-source.mjs';
import getData from './lib/get-data.mjs';
import { getOpenskyData } from './lib/get-data.mjs';
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
export default async function(indexName, opts = {}) {
const client = new elasticsearch.Client({
@@ -18,29 +17,9 @@ export default async function(indexName, opts = {}) {
// create the target index
const index = await createIndex(client, indexName);
const records = await getData();
logger.debug(`ADS-B records:, ${records.length}`);
const records = await getOpenskyData();
logger.debug(`Record count:, ${records.length}`);
// index all the data
const documents = records.map(rec => ({
transponder: `${rec[0]}`.toLowerCase(),
callsign: `${rec[1]}`.trim(),
origin_country: rec[2],
time_position: new Date(rec[3] * 1000),
last_contact: new Date(rec[4] * 1000),
location: rec[5] && rec[6] ? `${rec[6]},${rec[5]}` : null,
lat: rec[6],
lon: rec[5],
baro_altitude: rec[7],
geo_altitude: rec[13],
on_ground: rec[8],
velocity: rec[9],
vertical_rate: rec[11],
squawk: rec[14],
spi: rec[15],
position_source: positionSourceMap[rec[16]],
}));
await bulkInsert(client, index, documents);
await bulkInsert(client, index, records);
logger.debug(`Successfully indexed ${records.length} records to ${index}`);
}