Skip to content

Commit

Permalink
Adds AIRAC from profile #1
Browse files Browse the repository at this point in the history
Reformat sectors for better exploration and search
Adds correct VATSIM data API discovery
  • Loading branch information
Kahn committed Oct 7, 2021
1 parent 8c54fde commit c5d252e
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 49 deletions.
83 changes: 79 additions & 4 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import query_overpass from 'query-overpass';
import config from 'config';
import { iso2dec } from './iso2dec.js';
import {Mutex, Semaphore, withTimeout} from 'async-mutex';
import uniqueRandomArray from 'unique-random-array';

var log = bunyan.createLogger({name: config.get('app.name'), level: config.get('app.log_level')});

Expand Down Expand Up @@ -35,6 +36,76 @@ export function cacheStats(){
return stats;
}

async function getVatsimServers(){
const url = config.get('data.vatsim.statusUrl');
var ttlMs = cache.getTtl(url);
let data;
// VATSIM data is refreshed every 15s. Check 10s out from expiry.
if (ttlMs == undefined || ttlMs - Date.now() <= 10000) {
try{
// Download fresh VATSIM data
if(ttlMs == undefined){
// If there is nothing cached - retry forever.
const res = await fetch(url, {
retryOptions: {
retryMaxDuration: 30000, // Max 30s retrying
retryInitialDelay: 1000, // 1s initial wait
retryBackoff: 500 // 0.5s backoff
},
headers: {
'User-Agent': userAgent
}
})
.then(res => res.json())
.then( data => {
return data;
})
log.trace({res: res});
data = res;
}else{
// If there is an old cache, timeout quickly.
const res = await fetch(url, {
retryOptions: {
retryMaxDuration: 2000,
retryInitialDelay: 500,
retryBackoff: 1.0 // no backoff
},
headers: {
'User-Agent': userAgent
}
})
.then(res => res.json())
.then( data => {
return data;
})
log.trace({res: res});
data = res;
}
log.info({
cache: 'set',
url: url,
keys: Object.keys(data).length
})
cache.set(url, data, 30);
}catch(err){
if ( err instanceof FetchError) {
// Failed to download - load from cache
data = cache.get(url);
} else {
log.error(err);
}
};
}else{
data = cache.get(url);
log.debug({
cache: 'get',
url: url,
keys: Object.keys(data).length
})
}
return data;
}

