Scan Progress

This commit is contained in:
portree_kid 2020-02-18 21:05:10 +01:00
parent 07c7caff2f
commit 88f15c3e61
11 changed files with 435 additions and 192 deletions

View File

@ -5,7 +5,8 @@
<ul role="tablist"> <!-- top aligned tabs -->
<li><a href="#home" role="tab"><i class="fa fa-bars"></i></a></li>
<li><a href="#edit" role="tab"><i class="fas fa-edit"></i></a></li>
<li><a href="#scan" role="tab"><i class="fa fa-search"></i></a></li>
<li><a href="#search" role="tab"><i class="fa fa-search"></i></a></li>
<li><a href="#scan" role="tab"><i class="fa fa-sync"></i></a></li>
</ul>
<ul role="tablist"> <!-- bottom aligned tabs -->
@ -32,6 +33,9 @@
<ArcEdit></ArcEdit>
<NodeEdit></NodeEdit>
</div>
<div class="leaflet-sidebar-pane" id="search">
<Search></Search>
</div>
<div class="leaflet-sidebar-pane" id="scan">
<RunScan></RunScan>
</div>
@ -53,11 +57,12 @@
import NodeEdit from './NodeEdit'
import SettingsPanel from './SettingsPanel'
import RunScan from './RunScan'
import Search from './Search'
import FileSelect from './FileSelect'
export default {
name: 'leaflet-sidebar',
components: { AirportEdit, ArcEdit, NodeEdit, GroundnetEdit, SettingsPanel, RunScan, FileSelect },
components: { AirportEdit, ArcEdit, NodeEdit, GroundnetEdit, SettingsPanel, RunScan, FileSelect, Search },
props: [],
mounted () {
this.add()

View File

@ -7,13 +7,14 @@
</div>
</h1>
<el-container direction="vertical">
<el-button @click="scanAPT()">Scan APT File</el-button>
<el-button @click="scanGroundnets()">Scan Groundnet Files</el-button>
<el-button @click="scanTraffic()">Scan Traffic Files</el-button>
<el-input placeholder="Search" v-model="searchterm" class="input-with-select">
</el-input>
<el-progress :percentage="Number(((progress / max)*100).toPrecision(3))" v-if="max > 0"></el-progress>
<!--<el-progress :percentage="progress / max"></el-progress>-->
<!--{{max}}&nbsp;{{progress}}-->
<el-button @click="scanAPT()" :disabled="scanning">Scan APT File</el-button>
<el-button @click="scanGroundnets()" :disabled="scanning">Scan Groundnet Files</el-button>
<el-button @click="scanTraffic()" :disabled="scanning">Scan Traffic Files</el-button>
</el-container>
<li v-for="item in searched" v-bind:key="item.icao"><el-link type="primary" @click="goto(item.icao)">{{ item.icao }} {{ item.name }}</el-link></li>
</div>
</template>
@ -21,6 +22,7 @@
// import scanner from '../utils/scan'
import fileUrl from 'file-url'
import {Table, TableColumn} from 'element-ui'
// import Vue from 'vue'
const path = require('path')
@ -32,26 +34,35 @@
mounted () {
},
beforeDestroy () {
if (this.polling != null) {
clearInterval(this.polling)
}
},
data () {
// this.$store.dispatch('getAirportsUnfiltered')
return {searchterm: this.searchterm}
},
methods: {
goto (icao) {
console.log(icao)
let airports = this.$store.state.Airports.airports
.filter(a => a.properties.icao.match(icao))
if (airports.length > 0) {
this.$store.commit('CENTER', [airports[0].geometry.coordinates[1], airports[0].geometry.coordinates[0]])
return {
max: 0,
progress: 0,
scanning: false,
polling: null,
worker: null
}
},
formatter (row, column) {
console.log('Row ' + row)
return row
methods: {
pollData () {
var workery = this.worker
var view = this
this.polling = setInterval(() => {
if (workery != null) {
view.max = Number(workery.max)
view.progress = Number(workery.progress)
view.scanning = Boolean(workery.scanning)
}
}, 1000)
},
scanAPT () {
try {
this.scanning = true
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/src/renderer/utils/worker.js`
: `file://${__dirname}/worker.js`
@ -60,8 +71,13 @@
const worker = new Worker(winURL)
console.log(fileUrl('src/renderer/utils/worker.js'))
worker.scanning = this.scanning
worker.max = this.max
worker.progress = 0
// var worker = new Worker(fileUrl('src/renderer/utils/worker.js'))
this.worker = worker
worker.postMessage(['scanapt'])
this.pollData()
// the reply
var store = this.$store
worker.onmessage = function (e) {
@ -69,8 +85,17 @@
console.log('DONE')
store.dispatch('getAirports')
worker.terminate()
clearInterval(this.polling)
this.scanning = false
} else if (e.data.length > 0) {
if (e.data[0] === 'max') {
this.max = e.data[1]
}
console.log(e.data)
if (e.data[0] === 'progress') {
this.progress = e.data[1]
}
}
// console.log(e.data)
}
} catch (err) {
console.error(err)
@ -78,6 +103,7 @@
},
scanGroundnets () {
try {
this.scanning = true
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/src/renderer/utils/worker.js`
: `file://${__dirname}/worker.js`
@ -86,7 +112,13 @@
const worker = new Worker(winURL)
console.log(fileUrl('src/renderer/utils/worker.js'))
worker.scanning = this.scanning
worker.max = this.max
worker.progress = 0
this.worker = worker
worker.postMessage(['scan', this.$store.state.Settings.settings.airportsDirectory])
this.pollData()
// the reply
var store = this.$store
worker.onmessage = function (e) {
@ -94,8 +126,18 @@
console.log('DONE')
store.dispatch('getAirports')
worker.terminate()
clearInterval(this.polling)
this.scanning = false
} else if (e.data.length > 0) {
if (e.data[0] === 'max') {
this.max = e.data[1]
}
console.log(e.data)
if (e.data[0] === 'progress') {
this.scanning = false
this.progress += e.data[1]
}
}
// console.log(e.data)
}
} catch (err) {
console.error(err)
@ -104,6 +146,7 @@
scanTraffic () {
// let flightgearDirectory = this.$store.state.settings.flightgearDirectory
try {
this.scanning = true
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/src/renderer/utils/worker.js`
: `file://${__dirname}/worker.js`
@ -111,16 +154,31 @@
const worker = new Worker(winURL)
console.log(fileUrl('src/renderer/utils/worker.js'))
worker.postMessage(['scanai', this.$store.state.Settings.settings.flightgearDirectory])
this.scanning = true
worker.scanning = this.scanning
worker.max = this.max
worker.progress = this.progress
this.worker = worker
worker.postMessage(['scanai', this.$store.state.Settings.settings.flightgearDirectory_traffic])
this.pollData()
// the reply
var store = this.$store
worker.onmessage = function (e) {
if (e.data === 'DONE') {
this.scanning = false
console.log('DONE')
clearInterval(this.polling)
store.dispatch('getAirports')
worker.terminate()
} else if (e.data.length > 0) {
if (e.data[0] === 'max') {
this.max = e.data[1]
}
console.log(e.data)
if (e.data[0] === 'progress') {
this.progress += e.data[1]
}
}
// console.log(e)
}
} catch (err) {
console.error(err)
@ -128,14 +186,11 @@
}
},
computed: {
searched: function () {
console.log(this.searchterm)
let searchRegex = new RegExp(this.searchterm, 'i')
return this.$store.state.Airports.airports
.filter(a => searchRegex.test(a.properties.icao) || searchRegex.test(a.properties.name))
// .map(a => console.log(a.properties))
.map(a => ({ icao: a.properties.icao, name: a.properties.name }))
}
}
}
</script>
<style>
.el-button+.el-button {
margin-left: 0px;
}
</style>

View File

@ -0,0 +1,138 @@
<template>
<div>
<h1 class="leaflet-sidebar-header">
Search
<div class="leaflet-sidebar-close">
<i class="fa fa-caret-left"></i>
</div>
</h1>
<el-container direction="vertical">
<el-input placeholder="Search" v-model="searchterm" class="input-with-select">
</el-input>
</el-container>
<li v-for="item in searched" v-bind:key="item.icao"><el-link type="primary" @click="goto(item.icao)">{{ item.icao }} {{ item.name }}</el-link></li>
</div>
</template>
<script lang="js">
// import scanner from '../utils/scan'
import fileUrl from 'file-url'
import {Table, TableColumn} from 'element-ui'
const path = require('path')
export default {
name: 'search',
components: { [Table.name]: Table,
[TableColumn.name]: TableColumn},
props: [],
mounted () {
},
beforeDestroy () {
},
data () {
// this.$store.dispatch('getAirportsUnfiltered')
return {searchterm: this.searchterm}
},
methods: {
goto (icao) {
console.log(icao)
let airports = this.$store.state.Airports.airports
.filter(a => a.properties.icao.match(icao))
if (airports.length > 0) {
this.$store.commit('CENTER', [airports[0].geometry.coordinates[1], airports[0].geometry.coordinates[0]])
}
},
formatter (row, column) {
console.log('Row ' + row)
return row
},
scanAPT () {
try {
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/src/renderer/utils/worker.js`
: `file://${__dirname}/worker.js`
console.log('make a worker: ', path.resolve(__dirname, 'worker.js'))
const worker = new Worker(winURL)
console.log(fileUrl('src/renderer/utils/worker.js'))
// var worker = new Worker(fileUrl('src/renderer/utils/worker.js'))
worker.postMessage(['scanapt'])
// the reply
var store = this.$store
worker.onmessage = function (e) {
if (e.data === 'DONE') {
console.log('DONE')
store.dispatch('getAirports')
worker.terminate()
}
console.log(e.data)
}
} catch (err) {
console.error(err)
}
},
scanGroundnets () {
try {
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/src/renderer/utils/worker.js`
: `file://${__dirname}/worker.js`
console.log('make a worker: ', path.resolve(__dirname, 'worker.js'))
const worker = new Worker(winURL)
console.log(fileUrl('src/renderer/utils/worker.js'))
worker.postMessage(['scan', this.$store.state.Settings.settings.airportsDirectory])
// the reply
var store = this.$store
worker.onmessage = function (e) {
if (e.data === 'DONE') {
console.log('DONE')
store.dispatch('getAirports')
worker.terminate()
}
console.log(e.data)
}
} catch (err) {
console.error(err)
}
},
scanTraffic () {
// let flightgearDirectory = this.$store.state.settings.flightgearDirectory
try {
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/src/renderer/utils/worker.js`
: `file://${__dirname}/worker.js`
console.log('make a worker: ', path.resolve(__dirname, 'worker.js'))
const worker = new Worker(winURL)
console.log(fileUrl('src/renderer/utils/worker.js'))
worker.postMessage(['scanai', this.$store.state.Settings.settings.flightgearDirectory])
// the reply
var store = this.$store
worker.onmessage = function (e) {
if (e.data === 'DONE') {
console.log('DONE')
store.dispatch('getAirports')
worker.terminate()
}
console.log(e.data)
}
} catch (err) {
console.error(err)
}
}
},
computed: {
searched: function () {
console.log(this.searchterm)
let searchRegex = new RegExp(this.searchterm, 'i')
return this.$store.state.Airports.airports
.filter(a => searchRegex.test(a.properties.icao) || searchRegex.test(a.properties.name))
// .map(a => console.log(a.properties))
.map(a => ({ icao: a.properties.icao, name: a.properties.name }))
}
}
}
</script>

View File

@ -27,6 +27,12 @@
<el-col :span="2">
</el-col>
</el-row>
<el-row>
<el-col :span="7">Traffic Directory</el-col>
<el-col :span="15">{{ Traffic_directory }}</el-col>
<el-col :span="2">
</el-col>
</el-row>
<el-row>
<el-col :span="7">APT File</el-col>
<el-col :span="15">{{ apt_file }}</el-col>
@ -68,6 +74,9 @@
AI_directory: function () {
return this.$store.state.Settings.settings.flightgearDirectory_ai
},
Traffic_directory: function () {
return this.$store.state.Settings.settings.flightgearDirectory_traffic
},
apt_file: function () {
return this.$store.state.Settings.settings.flightgearDirectory_apt
},

View File

@ -70,7 +70,6 @@ export default {
},
async saveAirport(airport) {
let db = await this.getDb();
return new Promise(resolve => {

View File

@ -10,6 +10,7 @@ const mutations = {
'FLIGHTGEAR_DIRECTORY' (state, flightgearDirectory) {
state.settings.flightgearDirectory = flightgearDirectory
state.settings.flightgearDirectory_ai = flightgearDirectory + '/data/AI'
state.settings.flightgearDirectory_traffic = flightgearDirectory + '/data/AI/Traffic'
state.settings.flightgearDirectory_apt = flightgearDirectory + '/data/Airports/apt.dat.gz'
},
'AIPORTS_DIRECTORY' (state, airportsDirectory) {

View File

@ -21,10 +21,6 @@ async function initDB() {
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" });
@ -36,15 +32,15 @@ async function initDB() {
var desiredKeyPathForMyIndex = "properties.icao";
console.log(indexNames);
if(indexNames.contains('myIndexName')) {
var myIndex = objectStore.index('myIndexName');
if(indexNames.contains('icaoIndex')) {
var myIndex = objectStore.index('icaoIndex');
var currentKeyPath = myIndex.keyPath;
if(currentKeyPath != desiredKeyPathForMyIndex) {
objectStore.deleteIndex('myIndexName');
objectStore.createIndex('myIndexName', desiredKeyPathForMyIndex);
objectStore.deleteIndex('icaoIndex');
objectStore.createIndex('icaoIndex', desiredKeyPathForMyIndex);
}
} else {
objectStore.createIndex('myIndexName', desiredKeyPathForMyIndex);
objectStore.createIndex('icaoIndex', desiredKeyPathForMyIndex);
}
}

View File

@ -1,20 +1,19 @@
/* eslint-disable */
const lineReader = require('readline');
var icao;
var scanMethods = {
1: (l, apts) => {
console.log('Airport:', l);
logger('info', 'Airport:', l);
icao = l[4];
saveName(apts, l[4], l.slice(5).join(' ').replace('\t', ' '));
},
14: (l, apts) => {
console.log('Viewport:', l);
logger('info','Viewport:', l);
saveCoordinates(apts, icao, l[1], l[2]);
},
99: (l) => {
console.log('Finished');
logger('info','Finished');
}
};
@ -23,11 +22,12 @@ async function saveName(features, icao, name) {
var transaction = features.transaction("airports", "readwrite");
var objectStore = transaction.objectStore("airports");
var objectStoreRequest = objectStore.get(icao);
var index = objectStore.index('icaoIndex');
var objectStoreRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) {
console.log(event);
var feature = objectStoreRequest.result;
logger('info',event);
var feature = event.target.result;
if (!feature) {
feature = {
"type": "Feature",
@ -39,25 +39,25 @@ async function saveName(features, icao, name) {
}
feature.properties.name = name;
feature.properties.icao = icao;
console.log("ICAO : " + feature.properties.icao);
logger('info',"ICAO : " + feature.properties.icao + " Name : " + name );
// 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);
logger('info',"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");
logger('info',"Stored");
resolve();
};
updateAirportRequest.onerror = function (event) {
console.log("Error " + event);
logger('info',"Error " + event);
reject(event);
};
};
objectStoreRequest.onerror = function (event) {
console.log("Error " + event);
logger('info',"Error " + event);
reject(event);
};
});
@ -69,11 +69,12 @@ async function saveCoordinates(features, icao, lat, lon) {
var transaction = features.transaction("airports", "readwrite");
var objectStore = transaction.objectStore("airports");
var objectStoreRequest = objectStore.get(icao);
var index = objectStore.index('icaoIndex');
var objectStoreRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) {
console.log(event);
var feature = objectStoreRequest.result;
logger('info',event);
var feature = event.target.result;
if (!feature) {
feature = {
"type": "Feature",
@ -84,25 +85,25 @@ async function saveCoordinates(features, icao, lat, lon) {
};
}
feature.geometry.coordinates = [lon, lat];
console.log("ICAO : " + feature.properties.icao);
logger('info',"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);
logger('info',"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");
updateAirportRequest.onsuccess = function (event) {
logger('info',"Stored", event);
resolve();
};
updateAirportRequest.onerror = function (event) {
console.log("Error " + event);
logger('info',"Error ", event);
reject(event);
};
};
objectStoreRequest.onerror = function (event) {
console.log("Error " + event);
logger('info',"Error ", event);
reject(event);
};
});
@ -112,9 +113,21 @@ async function saveCoordinates(features, icao, lat, lon) {
async function scanAPTIntoDB(f, features) {
var promise = new Promise(function (resolve, reject) {
try {
var i;
var count = 0;
var postMessage = this.postMessage;
require('fs').createReadStream(f)
.on('data', function(chunk) {
for (i=0; i < chunk.length; ++i)
if (chunk[i] == 10) count++;
})
.on('end', function() {
postMessage(['max', count]);
console.log('Line Count',count);
lineReader.createInterface({
input: fs.createReadStream(f)
}).on('line', function (line) {
postMessage(['progress', 1]);
var fields = line.split(/[ ]+/);
// var fields = line.match('([0-9]+)');
if (fields == null)
@ -127,19 +140,21 @@ async function scanAPTIntoDB(f, features) {
if (fields[0] == '99') {
lineReader.close();
}
// console.log('Ignored:', line);
// logger('info','Ignored:', line);
}
}).on('error', function (err) {
console.log(err);
logger('info',err);
lr.close();
}).on('close', function () {
console.log("End");
logger('info',"End");
features.close();
this.postMessage('DONE');
postMessage('DONE');
});
});
} catch (error) {
console.log(error);
console.error(error);
reject(error);
this.postMessage('DONE');
}
});
}

View File

@ -0,0 +1,21 @@
var util = require("util")
const d = new Date();
const fName = 'scan_' + d.getFullYear()
+ d.getMonth()
+ d.getDay()
+ d.getHours()
+ d.getMinutes()
+ d.getSeconds()
+ d.getMilliseconds() + '.log';
var logStream = require('fs').createWriteStream( fName, {autoClose: true});
var logger = function (level, msg, o) {
var d = new Date();
logStream.write(d.toUTCString() + '|' + level + ' | ' + msg + '\r\n');
if (o != undefined) {
logStream.write( util.inspect(o,{depth: 2}) + '\r\n');
}
}

View File

@ -1,4 +1,3 @@
/* eslint-disable */
// const fs = require('fs');
// const path = require('path');
@ -15,13 +14,13 @@
*/
async function asyncForEach(array, callback) {
console.log("AsyncForEach Len " + array.length);
logger('info', "AsyncForEach 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);
logger('info', "Index " + index + " " + res);
} catch (error) {
console.error(error);
logger('error', error);
}
}
}
@ -29,7 +28,7 @@ async function asyncForEach(array, callback) {
function scanAPT_Old(p) {
return airports.init().then(features => {
var d = path.join(homedir, 'Documents/apt.dat');
console.log(d);
logger('info', d);
apt.scan(d, features);
});
}
@ -42,34 +41,37 @@ async function waitFor(milliseconds) {
async function scanGroundnetFiles(p, features) {
var promise = new Promise(function (resolve, reject) {
try {
console.log('Start Groundnets ' + p);
logger('info', 'Start Groundnets ' + p);
var files = traverseDir(p);
console.log(files);
this.postMessage(['max', files.length]);
logger('info', files);
asyncForEach(files, async f => {
//await waitFor(5000);
try {
this.postMessage(['progress', 1]);
var text = await readGroundnet(f, features);
console.log(text);
logger('info', text);
resolve(text);
} catch (error) {
console.error(error);
logger('error', error);
reject(error);
}
}).then(t => {
console.log("Finished");
logger('info', "Finished");
features.close();
this.postMessage('DONE');
resolve();
}).catch(reason => {
console.log("Crashed");
console.log(reason);
logger('info', "Crashed");
logger('info', reason);
features.close()
});
//walkDir(p, f => { readGroundnet(f, features) });
} catch (error) {
console.log(error);
logger('info', error);
reject(error);
}
});
@ -85,17 +87,17 @@ async function resetAI() {
if (cursor) {
cursor.value.properties.flights = 0
cursor.value.properties.airlines = [];
console.log("Name for SSN " + cursor.key + " is " + cursor.value.properties.name);
logger('info', "Name for SSN " + cursor.key + " is " + cursor.value.properties.name);
cursor.update(cursor.value);
cursor.continue();
}
else {
console.log("No more entries!");
logger('info', "No more entries!");
resolve();
}
};
} catch (error) {
console.log(error);
logger('info', error);
reject(error);
}
});
@ -105,30 +107,32 @@ async function resetAI() {
async function scanTrafficFiles(p, features) {
var promise = new Promise(function (resolve, reject) {
try {
console.log('Start Traffic ' + p);
logger('info', 'Start Traffic ' + p);
resetAI().then(f => {
var files = traverseDir(p);
console.log(files);
this.postMessage(['max', files.length]);
logger('info', files);
asyncForEach(files, async f => {
//await waitFor(5000);
try {
this.postMessage(['progress', 1]);
var text = await readAI(f, features);
console.log(text);
logger('info', text);
resolve(text);
} catch (error) {
console.error(error);
logger('error', error);
reject(error);
}
}).then(t => {
console.log("Finished");
logger('info', "Finished");
features.close();
resolve();
this.postMessage('DONE');
}).catch(reason => {
console.log("Crashed");
console.log(reason);
logger('info', "Crashed");
logger('info', reason);
features.close()
this.postMessage('DONE');
});
@ -139,7 +143,7 @@ async function scanTrafficFiles(p, features) {
//walkDir(p, f => { readGroundnet(f, features) });
} catch (error) {
console.log(error);
logger('info', error);
reject(error);
}
});
@ -153,7 +157,7 @@ async function scanTrafficFiles(p, features) {
function scanTrafficIntoDB(p, features) {
try {
console.log('Start Traffic ' + p + ' ' + features);
logger('info', 'Start Traffic ' + p + ' ' + features);
var objectStore = features.transaction("airports").objectStore("airports");
objectStore.openCursor().onsuccess = function (event) {
@ -161,21 +165,21 @@ function scanTrafficIntoDB(p, features) {
if (cursor) {
feature.value.properties.flights = 0
feature.value.properties.airlines = [];
console.log("Name for SSN " + cursor.key + " is " + cursor.value.name);
logger('info', "Name for SSN " + cursor.key + " is " + cursor.value.name);
cursor.continue();
}
else {
console.log("No more entries!");
logger('info', "No more entries!");
}
};
//walkDir(p, f => { readAI(f, features) });
console.log("Closing");
logger('info', "Closing");
features.close();
this.postMessage('DONE');
console.log("End Traffic");
logger('info', "End Traffic");
} catch (error) {
console.log(error);
logger('info', error);
}
}
@ -184,11 +188,11 @@ function traverseDir(dir) {
fs.readdirSync(dir).forEach(file => {
let fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
console.log(fullPath);
logger('info', fullPath);
var children = traverseDir(fullPath);
result = result.concat(children);
} else {
console.log(fullPath);
logger('info', fullPath);
result.push(fullPath);
}
});
@ -203,7 +207,7 @@ function walkDir(dir, callback) {
isDirectory ?
walkDir(dirPath, callback) : callback(path.join(dir, f));
} catch (error) {
console.error(error);
logger('error', error);
}
});
}
@ -217,7 +221,6 @@ function walkDir(dir, callback) {
function readAI(f, apts) {
var promise = new Promise(function (resolve, reject) {
try {
console.log(path.basename(f));
// Reset
var airline = path.basename(f).match('([^.]+)\.xml');
if (airline == null) {
@ -225,35 +228,26 @@ function readAI(f, apts) {
return;
}
var xmlSource = fs.readFileSync(f, 'utf8').toString();
console.debug("read airline " + path.basename(f));
logger('info', "read airline ", path.basename(f));
// var doc = new domParser().parseFromString(xmlSource );
// console.log("parsed ");
// logger('info', "parsed ");
// var flights = xpath.select("/trafficlist/flight", doc);
// console.log("selected flight ");
// console.log(flights);
var dat = tXml(xmlSource);
// console.log(dat);
if (!dat || !dat[0] || !dat[0].children || !dat[0].children[0]) {
// logger('info', "selected flight ");
// logger('info', flights);
var dat = tXml.simplify(tXml(xmlSource))['?xml'];
// logger('info', dat);
if (!dat || !dat.trafficlist || !dat.trafficlist.flight) {
resolve();
return;
}
console.log(dat[0].children[0]);
logger('info', 'Traffic', dat.trafficlist.flight);
var flightNodes = dat[0].children[0].children.filter(e => e.tagName === 'flight');
flightNodes = tXml.simplify(flightNodes);
if (!flightNodes || !flightNodes.flight) {
resolve();
return;
}
console.log(flightNodes.flight);
console.log("Departure flights " + flightNodes.flight.length);
logger('info', "Departure flights " + dat.trafficlist.flight.length);
var merged = new Array();
flightNodes.flight.map(n => {
dat.trafficlist.flight.map(n => {
merged.push(n.departure.port);
merged.push(n.arrival.port);
}).sort();
@ -264,14 +258,13 @@ function readAI(f, apts) {
}
asyncForEach(Object.keys(counts), async key => {
console.log(key);
logger('info', key);
await store(key, airline[1], counts[key]);
}).then(t => {
console.log("Finished");
logger('info', "Finished");
resolve();
}).catch(reason => {
console.log("Crashed");
console.log(reason);
logger('error', "Crashed", reason);
features.close()
});
//for (var key in counts) {
@ -279,13 +272,13 @@ function readAI(f, apts) {
//}
// var flights = xpath.select("/trafficlist/flight/departure/port/text()", doc);
// console.log(nodes);
// console.log(nodes);
// logger('info', nodes);
// logger('info', nodes);
// nodes = xpath.select("/trafficlist/flight/arrival/port/text()", doc);
// console.log(nodes);
// logger('info', nodes);
} catch (error) {
console.error(error);
logger('error', error);
reject(error);
}
});
@ -301,43 +294,44 @@ function readAI(f, apts) {
function store(icao, airline, value) {
var promise = new Promise(function (resolve, reject) {
console.log("Airport " + icao + " has " + value + " new flights");
logger('info', "Airport " + icao + " has " + value + " new 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);
var index = objectStore.index('icaoIndex');
var objectStoreRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) {
console.log(event);
logger('info', 'Stored ', event);
var feature = objectStoreRequest.result;
if (!feature) {
feature = createFeature(icao);
}
feature.properties.flights += value;
console.log("Airline " + airline);
logger('info', "Airline : ", airline);
if (!feature.properties.airlines.includes(airline)) {
feature.properties.airlines.push(airline);
feature.properties.airlines.sort();
}
console.log("ICAO : " + feature.properties.icao + " Flights : " + feature.properties.flights);
logger('info', "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);
logger('info', "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");
updateAirportRequest.onsuccess = function (event) {
logger('info', "Stored", event);
resolve();
};
updateAirportRequest.onerror = function (event) {
console.log("Error storing " + event);
logger('info', "Error storing ", event);
reject(event);
};
};
objectStoreRequest.onerror = function (event) {
console.log("Error " + event);
logger('info', "Error " + event);
reject(event);
};
});
@ -358,68 +352,75 @@ async function readGroundnet(f, features) {
resolve("File didn't match");
}
else {
console.log('Parsing ' + f);
logger('info', 'Parsing ' + f);
fs.readFile(f, 'utf8', (err, data) => {
if (err) {
console.log('Error reading file ' + err);
logger('info', 'Error reading file ' + err);
reject(err);
}
console.log(data);
logger('info', data);
var dat = tXml.simplify(tXml(data));
console.log('Simplified ' + filename);
logger('info', 'Simplified ' + filename);
if (dat['?xml']) {
console.log("parsed " + f);
logger('info', "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);
logger('info', 'Read Transaction complete ', event);
};
transaction.onerror = function (event) {
console.log('Transaction error ' + event);
logger('info', 'Transaction error ', event);
};
var objectStore = transaction.objectStore("airports");
var objectStoreRequest = objectStore.get(filename[1]);
var icao = filename[1];
var index = objectStore.index('icaoIndex');
var objectStoreRequest = index.get(icao);
/*
var getAllKeysRequest = index.getAllKeys();
getAllKeysRequest.onsuccess = function() {
logger('AllKeys', getAllKeysRequest.result);
}
*/
objectStoreRequest.onsuccess = function (event) {
console.log(dat['?xml'].groundnet);
var feature = event.result;
console.log("Got Airport : " + feature);
logger('info', dat['?xml'].groundnet);
var feature = event.target.result;
logger('info', "Got Airport : ", feature);
if (!feature) {
feature = createFeature(filename[1]);
}
if (filename[2] == 'threshold') {
try {
console.log('threshold : ' + filename[1]);
logger('info', 'threshold : ' + filename[1]);
var nodes = dat['?xml'].PropertyList.runway;
if (nodes.threshold == 0) {
console.log("No Runway");
logger('info', "No Runway");
resolve();
}
nodes.forEach(r => {
nodes.threshold.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);
logger('info', feature.geometry.coordinates);
}
});
feature.properties['threshold'] = true;
} catch (error) {
console.log(error);
logger('info', error);
}
} else if (filename[2] == 'twr') {
try {
console.log('twr : ' + filename[1]);
logger('info', 'twr : ' + filename[1]);
var nodes = dat['?xml'].PropertyList.tower.twr;
if (nodes.length == 0) {
console.log("No Tower");
logger('info', "No Tower");
resolve();
}
var lat = parseFloat(nodes.lat);
@ -428,21 +429,21 @@ async function readGroundnet(f, features) {
feature.geometry.coordinates = [lon, lat];
} catch (error) {
console.log(error);
logger('info', error);
}
} else if (filename[2] == 'groundnet') {
console.log('groundnet : ' + filename[1]);
logger('info', 'groundnet : ' + filename[1]);
if (dat['?xml'].groundnet) {
var nodes = dat['?xml'].groundnet.TaxiNodes;
if (nodes && nodes.node) {
console.log(nodes);
logger('info', nodes);
}
feature['properties']['groundnet'] = nodes && nodes.node ? nodes.node.length : 0;
var nodes = dat['?xml'].groundnet.parkingList;
feature['properties']['parking'] = nodes && nodes.Parking ? nodes.Parking.length : 0;
}
} else if (filename[2] == 'ils') {
console.log('ils : ' + filename[1]);
logger('info', 'ils : ' + filename[1]);
if (dat['?xml'].PropertyList.runways) {
var nodes = dat['?xml'].PropertyList.runways.ils;
feature.properties['ils'] = nodes !== undefined;
@ -451,30 +452,30 @@ async function readGroundnet(f, features) {
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);
logger('info', 'Write Transaction complete ' + event);
resolve("Stored " + filename[1]);
};
transaction.onerror = function (event) {
console.log('Transaction error ' + event);
logger('info', '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);
logger('info', "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");
logger('info', "Stored");
};
updateAirportRequest.onerror = function (event) {
console.log("Error storing " + event);
logger('info', "Error storing " + event);
reject(event);
};
}
objectStoreRequest.onerror = function (event) {
console.log("Read Errpr : " + event);
logger('info', "Read Errpr : " + event);
resolve(event);
}
}
@ -486,7 +487,7 @@ async function readGroundnet(f, features) {
}
} catch (error) {
console.error(error);
logger('error', error);
reject(error);
}
});

View File

@ -11,17 +11,20 @@ const homedir = require('os').homedir();
var airports = importScripts(`${winURL}airports.js`);
importScripts('../txml/tXml.min.js');
importScripts('logger.js');
function errorReceiver(event) {
throw event.data;
}
onmessage = function (event) {
postMessage('scanStarted');
logger('info', 'Scan Started');
console.log(event.data);
if (event.data[0] === 'scan') {
scanGroundnet(event.data[1]).then(result => {
console.log("DONE Scanning");
postMessage('DONE', 'this');
postMessage('DONE');
// event.origin.webContents.send('scanFinished');
}
).catch(result => {