Groundnet Scan
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/* eslint-disable */
|
||||
const loki = require('lokijs');
|
||||
const fs = require('fs');
|
||||
|
||||
var db = new loki('airports_DB.json');
|
||||
var features = null;
|
||||
|
||||
export async function init() {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
console.log("Init " + (features == null));
|
||||
if (features == null) {
|
||||
console.log("Loading DB");
|
||||
db.loadDatabase({}, function (err) {
|
||||
if (err) {
|
||||
console.error("Error loading DB");
|
||||
console.error(err);
|
||||
db.addCollection('features', {
|
||||
unique: ["properties.icao"], autoupdate: true
|
||||
});
|
||||
features = db.getCollection('features');
|
||||
}
|
||||
features = db.getCollection('features');
|
||||
if( features == null ){
|
||||
db.addCollection('features', {
|
||||
unique: ["properties.icao"], autoupdate: true
|
||||
});
|
||||
features = db.getCollection('features');
|
||||
}
|
||||
console.log("Loaded " + features.count() + " features");
|
||||
resolve(features);
|
||||
});
|
||||
}
|
||||
else {
|
||||
resolve(features);
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
export function getAirport(apts, icao) {
|
||||
console.log("Getting Airport " + icao);
|
||||
var results = apts.where(function (f) {
|
||||
return f.properties['icao'] === icao;
|
||||
});
|
||||
var feature;
|
||||
if (results.length == 0) {
|
||||
feature = {
|
||||
"type": "Feature",
|
||||
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0 },
|
||||
'geometry': {
|
||||
"type": "Point"
|
||||
}
|
||||
};
|
||||
feature = apts.insert(feature);
|
||||
// apts.update(feature);
|
||||
console.log("Added New");
|
||||
console.log(JSON.stringify(feature));
|
||||
return feature;
|
||||
}
|
||||
else {
|
||||
console.debug("retrieved " + JSON.stringify(results[0]));
|
||||
return results[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function save() {
|
||||
if (!features || !features.data)
|
||||
return;
|
||||
var mappedData = features.data.map(function (f) {
|
||||
delete f.meta;
|
||||
delete f.$loki;
|
||||
if(f.properties.airlines) {
|
||||
f.properties.airlines = f.properties.airlines.join(' ');
|
||||
}
|
||||
else {
|
||||
f.properties.airlines = [];
|
||||
}
|
||||
|
||||
return f;
|
||||
});
|
||||
|
||||
mappedData = mappedData.filter(feature => feature.properties['twr'] || feature.properties['threshold']);
|
||||
|
||||
//console.log(mappedData);
|
||||
var featureCollection = { type: "FeatureCollection", features: mappedData };
|
||||
|
||||
let data = JSON.stringify(featureCollection, null, 2);
|
||||
fs.writeFileSync('airports.json', data);
|
||||
db.saveDatabase(function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/* eslint-disable */
|
||||
|
||||
var features = null;
|
||||
|
||||
async function initDB() {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
console.log("Init " + (features == null));
|
||||
if (features == null) {
|
||||
console.log("Loading DB");
|
||||
console.log(this.indexedDB);
|
||||
// var deleteRequest = indexedDB.deleteDatabase("flightgear");
|
||||
// deleteRequest.onerror = function (event) {
|
||||
// console.log(event);
|
||||
// reject(event);
|
||||
// };
|
||||
// deleteRequest.onsuccess = function (event) {
|
||||
// console.log(event);
|
||||
// };
|
||||
|
||||
var request = this.indexedDB.open("flightgear", 2);
|
||||
request.onerror = function (event) {
|
||||
reject(event);
|
||||
};
|
||||
request.onsuccess = function (event) {
|
||||
console.log('Opened DB ' + event);
|
||||
|
||||
features = request.result;
|
||||
resolve(features);
|
||||
};
|
||||
request.onupgradeneeded = function (event) {
|
||||
var db = event.target.result;
|
||||
console.log("Migrate " + event);
|
||||
|
||||
// Create an objectStore to hold information about our customers. We're
|
||||
// going to use "ssn" as our key path because it's guaranteed to be
|
||||
// unique.
|
||||
if (event.oldVersion < 1) {
|
||||
// Version 1 is the first version of the database.
|
||||
var objectStore = db.createObjectStore("airports", { keyPath: "properties.icao" });
|
||||
}
|
||||
if (event.oldVersion < 2) {
|
||||
// Version 1 is the first version of the database.
|
||||
var objectStore = event.target.transaction.objectStore("airports");
|
||||
var indexNames = objectStore.indexNames;
|
||||
var desiredKeyPathForMyIndex = "properties.icao";
|
||||
console.log(indexNames);
|
||||
|
||||
if(indexNames.contains('myIndexName')) {
|
||||
var myIndex = objectStore.index('myIndexName');
|
||||
var currentKeyPath = myIndex.keyPath;
|
||||
if(currentKeyPath != desiredKeyPathForMyIndex) {
|
||||
objectStore.deleteIndex('myIndexName');
|
||||
objectStore.createIndex('myIndexName', desiredKeyPathForMyIndex);
|
||||
}
|
||||
} else {
|
||||
objectStore.createIndex('myIndexName', desiredKeyPathForMyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
// db.loadDatabase({}, function (err) {
|
||||
// if (err) {
|
||||
// console.error("Error loading DB");
|
||||
// console.error(err);
|
||||
// db.addCollection('features', {
|
||||
// unique: ["properties.icao"], autoupdate: true
|
||||
// });
|
||||
// features = db.getCollection('features');
|
||||
// }
|
||||
// features = db.getCollection('features');
|
||||
// if( features == null ){
|
||||
// db.addCollection('features', {
|
||||
// unique: ["properties.icao"], autoupdate: true
|
||||
// });
|
||||
// features = db.getCollection('features');
|
||||
// }
|
||||
// console.log("Loaded " + features.count() + " features");
|
||||
// resolve(features);
|
||||
// });
|
||||
}
|
||||
else {
|
||||
resolve(features);
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
function getAirport(apts, icao) {
|
||||
console.log("Getting Airport " + icao);
|
||||
var results = apts.where(function (f) {
|
||||
return f.properties['icao'] === icao;
|
||||
});
|
||||
var feature;
|
||||
if (results.length == 0) {
|
||||
feature = {
|
||||
"type": "Feature",
|
||||
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0 },
|
||||
'geometry': {
|
||||
"type": "Point"
|
||||
}
|
||||
};
|
||||
feature = apts.insert(feature);
|
||||
// apts.update(feature);
|
||||
console.log("Added New");
|
||||
console.log(JSON.stringify(feature));
|
||||
return feature;
|
||||
}
|
||||
else {
|
||||
console.debug("retrieved " + JSON.stringify(results[0]));
|
||||
return results[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function save() {
|
||||
if (!features || !features.data)
|
||||
return;
|
||||
var mappedData = features.data.map(function (f) {
|
||||
delete f.meta;
|
||||
delete f.$loki;
|
||||
if (f.properties.airlines) {
|
||||
f.properties.airlines = f.properties.airlines.join(' ');
|
||||
}
|
||||
else {
|
||||
f.properties.airlines = [];
|
||||
}
|
||||
|
||||
return f;
|
||||
});
|
||||
|
||||
mappedData = mappedData.filter(feature => feature.properties['twr'] || feature.properties['threshold']);
|
||||
|
||||
//console.log(mappedData);
|
||||
var featureCollection = { type: "FeatureCollection", features: mappedData };
|
||||
|
||||
let data = JSON.stringify(featureCollection, null, 2);
|
||||
fs.writeFileSync('airports.json', data);
|
||||
// db.saveDatabase(function (err) {
|
||||
// if (err) {
|
||||
// console.error(err);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/* eslint-disable */
|
||||
const lineReader = require('readline');
|
||||
const fs = require('fs');
|
||||
const airports = require('./airports');
|
||||
|
||||
var scanMethods = {
|
||||
1: (l, apts) => {
|
||||
console.log('Airport:', l);
|
||||
|
||||
var airportFeature = airports.getAirport(apts, l[4]);
|
||||
console.log(JSON.stringify(airportFeature));
|
||||
airportFeature.properties.name = l.slice(5).join(' ').replace('\t', ' ');
|
||||
console.debug(airportFeature.properties.name);
|
||||
// apts.update(airportFeature);
|
||||
},
|
||||
99: (l) => {
|
||||
console.log('Finished');
|
||||
}
|
||||
};
|
||||
|
||||
function scan (f, apts) {
|
||||
console.log(f);
|
||||
lineReader.createInterface({
|
||||
input: fs.createReadStream(f)
|
||||
}).on('line', function (line) {
|
||||
var fields = line.split(/[ ]+/);
|
||||
// var fields = line.match('([0-9]+)');
|
||||
if (fields == null)
|
||||
return;
|
||||
var scanMethod = scanMethods[fields[0]];
|
||||
if (scanMethod != null) {
|
||||
scanMethod(fields, apts);
|
||||
}
|
||||
else {
|
||||
if (fields[0] == '99') {
|
||||
lineReader.close();
|
||||
}
|
||||
// console.log('Ignored:', line);
|
||||
}
|
||||
}).on('error', function (err) {
|
||||
console.log(err);
|
||||
lr.close();
|
||||
}).on('close', function () {
|
||||
console.log("End");
|
||||
airports.save();
|
||||
});
|
||||
}
|
||||
|
||||
// export default { scan, name }
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/* eslint-disable */
|
||||
const lineReader = require('readline');
|
||||
|
||||
var scanMethods = {
|
||||
1: (l, apts) => {
|
||||
console.log('Airport:', l);
|
||||
saveName(apts, l[4], l.slice(5).join(' ').replace('\t', ' '));
|
||||
},
|
||||
99: (l) => {
|
||||
console.log('Finished');
|
||||
}
|
||||
};
|
||||
|
||||
async function saveName(features, icao, name) {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
|
||||
var transaction = features.transaction("airports", "readwrite");
|
||||
var objectStore = transaction.objectStore("airports");
|
||||
var objectStoreRequest = objectStore.get(icao);
|
||||
|
||||
objectStoreRequest.onsuccess = function (event) {
|
||||
console.log(event);
|
||||
var feature = objectStoreRequest.result;
|
||||
if (!feature) {
|
||||
feature = {
|
||||
"type": "Feature",
|
||||
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0, airlines: [] },
|
||||
'geometry': {
|
||||
"type": "Point"
|
||||
}
|
||||
};
|
||||
}
|
||||
feature.properties.name = name;
|
||||
feature.properties.icao = icao;
|
||||
console.log("ICAO : " + feature.properties.icao);
|
||||
// Create another request that inserts the item back into the database
|
||||
var updateAirportRequest = objectStore.put(feature);
|
||||
|
||||
// Log the transaction that originated this request
|
||||
console.log("The transaction that originated this request is " + updateAirportRequest.updateAirportRequest);
|
||||
|
||||
// When this new request succeeds, run the displayData() function again to update the display
|
||||
updateAirportRequest.onsuccess = function () {
|
||||
console.log("Stored");
|
||||
resolve();
|
||||
};
|
||||
updateAirportRequest.onerror = function (event) {
|
||||
console.log("Error " + event);
|
||||
reject(event);
|
||||
};
|
||||
};
|
||||
objectStoreRequest.onerror = function (event) {
|
||||
console.log("Error " + event);
|
||||
reject(event);
|
||||
};
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
function scanAPTIntoDB(f, apts) {
|
||||
console.log(f);
|
||||
lineReader.createInterface({
|
||||
input: fs.createReadStream(f)
|
||||
}).on('line', function (line) {
|
||||
var fields = line.split(/[ ]+/);
|
||||
// var fields = line.match('([0-9]+)');
|
||||
if (fields == null)
|
||||
return;
|
||||
var scanMethod = scanMethods[fields[0]];
|
||||
if (scanMethod != null) {
|
||||
scanMethod(fields, apts);
|
||||
}
|
||||
else {
|
||||
if (fields[0] == '99') {
|
||||
lineReader.close();
|
||||
}
|
||||
// console.log('Ignored:', line);
|
||||
}
|
||||
}).on('error', function (err) {
|
||||
console.log(err);
|
||||
lr.close();
|
||||
}).on('close', function () {
|
||||
console.log("End");
|
||||
apts.close();
|
||||
});
|
||||
}
|
||||
|
||||
// export default { scan, name }
|
||||
|
||||
@@ -0,0 +1,386 @@
|
||||
|
||||
/* eslint-disable */
|
||||
// const fs = require('fs');
|
||||
// const path = require('path');
|
||||
// const math = require('mathjs');
|
||||
// const util = require('util');
|
||||
// const airports = require('./airports.js');
|
||||
// const homedir = require('os').homedir();
|
||||
// const apt = require('apt.js');
|
||||
|
||||
async function asyncForEach(array, callback) {
|
||||
console.log("Len " + array.length);
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
try {
|
||||
var res = await callback(array[index], index, array);
|
||||
console.log("Index " + index + " " + res);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scanAPT_Old(p) {
|
||||
return airports.init().then(features => {
|
||||
var d = path.join(homedir, 'Documents/apt.dat');
|
||||
console.log(d);
|
||||
apt.scan(d, features);
|
||||
});
|
||||
}
|
||||
|
||||
async function waitFor(milliseconds) {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
||||
async function scanGroundnetFiles(p, features) {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
try {
|
||||
console.log('Start Groundnets ' + p);
|
||||
var files = traverseDir(p);
|
||||
console.log(files);
|
||||
|
||||
asyncForEach(files, async f => {
|
||||
//await waitFor(5000);
|
||||
try {
|
||||
var text = await readGroundnet(f, features);
|
||||
console.log(text);
|
||||
resolve(text);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
}
|
||||
}).then(t => {
|
||||
console.log("Finished");
|
||||
features.close();
|
||||
resolve();
|
||||
}).catch(reason => {
|
||||
console.log("Crashed");
|
||||
console.log(reason);
|
||||
features.close()
|
||||
});
|
||||
|
||||
//walkDir(p, f => { readGroundnet(f, features) });
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function scanTrafficIntoDB(p, features) {
|
||||
try {
|
||||
console.log('Start Traffic ' + p + ' ' + features);
|
||||
var objectStore = features.transaction("airports").objectStore("airports");
|
||||
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
var cursor = event.target.result;
|
||||
if (cursor) {
|
||||
feature.value.properties.flights = 0
|
||||
feature.value.properties.airlines = [];
|
||||
console.log("Name for SSN " + cursor.key + " is " + cursor.value.name);
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
console.log("No more entries!");
|
||||
}
|
||||
};
|
||||
walkDir(p, f => { readAI(f, features) });
|
||||
console.log("Closing");
|
||||
features.close();
|
||||
console.log("End Traffic");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
function traverseDir(dir) {
|
||||
var result = [];
|
||||
fs.readdirSync(dir).forEach(file => {
|
||||
let fullPath = path.join(dir, file);
|
||||
if (fs.lstatSync(fullPath).isDirectory()) {
|
||||
console.log(fullPath);
|
||||
var children = traverseDir(fullPath);
|
||||
result = result.concat(children);
|
||||
} else {
|
||||
console.log(fullPath);
|
||||
result.push(fullPath);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function walkDir(dir, callback) {
|
||||
fs.readdirSync(dir).forEach(f => {
|
||||
try {
|
||||
let dirPath = path.join(dir, f);
|
||||
let isDirectory = fs.statSync(dirPath).isDirectory();
|
||||
isDirectory ?
|
||||
walkDir(dirPath, callback) : callback(path.join(dir, f));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function readAI(f, apts) {
|
||||
try {
|
||||
console.log(path.basename(f));
|
||||
// Reset
|
||||
var airline = path.basename(f).match('([^.]+)');
|
||||
if (airline == null)
|
||||
return;
|
||||
var xmlSource = fs.readFileSync(f, 'utf8').toString();
|
||||
console.debug("read " + path.basename(f));
|
||||
// var doc = new domParser().parseFromString(xmlSource );
|
||||
// console.log("parsed ");
|
||||
// var flights = xpath.select("/trafficlist/flight", doc);
|
||||
// console.log("selected flight ");
|
||||
// console.log(flights);
|
||||
var dat = tXml(xmlSource);
|
||||
// console.log(dat);
|
||||
console.log(dat[0].children[0]);
|
||||
|
||||
var flightNodes = dat[0].children[0].children.filter(e => e.tagName === 'flight');
|
||||
flightNodes = tXml.simplify(flightNodes);
|
||||
|
||||
console.log(flightNodes.flight);
|
||||
|
||||
console.log("Departure flights " + flightNodes.flight.length);
|
||||
|
||||
var merged = new Array();
|
||||
|
||||
flightNodes.flight.map(n => {
|
||||
merged.push(n.departure.port);
|
||||
merged.push(n.arrival.port);
|
||||
}).sort();
|
||||
|
||||
var counts = {};
|
||||
for (var i = 0; i < merged.length; i++) {
|
||||
counts[merged[i]] = 1 + (counts[merged[i]] || 0);
|
||||
}
|
||||
|
||||
for (var key in counts) {
|
||||
store(key, airline[0], counts[key]);
|
||||
}
|
||||
|
||||
// var flights = xpath.select("/trafficlist/flight/departure/port/text()", doc);
|
||||
// console.log(nodes);
|
||||
// console.log(nodes);
|
||||
// nodes = xpath.select("/trafficlist/flight/arrival/port/text()", doc);
|
||||
// console.log(nodes);
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store airline info into DB
|
||||
* @param {*} icao
|
||||
* @param {*} airline
|
||||
* @param {*} value
|
||||
*/
|
||||
|
||||
function store(icao, airline, value) {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
console.log("Airport " + icao + " has " + value + " flights");
|
||||
// Make a request to get a record by key from the object store
|
||||
var transaction = features.transaction("airports", "readwrite");
|
||||
var objectStore = transaction.objectStore("airports");
|
||||
var objectStoreRequest = objectStore.get(icao);
|
||||
|
||||
objectStoreRequest.onsuccess = function (event) {
|
||||
console.log(event);
|
||||
var feature = objectStoreRequest.result;
|
||||
if (!feature) {
|
||||
feature = createFeature(icao);
|
||||
}
|
||||
feature.properties.flights += value;
|
||||
console.log("Airline " + airline);
|
||||
feature.properties.airlines.push(airline);
|
||||
feature.properties.airlines.sort();
|
||||
console.log("ICAO : " + feature.properties.icao + " Flights : " + feature.properties.flights);
|
||||
// Create another request that inserts the item back into the database
|
||||
var updateAirportRequest = objectStore.put(feature);
|
||||
|
||||
// Log the transaction that originated this request
|
||||
console.log("The transaction that originated this request is " + updateAirportRequest);
|
||||
|
||||
// When this new request succeeds, run the displayData() function again to update the display
|
||||
updateAirportRequest.onsuccess = function () {
|
||||
console.log("Stored");
|
||||
resolve();
|
||||
};
|
||||
updateAirportRequest.onerror = function (event) {
|
||||
console.log("Error storing " + event);
|
||||
reject(event);
|
||||
};
|
||||
};
|
||||
objectStoreRequest.onerror = function (event) {
|
||||
console.log("Error " + event);
|
||||
reject(event);
|
||||
};
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* read a groundnet xml file
|
||||
* @param {*} f
|
||||
* @param {*} apts
|
||||
*/
|
||||
|
||||
async function readGroundnet(f, features) {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var filename = path.basename(f).match('^([^.]+)\\.([^.]+)\\.([^.]+)');
|
||||
if (filename == null) {
|
||||
resolve("File didn't match");
|
||||
}
|
||||
else {
|
||||
console.log('Parsing ' + f);
|
||||
fs.readFile(f, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.log('Error reading file ' + err);
|
||||
reject(err);
|
||||
}
|
||||
console.log(data);
|
||||
var dat = tXml.simplify(tXml(data));
|
||||
console.log('Simplified ' + filename);
|
||||
|
||||
if (dat['?xml']) {
|
||||
console.log("parsed " + f);
|
||||
|
||||
var transaction = features.transaction("airports", "readonly");
|
||||
// report on the success of the transaction completing, when everything is done
|
||||
transaction.oncomplete = function (event) {
|
||||
console.log('Read Transaction complete ' + event);
|
||||
};
|
||||
|
||||
transaction.onerror = function (event) {
|
||||
console.log('Transaction error ' + event);
|
||||
};
|
||||
var objectStore = transaction.objectStore("airports");
|
||||
var objectStoreRequest = objectStore.get(filename[1]);
|
||||
|
||||
objectStoreRequest.onsuccess = function (event) {
|
||||
console.log(dat['?xml'].groundnet);
|
||||
var feature = event.result;
|
||||
console.log("Got Airport : " + feature);
|
||||
if (!feature) {
|
||||
feature = createFeature(filename[1]);
|
||||
}
|
||||
|
||||
if (filename[2] == 'threshold') {
|
||||
try {
|
||||
console.log('threshold : ' + filename[1]);
|
||||
var nodes = dat['?xml'].PropertyList.runway;
|
||||
if (nodes.threshold == 0) {
|
||||
console.log("No Runway");
|
||||
resolve();
|
||||
}
|
||||
nodes.forEach(r => {
|
||||
var lat1 = parseFloat(r.threshold[0].lat);
|
||||
var lon1 = parseFloat(r.threshold[0].lon);
|
||||
var lat2 = parseFloat(r.threshold[1].lat);
|
||||
var lon2 = parseFloat(r.threshold[1].lon);
|
||||
if (!feature.geometry.coordinates) {
|
||||
feature.geometry.coordinates = [mean(lon1, lon2), mean(lat1, lat2)];
|
||||
console.log(feature.geometry.coordinates);
|
||||
}
|
||||
});
|
||||
feature.properties['threshold'] = true;
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} else if (filename[2] == 'twr') {
|
||||
try {
|
||||
console.log('twr : ' + filename[1]);
|
||||
var nodes = dat['?xml'].PropertyList.tower.twr;
|
||||
if (nodes.length == 0) {
|
||||
console.log("No Tower");
|
||||
resolve();
|
||||
}
|
||||
var lat = parseFloat(nodes.lat);
|
||||
var lon = parseFloat(nodes.lon);
|
||||
feature.properties['twr'] = true;
|
||||
feature.geometry.coordinates = [lon, lat];
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} else if (filename[2] == 'groundnet') {
|
||||
console.log('groundnet : ' + filename[1]);
|
||||
var nodes = dat['?xml'].groundnet.TaxiNodes;
|
||||
feature['properties']['groundnet'] = nodes ? true : false;
|
||||
var nodes = dat['?xml'].groundnet.Parking;
|
||||
feature['properties']['parking'] = nodes ? true : false;
|
||||
} else if (filename[2] == 'ils') {
|
||||
console.log('ils : ' + filename[1]);
|
||||
if (dat['?xml'].PropertyList.runways) {
|
||||
var nodes = dat['?xml'].PropertyList.runways.ils;
|
||||
feature.properties['ils'] = nodes !== undefined;
|
||||
}
|
||||
}
|
||||
var transaction = features.transaction("airports", "readwrite");
|
||||
// report on the success of the transaction completing, when everything is done
|
||||
transaction.oncomplete = function (event) {
|
||||
console.log('Write Transaction complete ' + event);
|
||||
resolve("Stored " + filename[1]);
|
||||
};
|
||||
|
||||
transaction.onerror = function (event) {
|
||||
console.log('Transaction error ' + event);
|
||||
};
|
||||
var objectStore = transaction.objectStore("airports");
|
||||
var updateAirportRequest = objectStore.put(feature);
|
||||
|
||||
// Log the transaction that originated this request
|
||||
console.log("The transaction that originated this request is " + updateAirportRequest.transaction);
|
||||
|
||||
// When this new request succeeds, run the displayData() function again to update the display
|
||||
updateAirportRequest.onsuccess = function () {
|
||||
console.log("Stored");
|
||||
};
|
||||
updateAirportRequest.onerror = function (event) {
|
||||
console.log("Error storing " + event);
|
||||
reject(event);
|
||||
};
|
||||
}
|
||||
objectStoreRequest.onerror = function (event) {
|
||||
console.log("Read Errpr : " + event);
|
||||
resolve(event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
resolve('No root');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
function createFeature(icao) {
|
||||
return {
|
||||
"type": "Feature",
|
||||
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0, airlines: [] },
|
||||
'geometry': {
|
||||
"type": "Point"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function mean(coord1, coord2) {
|
||||
|
||||
return (coord1 + coord2) / 2;
|
||||
}
|
||||
// export default { scanAPT, scanTraffic, scanGroundnet }
|
||||
@@ -0,0 +1,81 @@
|
||||
/* eslint-disable */
|
||||
const winURL = process.env.NODE_ENV === 'development'
|
||||
? `http://localhost:9080/src/renderer/utils/`
|
||||
: `file://D:/GIT/flightgear-airports/src/renderer/utils/`
|
||||
|
||||
var scanner = importScripts(`${winURL}scan.js`);
|
||||
var apt = importScripts(`${winURL}apt.js`);
|
||||
var path = require('path');
|
||||
const fs = require('fs');
|
||||
const homedir = require('os').homedir();
|
||||
var airports = importScripts(`${winURL}airports.js`);
|
||||
importScripts('../txml/tXml.min.js');
|
||||
|
||||
function errorReceiver(event) {
|
||||
throw event.data;
|
||||
}
|
||||
|
||||
onmessage = function (event) {
|
||||
postMessage('scanStarted');
|
||||
console.log(event.data);
|
||||
if (event.data === 'scan') {
|
||||
scanGroundnet().then(result => {
|
||||
console.log("DONE Scanning");
|
||||
postMessage('DONE', 'this');
|
||||
// event.origin.webContents.send('scanFinished');
|
||||
}
|
||||
).catch(result => {
|
||||
console.log('Crashed');
|
||||
console.log(result);
|
||||
});
|
||||
} else if (event.data === 'scanai') {
|
||||
scanai().then(result => {
|
||||
console.log("DONE Scanning");
|
||||
postMessage('DONE');
|
||||
// event.origin.webContents.send('scanFinished');
|
||||
}
|
||||
).catch(result => {
|
||||
console.log('Crashed');
|
||||
console.log(result);
|
||||
});
|
||||
}
|
||||
else if (event.data === 'scanapt') {
|
||||
scanAPT().then(result => {
|
||||
console.log("DONE Scanning");
|
||||
postMessage('DONE');
|
||||
// event.origin.webContents.send('scanFinished');
|
||||
}
|
||||
).catch(result => {
|
||||
console.log('Crashed');
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
async function scanGroundnet() {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
return initDB().then(features => {
|
||||
var d = path.join(homedir, '/Documents/Flightgear/main/Airports/A');
|
||||
scanGroundnetFiles(d, features);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
function scanai() {
|
||||
return initDB().then(features => {
|
||||
scanTrafficIntoDB("C:/GIT/fgmeta/fgdata/AI/Traffic", features);
|
||||
});
|
||||
}
|
||||
|
||||
async function scanAPT() {
|
||||
return initDB().then(features => {
|
||||
var d = path.join(homedir, 'Documents/apt.dat');
|
||||
scanAPTIntoDB(d, features);
|
||||
features.close();
|
||||
console.log("Closed DB");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user