Compare commits
4 Commits
v1.0.1
...
d290165899
| Author | SHA1 | Date | |
|---|---|---|---|
| d290165899 | |||
| 89261d0010 | |||
| 9f0da54ccf | |||
| aca5c03388 |
@@ -5,7 +5,7 @@ const cron = require('node-cron');
|
|||||||
const mod = require('../src/index.mjs').default;
|
const mod = require('../src/index.mjs').default;
|
||||||
const logger = require('../src/lib/logger.mjs').default;
|
const logger = require('../src/lib/logger.mjs').default;
|
||||||
|
|
||||||
const { index, interval, ...elasticsearch } = getopts(process.argv.slice(2), {
|
const { index, interval, lat, lon, radius, ...elasticsearch } = getopts(process.argv.slice(2), {
|
||||||
string: ['host', 'auth', 'log', 'index'],
|
string: ['host', 'auth', 'log', 'index'],
|
||||||
alias: {
|
alias: {
|
||||||
h: 'host',
|
h: 'host',
|
||||||
@@ -19,6 +19,9 @@ const { index, interval, ...elasticsearch } = getopts(process.argv.slice(2), {
|
|||||||
log: 'error',
|
log: 'error',
|
||||||
index: 'adsb-data',
|
index: 'adsb-data',
|
||||||
interval: 0,
|
interval: 0,
|
||||||
|
lat: 33.433638,
|
||||||
|
lon: -112.008113,
|
||||||
|
radius: 1000,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -28,7 +31,7 @@ function handleError(err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAndIndex() {
|
async function fetchAndIndex() {
|
||||||
return mod(index, { elasticsearch });
|
return mod(index, { elasticsearch, filter: { lat, lon, radius } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import elasticsearch from 'elasticsearch';
|
import elasticsearch from 'elasticsearch';
|
||||||
import logger from './lib/logger.mjs';
|
import logger from './lib/logger.mjs';
|
||||||
import { createIndex, bulkInsert } from './lib/data-source.mjs';
|
import { createIndex, bulkInsert } from './lib/data-source.mjs';
|
||||||
import getData from './lib/get-data.mjs';
|
import { getAdbsExchangeData } from './lib/get-data.mjs';
|
||||||
|
|
||||||
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
|
||||||
|
|
||||||
export default async function(indexName, opts = {}) {
|
export default async function(indexName, opts = {}) {
|
||||||
const client = new elasticsearch.Client({
|
const client = new elasticsearch.Client({
|
||||||
@@ -18,29 +16,9 @@ export default async function(indexName, opts = {}) {
|
|||||||
// create the target index
|
// create the target index
|
||||||
const index = await createIndex(client, indexName);
|
const index = await createIndex(client, indexName);
|
||||||
|
|
||||||
const records = await getData();
|
const records = await getAdbsExchangeData(opts.filter);
|
||||||
logger.debug(`ADS-B records:, ${records.length}`);
|
logger.debug(`Record count:, ${records.length}`);
|
||||||
|
|
||||||
// index all the data
|
await bulkInsert(client, index, records);
|
||||||
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);
|
|
||||||
logger.debug(`Successfully indexed ${records.length} records to ${index}`);
|
logger.debug(`Successfully indexed ${records.length} records to ${index}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ export async function createIndex(client, index) {
|
|||||||
mappings: {
|
mappings: {
|
||||||
[doctype]: {
|
[doctype]: {
|
||||||
properties: {
|
properties: {
|
||||||
|
operator: { type: 'keyword' },
|
||||||
|
aircraft: { type: 'text' },
|
||||||
|
aircraft_manufacturer: { type: 'keyword' },
|
||||||
transponder: { type: 'keyword' },
|
transponder: { type: 'keyword' },
|
||||||
callsign: { type: 'keyword' },
|
callsign: { type: 'keyword' },
|
||||||
origin_country: { type: 'keyword' },
|
origin_country: { type: 'keyword' },
|
||||||
@@ -42,6 +45,8 @@ export async function createIndex(client, index) {
|
|||||||
squawk: { type: 'keyword' },
|
squawk: { type: 'keyword' },
|
||||||
spi: { type: 'boolean' },
|
spi: { type: 'boolean' },
|
||||||
position_source: { type: 'keyword' },
|
position_source: { type: 'keyword' },
|
||||||
|
from: { type: 'text' },
|
||||||
|
to: { type: 'text' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const api = 'https://opensky-network.org/api';
|
|
||||||
|
|
||||||
export default axios.create({
|
export default axios.create({
|
||||||
baseURL: api,
|
timeout: 5000,
|
||||||
timeout: 3000,
|
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Custom-Header': 'foobar',
|
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,57 @@
|
|||||||
import fetch from './fetch.mjs';
|
import fetch from './fetch.mjs';
|
||||||
|
|
||||||
export default async function getData() {
|
export async function getOpenskyData() {
|
||||||
const res = await fetch.get('/states/all');
|
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
||||||
return res.data.states;
|
const res = await fetch.get(`https://opensky-network.org/api/states/all`);
|
||||||
|
return res.data.states.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]],
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAdbsExchangeData({ lat, lon, radius }) {
|
||||||
|
const positionSourceMap = ['Unknown', 'Mode-S', 'ADS-B', 'ADS-B', 'ADS-B', 'ADS-B'];
|
||||||
|
const formatNumber = str => str && Number(`${str}`.replace(/[^0-9.-]/, ''));
|
||||||
|
|
||||||
|
const res = await fetch.get(
|
||||||
|
`http://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat=${lat}&lng=${lon}&fDstL=0&fDstU=${radius}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.data.acList.map(rec => ({
|
||||||
|
transponder: `${rec.Icao}`.toLowerCase(),
|
||||||
|
callsign: `${rec.Call}`.trim(),
|
||||||
|
origin_country: rec.Cou,
|
||||||
|
time_position: new Date(rec.PosTime),
|
||||||
|
last_contact: new Date(rec.PosTime),
|
||||||
|
location: rec.Lat && rec.Long ? `${rec.Lat},${rec.Long}` : null,
|
||||||
|
lat: rec.Lat,
|
||||||
|
lon: rec.Long,
|
||||||
|
baro_altitude: formatNumber(rec.Alt),
|
||||||
|
geo_altitude: formatNumber(rec.GAlt),
|
||||||
|
on_ground: rec.Gnd,
|
||||||
|
velocity: formatNumber(rec.Spd),
|
||||||
|
vertical_rate: formatNumber(rec.Vsi),
|
||||||
|
squawk: rec.Sqk,
|
||||||
|
spi: false,
|
||||||
|
position_source: positionSourceMap[rec.Trt],
|
||||||
|
operator: rec.Op,
|
||||||
|
aircraft: rec.Mdl,
|
||||||
|
aircraft_manufacturer: rec.Man,
|
||||||
|
from: rec.From,
|
||||||
|
to: rec.To,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user