Compare commits
4 Commits
295d7ffa80
...
89261d0010
| Author | SHA1 | Date | |
|---|---|---|---|
| 89261d0010 | |||
| 9f0da54ccf | |||
| aca5c03388 | |||
| 96482e9044 |
@@ -1,6 +1,9 @@
|
||||
### Changelog
|
||||
|
||||
#### 1.0.0 (2 November 2018)
|
||||
#### [v1.0.1](https://git.w33ble.com/w33ble/adsb-index/compare/v1.0.0...v1.0.1) (2 November 2018)
|
||||
- fix: format api data correctly [`6def944`](https://git.w33ble.com/w33ble/adsb-index/commit/6def9449be415c50390a2eaa4fd124bd5fa548b6)
|
||||
|
||||
#### v1.0.0 (2 November 2018)
|
||||
- feat: index location as raw numbers [`98e54c8`](https://git.w33ble.com/w33ble/adsb-index/commit/98e54c89d99d01f9dd7762e2851449740e0c8571)
|
||||
- fix: save timestamps correctly [`20bb946`](https://git.w33ble.com/w33ble/adsb-index/commit/20bb9460d17af65950bb5beffab3a3fc6a075a9a)
|
||||
- feat: add basic auth support [`420c845`](https://git.w33ble.com/w33ble/adsb-index/commit/420c845cbc70a7a816ea92986c4e10c206194dca)
|
||||
|
||||
@@ -5,7 +5,7 @@ const cron = require('node-cron');
|
||||
const mod = require('../src/index.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'],
|
||||
alias: {
|
||||
h: 'host',
|
||||
@@ -19,6 +19,9 @@ const { index, interval, ...elasticsearch } = getopts(process.argv.slice(2), {
|
||||
log: 'error',
|
||||
index: 'adsb-data',
|
||||
interval: 0,
|
||||
lat: 33.433638,
|
||||
lon: -112.008113,
|
||||
radius: 1000,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -28,7 +31,7 @@ function handleError(err) {
|
||||
}
|
||||
|
||||
async function fetchAndIndex() {
|
||||
return mod(index, { elasticsearch });
|
||||
return mod(index, { elasticsearch, filter: { lat, lon, radius } });
|
||||
}
|
||||
|
||||
async function run() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "adsb-index",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"private": true,
|
||||
"description": "ADS-B indexing script",
|
||||
"bin": "bin/index.js",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
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';
|
||||
|
||||
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
||||
import { getAdbsExchangeData } from './lib/get-data.mjs';
|
||||
|
||||
export default async function(indexName, opts = {}) {
|
||||
const client = new elasticsearch.Client({
|
||||
@@ -18,29 +16,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 getAdbsExchangeData(opts.filter);
|
||||
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}`);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ export async function createIndex(client, index) {
|
||||
mappings: {
|
||||
[doctype]: {
|
||||
properties: {
|
||||
operator: { type: 'keyword' },
|
||||
aircraft: { type: 'text' },
|
||||
aircraft_manufacturer: { type: 'keyword' },
|
||||
transponder: { type: 'keyword' },
|
||||
callsign: { type: 'keyword' },
|
||||
origin_country: { type: 'keyword' },
|
||||
@@ -42,6 +45,8 @@ export async function createIndex(client, index) {
|
||||
squawk: { type: 'keyword' },
|
||||
spi: { type: 'boolean' },
|
||||
position_source: { type: 'keyword' },
|
||||
from: { type: 'text' },
|
||||
to: { type: 'text' },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = 'https://opensky-network.org/api';
|
||||
|
||||
export default axios.create({
|
||||
baseURL: api,
|
||||
timeout: 3000,
|
||||
timeout: 5000,
|
||||
responseType: 'json',
|
||||
headers: {
|
||||
'X-Custom-Header': 'foobar',
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,55 @@
|
||||
import fetch from './fetch.mjs';
|
||||
|
||||
export default async function getData() {
|
||||
const res = await fetch.get('/states/all');
|
||||
return res.data.states;
|
||||
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: `${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: rec.Alt,
|
||||
geo_altitude: rec.Galt,
|
||||
on_ground: rec.Gnd,
|
||||
velocity: rec.Spd,
|
||||
vertical_rate: 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