Compare commits
6 Commits
v2.1.0
...
4cbde45293
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cbde45293 | |||
| 559c7d64d6 | |||
| ed6186f63b | |||
| aefbcabac0 | |||
| 7b5ad0ffc6 | |||
| c5e8b7f178 |
@@ -1,5 +1,8 @@
|
||||
### Changelog
|
||||
|
||||
#### [v2.1.1](https://git.w33ble.com/w33ble/adsb-index/compare/v2.1.0...v2.1.1) (6 November 2018)
|
||||
- fix: saner defaults [`c5e8b7f`](https://git.w33ble.com/w33ble/adsb-index/commit/c5e8b7f178a8bbc76b72eea08afc4d578baababb)
|
||||
|
||||
#### [v2.1.0](https://git.w33ble.com/w33ble/adsb-index/compare/v2.0.1...v2.1.0) (2 November 2018)
|
||||
- feat: add raw version of text fields [`6591e7e`](https://git.w33ble.com/w33ble/adsb-index/commit/6591e7eaa8c9c317a55632f856310cdd3f783464)
|
||||
|
||||
|
||||
@@ -13,4 +13,8 @@ WORKDIR /app
|
||||
VOLUME /app/data
|
||||
COPY --from=0 /build .
|
||||
COPY . .
|
||||
ENTRYPOINT ["yarn", "start"]
|
||||
|
||||
ENV ELASTICSEARCH_HOST="host.docker.internal"
|
||||
ENV ELASTICSEARCH_PORT="9200"
|
||||
|
||||
ENTRYPOINT ["node", "bin/index", "-t", "5"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# adsb-index
|
||||
# fake-adsb-index
|
||||
|
||||
ADS-B indexing script.
|
||||
FAKE ADS-B indexing script.
|
||||
|
||||
[](https://raw.githubusercontent.com/w33ble/adsb-index/master/LICENSE)
|
||||
[](https://www.npmjs.com/package/adsb-index)
|
||||
|
||||
22
bin/index.js
22
bin/index.js
@@ -5,23 +5,26 @@ const runInterval = require('interval-promise');
|
||||
const mod = require('../src/index.mjs').default;
|
||||
const logger = require('../src/lib/logger.mjs').default;
|
||||
|
||||
const { index, interval, lat, lon, radius, ...elasticsearch } = getopts(process.argv.slice(2), {
|
||||
const esHost = process.env.ELASTICSEARCH_HOST || 'localhost';
|
||||
const esPort = process.env.ELASTICSEARCH_PORT || '9200';
|
||||
const auth = process.env.ELASTICSEARCH_AUTH || '';
|
||||
|
||||
const { index, interval, lat, lon, radius, ...esConfig } = getopts(process.argv.slice(2), {
|
||||
string: ['host', 'auth', 'log', 'index'],
|
||||
alias: {
|
||||
h: 'host',
|
||||
u: 'auth',
|
||||
l: 'log',
|
||||
i: 'index',
|
||||
t: 'interval',
|
||||
},
|
||||
default: {
|
||||
host: 'localhost:9200',
|
||||
host: `${esHost}:${esPort}`,
|
||||
log: 'error',
|
||||
index: 'adsb-data',
|
||||
interval: 0,
|
||||
lat: 33.433638,
|
||||
lon: -112.008113,
|
||||
radius: 1000,
|
||||
radius: 200,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -31,14 +34,21 @@ function handleError(err) {
|
||||
}
|
||||
|
||||
async function fetchAndIndex() {
|
||||
logger.debug('Fetching and indexing data...');
|
||||
return mod(index, { elasticsearch, filter: { lat, lon, radius } });
|
||||
return mod(index, { elasticsearch: { ...esConfig, auth }, filter: { lat, lon, radius } });
|
||||
}
|
||||
|
||||
async function run() {
|
||||
// initial kickoff
|
||||
await fetchAndIndex().catch(handleError);
|
||||
|
||||
// listen for termination
|
||||
const terminate = type => () => {
|
||||
console.log(`Terminating [${type}]`);
|
||||
process.exit(0);
|
||||
};
|
||||
process.on('SIGINT', terminate('SIGINT'));
|
||||
process.on('SIGTERM', terminate('SIGTERM'));
|
||||
|
||||
// scheduled running
|
||||
if (interval === 0) return;
|
||||
logger.debug(`Starting interval (${interval}s)...`);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "adsb-index",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.1",
|
||||
"private": true,
|
||||
"description": "ADS-B indexing script",
|
||||
"bin": "bin/index.js",
|
||||
|
||||
@@ -17,7 +17,6 @@ export default async function(indexName, opts = {}) {
|
||||
const index = await createIndex(client, indexName);
|
||||
|
||||
const records = await getAdbsExchangeData(opts.filter);
|
||||
logger.debug(`Record count:, ${records.length}`);
|
||||
|
||||
await bulkInsert(client, index, records);
|
||||
logger.debug(`Successfully indexed ${records.length} records to ${index}`);
|
||||
|
||||
@@ -58,10 +58,8 @@ export async function createIndex(client, index) {
|
||||
})
|
||||
.catch(err => {
|
||||
// check for existing index
|
||||
if (err instanceof BadRequest) {
|
||||
logger.debug(`Index exists: ${realIndex}`);
|
||||
if (err instanceof BadRequest)
|
||||
return client.indices.get({ index: realIndex }).then(() => realIndex);
|
||||
}
|
||||
|
||||
throw err;
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export default axios.create({
|
||||
timeout: 5000,
|
||||
timeout: 3000,
|
||||
responseType: 'json',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
|
||||
@@ -1,63 +1,206 @@
|
||||
import fetch from './fetch.mjs';
|
||||
/* eslint import/prefer-default-export: 0 */
|
||||
|
||||
const formatNumber = str => str && Number(`${str}`.replace(/[^0-9.-]/, ''));
|
||||
const formatString = str => {
|
||||
if (str == null) return 'N/A';
|
||||
if (typeof str !== 'string') return str;
|
||||
return str && str.length && str !== 'undefined' ? str.trim() : 'N/A';
|
||||
};
|
||||
|
||||
export async function getOpenskyData() {
|
||||
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
||||
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 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: formatString(`${rec.Icao}`.toLowerCase()),
|
||||
callsign: formatString(rec.Call),
|
||||
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,
|
||||
const aircrafts = [
|
||||
{
|
||||
transponder: 'abe09a',
|
||||
callsign: 'SWA146',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T20:49:35.234Z',
|
||||
last_contact: '2019-01-28T20:49:35.234Z',
|
||||
location: '33.440986,-112.079717',
|
||||
lat: 33.440986,
|
||||
lon: -112.079717,
|
||||
baro_altitude: 1950,
|
||||
geo_altitude: 2000,
|
||||
on_ground: false,
|
||||
velocity: 162.1,
|
||||
vertical_rate: -832,
|
||||
squawk: '1523',
|
||||
spi: false,
|
||||
position_source: positionSourceMap[rec.Trt],
|
||||
operator: formatString(rec.Op),
|
||||
aircraft: formatString(rec.Mdl),
|
||||
aircraft_manufacturer: formatString(rec.Man),
|
||||
from: formatString(rec.From),
|
||||
to: formatString(rec.To),
|
||||
}));
|
||||
position_source: 'ADS-B',
|
||||
operator: 'Southwest Airlines',
|
||||
aircraft: '2014 BOEING 737-8H4',
|
||||
aircraft_manufacturer: 'Boeing',
|
||||
from: 'KHOU William P Hobby, Houston, United States',
|
||||
to: 'KONT Ontario, United States',
|
||||
},
|
||||
{
|
||||
transponder: 'acc1ee',
|
||||
callsign: 'AAL2450',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T20:49:07.341Z',
|
||||
last_contact: '2019-01-28T20:49:07.341Z',
|
||||
location: '33.431071,-112.004887',
|
||||
lat: 33.431071,
|
||||
lon: -112.004887,
|
||||
baro_altitude: 1150,
|
||||
geo_altitude: 1200,
|
||||
on_ground: false,
|
||||
velocity: 125,
|
||||
vertical_rate: 64,
|
||||
squawk: '',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'AMERICAN AIRLINES INC - FORT WORTH, TX',
|
||||
aircraft: '1999 BOEING 737-823',
|
||||
aircraft_manufacturer: 'Boeing',
|
||||
from: 'KLAX Los Angeles, United States',
|
||||
to: 'KDFW Dallas Fort Worth, Dallas-Fort Worth, United States',
|
||||
},
|
||||
{
|
||||
transponder: 'a742c2',
|
||||
callsign: 'AAL2197',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T20:46:30.215Z',
|
||||
last_contact: '2019-01-28T20:46:30.215Z',
|
||||
location: '33.431053,-112.020776',
|
||||
lat: 33.431053,
|
||||
lon: -112.020776,
|
||||
baro_altitude: 1475,
|
||||
geo_altitude: 1525,
|
||||
on_ground: false,
|
||||
velocity: 183,
|
||||
vertical_rate: 3264,
|
||||
squawk: '2656',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'American Airlines',
|
||||
aircraft: '2013 AIRBUS A321-231',
|
||||
aircraft_manufacturer: 'Airbus',
|
||||
from: 'KMCO Orlando, United States',
|
||||
to: 'KDFW Dallas Fort Worth, Dallas-Fort Worth, United States',
|
||||
},
|
||||
{
|
||||
transponder: 'a23c2e',
|
||||
callsign: 'ASH5742',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T20:40:09.162Z',
|
||||
last_contact: '2019-01-28T20:40:09.162Z',
|
||||
location: '33.440826,-112.020557',
|
||||
lat: 33.440826,
|
||||
lon: -112.020557,
|
||||
baro_altitude: 1100,
|
||||
geo_altitude: 1088,
|
||||
on_ground: false,
|
||||
velocity: 138,
|
||||
vertical_rate: -320,
|
||||
squawk: '2444',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'BANK OF UTAH TRUSTEE - SALT LAKE CITY, UT',
|
||||
aircraft: '2006 BOMBARDIER INC CL-600-2D24',
|
||||
aircraft_manufacturer: 'Bombardier',
|
||||
from: 'N/A',
|
||||
to: 'N/A',
|
||||
},
|
||||
{
|
||||
transponder: 'a91e6e',
|
||||
callsign: 'N/A',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T19:02:32.530Z',
|
||||
last_contact: '2019-01-28T19:02:32.530Z',
|
||||
location: '33.435703,-112.003822',
|
||||
lat: 33.435703,
|
||||
lon: -112.003822,
|
||||
baro_altitude: 1350,
|
||||
geo_altitude: 1530,
|
||||
on_ground: false,
|
||||
velocity: 130,
|
||||
vertical_rate: -384,
|
||||
squawk: '1363',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'Spirit Airlines',
|
||||
aircraft: 'Airbus A321 231SL',
|
||||
aircraft_manufacturer: 'Airbus',
|
||||
from: 'N/A',
|
||||
to: 'N/A',
|
||||
},
|
||||
{
|
||||
transponder: 'a8a7f1',
|
||||
callsign: 'NKS1167',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T00:20:20.803Z',
|
||||
last_contact: '2019-01-28T00:20:20.803Z',
|
||||
location: '33.440826,-111.981006',
|
||||
lat: 33.440826,
|
||||
lon: -111.981006,
|
||||
baro_altitude: 1200,
|
||||
geo_altitude: 1259,
|
||||
on_ground: false,
|
||||
velocity: 143,
|
||||
vertical_rate: -768,
|
||||
squawk: '6513',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'Spirit Airlines',
|
||||
aircraft: '2015 AIRBUS A321-231',
|
||||
aircraft_manufacturer: 'Airbus',
|
||||
from: 'N/A',
|
||||
to: 'N/A',
|
||||
},
|
||||
{
|
||||
transponder: 'aa56db',
|
||||
callsign: 'UAL1139',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T21:04:05.916Z',
|
||||
last_contact: '2019-01-28T21:04:05.916Z',
|
||||
location: '33.429953,-112.004802',
|
||||
lat: 33.429953,
|
||||
lon: -112.004802,
|
||||
baro_altitude: 1100,
|
||||
geo_altitude: 1251,
|
||||
on_ground: false,
|
||||
velocity: 156,
|
||||
vertical_rate: -960,
|
||||
squawk: '3352',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'United Airlines',
|
||||
aircraft: '2010 BOEING 737-824',
|
||||
aircraft_manufacturer: 'Boeing',
|
||||
from: 'KIAD Washington Dulles, United States',
|
||||
to: 'MWCR Owen Roberts, Georgetown, Cayman Islands',
|
||||
},
|
||||
{
|
||||
transponder: 'abb601',
|
||||
callsign: 'SWA1386',
|
||||
origin_country: 'United States',
|
||||
time_position: '2019-01-28T21:02:07.189Z',
|
||||
last_contact: '2019-01-28T21:02:07.189Z',
|
||||
location: '33.432129,-111.9989',
|
||||
lat: 33.432129,
|
||||
lon: -111.9989,
|
||||
baro_altitude: 1875,
|
||||
geo_altitude: 1925,
|
||||
on_ground: false,
|
||||
velocity: 23,
|
||||
vertical_rate: -832,
|
||||
squawk: '7427',
|
||||
spi: false,
|
||||
position_source: 'ADS-B',
|
||||
operator: 'Southwest Airlines',
|
||||
aircraft: 'Boeing 737NG 800/W',
|
||||
aircraft_manufacturer: 'Boeing',
|
||||
from: 'KFLL Fort Lauderdale Hollywood, United States',
|
||||
to: 'KPIT Pittsburgh, United States',
|
||||
},
|
||||
];
|
||||
|
||||
export async function getAdbsExchangeData() {
|
||||
const count = Math.ceil(Math.random() * 3);
|
||||
const now = new Date();
|
||||
|
||||
const records = [];
|
||||
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
const idx = Math.floor(Math.random() * (aircrafts.length - 1));
|
||||
records.push({
|
||||
...aircrafts[idx],
|
||||
time_position: now.toISOString(),
|
||||
last_contact: now.toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user