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,6 +1,25 @@
import fetch from './fetch.mjs';
export default async function getData() {
const res = await fetch.get('/states/all');
return res.data.states;
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
export async function getOpenskyData() {
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]],
}));
}