export async function getOSMAerodromeData (areaName) {
log.info(`getOSMAerodromeData`);
var data = await mutex.runExclusive(async () => {
Expand Down Expand Up @@ -85,8 +156,12 @@ export async function getOSMAerodromeData (areaName) {
return data;
};

export async function getVatsimData (url) {
var ttlMs = cache.getTtl(url);
export async function getVatsimData () {
const vatsimServers = await getVatsimServers();
var getUrl = uniqueRandomArray(vatsimServers.data.v3);
var url = getUrl();
log.debug(`VATSIM data URL: ${url}`);
var ttlMs = cache.getTtl('getVatsimData');
let data;
// VATSIM data is refreshed every 15s. Check 10s out from expiry.
if (ttlMs == undefined || ttlMs - Date.now() <= 10000) {
Expand Down Expand Up @@ -134,7 +209,7 @@ export async function getVatsimData (url) {
url: url,
keys: Object.keys(data).length
})
cache.set(url, data, 30);
cache.set('getVatsimData', data, 30);
}catch(err){
if ( err instanceof FetchError) {
// Failed to download - load from cache
Expand All @@ -144,7 +219,7 @@ export async function getVatsimData (url) {
}
};
}else{
data = cache.get(url);
data = cache.get('getVatsimData');
log.debug({
cache: 'get',
url: url,
Expand Down
35 changes: 25 additions & 10 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,52 @@
],
"sectors": {
"standard": [
"BN-TRT_CTR",
"BN-ARA_CTR",
"BN-ISA_CTR",
"BN-KEN_CTR",
"BN-ISA_CTR",
"BN-INL_CTR",
"BN-ARM_CTR",
"BN-TRT_CTR",
"ML-OLW_CTR",
"ML-ASP_CTR",
"ML-ARM_CTR",
"ML-OLW_CTR",
"ML-PIY_CTR",
"ML-TBD_CTR",
"ML-TAS_CTR",
"ML-PIY_CTR",
"ML-BIK_CTR",
"ML-ELW_CTR",
"ML-BIK_CTR"
"ML-TAS_CTR",
"BN-TSN_FSS",
"ML-IND_FSS"
]
}
},
"majorAerodromes": [
"YSSY",
"YMML",
"YBBN",
"YPPH",
"YPAD",
"YBCG",
"YBCS",
"YSCB",
"YMHB",
"YPDN"
]
},
"data": {
"vatsim": {
"dataUrl": "https://data.vatsim.net/v3/vatsim-data.json"
"statusUrl": "https://status.vatsim.net/status.json"
},
"vatsys": {
"fir_boundariesUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Maps/FIR_BOUNDARIES.xml",
"volumesUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Volumes.xml",
"sectorsUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Sectors.xml",
"coastlineUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Maps/COAST_ALL.xml",
"coloursUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Colours.xml"
"coloursUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Colours.xml",
"profileUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Profile.xml"
},
"osm": {
"overpassUrl": "https://lz4.overpass-api.de/api/interpreter",
"aerodromesArea": "New South Wales"
"aerodromesArea": "Australia"
}
}
}
2 changes: 1 addition & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"data": {
"vatsim": {
"dataUrl": "https://data.vatsim.net/v3/vatsim-data.json"
"statusUrl": "https://status.vatsim.net/status.json"
},
"vatsys": {
"fir_boundariesUrl": "https://raw.githubusercontent.com/vatSys/australia-dataset/master/Maps/FIR_BOUNDARIES.xml",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"node-fetch": "^2.6.1",
"query-overpass": "https://github.com/Kahn/query-overpass.git",
"rgb2hex": "^0.2.5",
"unique-random-array": "^3.0.0",
"xml-js": "^1.6.11"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pilots.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var log = bunyan.createLogger({name: config.get('app.name'), level: config.get('
export async function getPilots(){
try{
var firs = await getLineFeatures(config.get('data.vatsys.fir_boundariesUrl'));
var vatsimData = await getVatsimData(config.get('data.vatsim.dataUrl'));
var vatsimData = await getVatsimData();
var aerodromes = await getOSMAerodromeData(config.get('data.osm.aerodromesArea'));
}catch(err){
log.error(err)
Expand Down
20 changes: 15 additions & 5 deletions public/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,19 @@ var map = new mapboxgl.Map({
map.dragRotate.disable();
map.touchZoomRotate.disableRotation();

map.addControl(new mapboxgl.AttributionControl({
customAttribution: '<a href="https://github.com/Kahn/vatsim-map">vatsim-map</a>'
}))

// Light / Dark switch
var theme = findGetParameter('theme') || 'light';
if(theme == 'dark'){
map.setStyle(styleDark);
}

async function getDataset() {
var response = await fetch(`${window.location.protocol}//${window.location.hostname}:${window.location.port}/v1/dataset`);
var json = await response.json();
dataset = json;
return json;
};

async function getPilots() {
var dataApi = findGetParameter('dataApi');
if(dataApi != false){
Expand Down Expand Up @@ -490,8 +493,15 @@ async function setPilotMarkers () {

getPilots();

map.on('load', function () {
(async () => {
var dataset = await getDataset();
console.log(dataset);
map.addControl(new mapboxgl.AttributionControl({
customAttribution: `vatSys ${dataset.Profile._attributes.Name} dataset <strong>AIRAC ${dataset.Profile.Version._attributes.AIRAC}${dataset.Profile.Version._attributes.Revision}</strong> | <a href="https://github.com/Kahn/vatsim-map">vatsim-map</a>`
}))
})();

map.on('load', function () {
map.addSource('aircraftMarkersSource', {
'type': 'geojson',
'data': null
Expand Down
17 changes: 17 additions & 0 deletions public/sectormap.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
top: 0;
bottom: 0;
width: 100%;
z-index: 0;
}

.mapboxgl-popup-content {
Expand All @@ -25,6 +26,13 @@
/* line-height: 1.4; */
white-space: pre-line;
}
#mgl-map-overlay {
position: absolute;
top: 10px;
left: 10px;
z-index: 1;
background-color: #fff;
}
</style>
</head>
<body>
Expand All @@ -43,6 +51,15 @@
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
<!-- <script src="map-styles.js"></script> -->
<div id='mgl-map-overlay'>
<strong>Map key</strong>
<ul>
<li>Thick solid line: Standard sector boundary</li>
<li>Thin solid line: Non-standard sector boundary</li>
<li>Thick dashed line: TMA volume boundary</li>
<li>Thin dotted line: Tower volume boundary</li>
</ul>
</div>
<script src="sectormap.js"></script>
</body>
</html>
Loading

0 comments on commit c5d252e

Please sign in to comment.