This commit is contained in:
portree_kid 2020-02-21 12:58:20 +01:00
parent 88f15c3e61
commit d3a7e12b5d
4 changed files with 112 additions and 62 deletions

View File

@ -7,7 +7,7 @@
</div> </div>
</h1> </h1>
<el-container direction="vertical"> <el-container direction="vertical">
<el-progress :percentage="Number(((progress / max)*100).toPrecision(3))" v-if="max > 0"></el-progress> <el-progress :percentage="Number(((progress / max)*100).toPrecision(3))" v-if="max>0"></el-progress>
<!--<el-progress :percentage="progress / max"></el-progress>--> <!--<el-progress :percentage="progress / max"></el-progress>-->
<!--{{max}}&nbsp;{{progress}}--> <!--{{max}}&nbsp;{{progress}}-->
@ -52,11 +52,12 @@
pollData () { pollData () {
var workery = this.worker var workery = this.worker
var view = this var view = this
this.polling = setInterval(() => { workery.polling = setInterval(() => {
if (workery != null) { if (workery != null) {
view.max = Number(workery.max) view.max = Number(workery.max)
view.progress = Number(workery.progress) view.progress = Number(workery.progress)
view.scanning = Boolean(workery.scanning) view.scanning = Boolean(workery.scanning)
workery.view = view
} }
}, 1000) }, 1000)
}, },
@ -76,15 +77,20 @@
worker.progress = 0 worker.progress = 0
// var worker = new Worker(fileUrl('src/renderer/utils/worker.js')) // var worker = new Worker(fileUrl('src/renderer/utils/worker.js'))
this.worker = worker this.worker = worker
worker.postMessage(['scanapt']) worker.postMessage(['scanapt', this.$store.state.Settings.settings.flightgearDirectory_apt])
this.pollData() this.pollData()
// the reply // the reply
var store = this.$store var store = this.$store
worker.onmessage = function (e) { worker.onmessage = function (e) {
if (e.data === 'DONE') { if (e.data === 'scanStarted') {
this.progress = 0
this.max = 0
} else if (e.data === 'DONE') {
console.log('DONE') console.log('DONE')
store.dispatch('getAirports') store.dispatch('getAirports')
worker.terminate() worker.terminate()
worker.view.max = 0
worker.view.scanning = false
clearInterval(this.polling) clearInterval(this.polling)
this.scanning = false this.scanning = false
} else if (e.data.length > 0) { } else if (e.data.length > 0) {
@ -92,7 +98,7 @@
this.max = e.data[1] this.max = e.data[1]
} }
if (e.data[0] === 'progress') { if (e.data[0] === 'progress') {
this.progress = e.data[1] this.progress += e.data[1]
} }
} }
// console.log(e.data) // console.log(e.data)
@ -122,10 +128,15 @@
// the reply // the reply
var store = this.$store var store = this.$store
worker.onmessage = function (e) { worker.onmessage = function (e) {
if (e.data === 'DONE') { if (e.data === 'scanStarted') {
this.progress = 0
this.max = 0
} else if (e.data === 'DONE') {
console.log('DONE') console.log('DONE')
store.dispatch('getAirports') store.dispatch('getAirports')
worker.terminate() worker.terminate()
worker.view.max = 0
worker.view.scanning = false
clearInterval(this.polling) clearInterval(this.polling)
this.scanning = false this.scanning = false
} else if (e.data.length > 0) { } else if (e.data.length > 0) {
@ -164,12 +175,17 @@
// the reply // the reply
var store = this.$store var store = this.$store
worker.onmessage = function (e) { worker.onmessage = function (e) {
if (e.data === 'DONE') { if (e.data === 'scanStarted') {
this.progress = 0
this.max = 0
} else if (e.data === 'DONE') {
this.scanning = false this.scanning = false
console.log('DONE') console.log('DONE')
clearInterval(this.polling)
store.dispatch('getAirports') store.dispatch('getAirports')
worker.view.max = 0
worker.view.scanning = false
worker.terminate() worker.terminate()
clearInterval(this.polling)
} else if (e.data.length > 0) { } else if (e.data.length > 0) {
if (e.data[0] === 'max') { if (e.data[0] === 'max') {
this.max = e.data[1] this.max = e.data[1]

View File

@ -1,37 +1,60 @@
/* eslint-disable */ /* eslint-disable */
const lineReader = require('readline'); const lineReader = require('readline');
const zlib = require('zlib');
var icao; var icao;
async function asyncForEach(array, callback) {
logger('info', "AsyncForEach Len " + array.length);
for (let index = 0; index < array.length; index++) {
try {
var res = await callback(array[index], index, array);
logger('info', "Index " + index + " " + res);
} catch (error) {
logger('error', error);
}
}
}
var scanMethods = { var scanMethods = {
1: (l, apts) => { 1: async (l, apts) => {
logger('info', 'Airport:', l); var promise = new Promise(function (resolve, reject) {
icao = l[4]; logger('info', 'Airport:', l);
saveName(apts, l[4], l.slice(5).join(' ').replace('\t', ' ')); icao = l[4];
saveName(apts, l[4], l.slice(5).join(' ').replace('\t', ' '))
.then(result => {
resolve(result)
}).catch( err => {reject(err)});
});
return promise;
}, },
14: (l, apts) => { 14: async (l, apts) => {
logger('info','Viewport:', l); var promise = new Promise(function (resolve, reject) {
saveCoordinates(apts, icao, l[1], l[2]); logger('info','Viewport:', l);
saveCoordinates(apts, icao, l[1], l[2]).then(result => {
resolve(result)
}).catch( err => {reject(err)});;
});
return promise;
}, },
99: (l) => { 99: async (l) => {
logger('info','Finished'); logger('info','Finished');
} }
}; };
async function saveName(features, icao, name) { async function saveName(features, icao, name) {
var promise = new Promise(function (resolve, reject) { var promise = new Promise(function (resolve, reject) {
var transaction = features.transaction("airports", "readwrite"); var transaction = features.transaction("airports", "readwrite");
var objectStore = transaction.objectStore("airports"); var objectStore = transaction.objectStore("airports");
var index = objectStore.index('icaoIndex'); var index = objectStore.index('icaoIndex');
var objectStoreRequest = index.get(icao); var objectGetRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) { objectGetRequest.onsuccess = function (event) {
logger('info',event); logger('info', 'objectGetRequest', event);
var feature = event.target.result; var feature = event.target.result;
if (!feature) { if (!feature) {
feature = { feature = {
"type": "Feature", "type": "Feature",
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0, airlines: [] }, 'properties': { 'icao': icao, 'name': '', 'twr': false, 'threshold': false, 'flights': 0, airlines: [] },
'geometry': { 'geometry': {
"type": "Point" "type": "Point"
} }
@ -39,25 +62,25 @@ async function saveName(features, icao, name) {
} }
feature.properties.name = name; feature.properties.name = name;
feature.properties.icao = icao; feature.properties.icao = icao;
logger('info',"ICAO : " + feature.properties.icao + " Name : " + name ); logger('info',"Storing ICAO : " + feature.properties.icao + " Name : " + name );
// Create another request that inserts the item back into the database // Create another request that inserts the item back into the database
var updateAirportRequest = objectStore.put(feature); var updateAirportRequest = objectStore.put(feature);
// Log the transaction that originated this request // Log the transaction that originated this request
logger('info',"The transaction that originated this request is " + updateAirportRequest.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 // When this new request succeeds, run the displayData() function again to update the display
updateAirportRequest.onsuccess = function () { updateAirportRequest.onsuccess = function (event) {
logger('info',"Stored"); logger('info',"Stored Name : " + event.target.result);
resolve(); resolve(event.target.result);
}; };
updateAirportRequest.onerror = function (event) { updateAirportRequest.onerror = function (event) {
logger('info',"Error " + event); logger('info',"Error ", event);
reject(event); reject(event);
}; };
}; };
objectStoreRequest.onerror = function (event) { objectGetRequest.onerror = function (event) {
logger('info',"Error " + event); logger('info',"Error ", event);
reject(event); reject(event);
}; };
}); });
@ -73,12 +96,12 @@ async function saveCoordinates(features, icao, lat, lon) {
var objectStoreRequest = index.get(icao); var objectStoreRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) { objectStoreRequest.onsuccess = function (event) {
logger('info',event); logger('info', 'objectStoreRequest',event);
var feature = event.target.result; var feature = event.target.result;
if (!feature) { if (!feature) {
feature = { feature = {
"type": "Feature", "type": "Feature",
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0, airlines: [] }, 'properties': { 'icao': icao, 'name': '', 'twr': false, 'threshold': false, 'flights': 0, airlines: [] },
'geometry': { 'geometry': {
"type": "Point" "type": "Point"
} }
@ -90,12 +113,12 @@ async function saveCoordinates(features, icao, lat, lon) {
var updateAirportRequest = objectStore.put(feature); var updateAirportRequest = objectStore.put(feature);
// Log the transaction that originated this request // Log the transaction that originated this request
logger('info',"The transaction that originated this request is " + updateAirportRequest.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 // When this new request succeeds, run the displayData() function again to update the display
updateAirportRequest.onsuccess = function (event) { updateAirportRequest.onsuccess = function (event) {
logger('info',"Stored", event); logger('info',"Stored Position : " + event.target.result);
resolve(); resolve("Stored Position : " + event.target.result);
}; };
updateAirportRequest.onerror = function (event) { updateAirportRequest.onerror = function (event) {
logger('info',"Error ", event); logger('info',"Error ", event);
@ -116,7 +139,8 @@ async function scanAPTIntoDB(f, features) {
var i; var i;
var count = 0; var count = 0;
var postMessage = this.postMessage; var postMessage = this.postMessage;
require('fs').createReadStream(f) var lines = [];
require('fs').createReadStream(f).pipe(zlib.createGunzip())
.on('data', function(chunk) { .on('data', function(chunk) {
for (i=0; i < chunk.length; ++i) for (i=0; i < chunk.length; ++i)
if (chunk[i] == 10) count++; if (chunk[i] == 10) count++;
@ -125,30 +149,46 @@ async function scanAPTIntoDB(f, features) {
postMessage(['max', count]); postMessage(['max', count]);
console.log('Line Count',count); console.log('Line Count',count);
lineReader.createInterface({ lineReader.createInterface({
input: fs.createReadStream(f) input: fs.createReadStream(f).pipe(zlib.createGunzip())
}).on('line', function (line) { }).on('line', function (line) {
postMessage(['progress', 1]); lines.push(line);
var fields = line.split(/[ ]+/); var fields = line.split(/[ ]+/);
// var fields = line.match('([0-9]+)'); if (fields[0] == '99') {
if (fields == null) logger('info',"End Reading");
return;
var scanMethod = scanMethods[fields[0]];
if (scanMethod != null) {
scanMethod(fields, features);
}
else {
if (fields[0] == '99') {
lineReader.close();
}
// logger('info','Ignored:', line);
} }
}).on('error', function (err) { }).on('error', function (err) {
logger('info',err); logger('info',err);
lr.close(); lr.close();
}).on('close', function () { }).on('close', async function () {
logger('info',"End"); logger('info',"End File Read");
features.close(); asyncForEach(lines, async line => {
postMessage('DONE'); //await waitFor(5000);
try {
postMessage(['progress', 1]);
var fields = line.split(/[ ]+/);
// var fields = line.match('([0-9]+)');
if (fields != null) {
var scanMethod = scanMethods[fields[0]];
if (scanMethod != null) {
var text = await scanMethod(fields, features);
logger('info', 'Scanned', text);
resolve(text);
} else {
resolve('Ignored ' + line);
}
}
} catch (error) {
logger('error', error);
reject(error);
}
}).then(t => {
logger('info', "Finished");
postMessage('DONE');
}).catch(reason => {
logger('error', "Crashed");
logger('error', reason);
postMessage('DONE');
});
}); });
}); });
} catch (error) { } catch (error) {

View File

@ -59,13 +59,11 @@ async function scanGroundnetFiles(p, features) {
} }
}).then(t => { }).then(t => {
logger('info', "Finished"); logger('info', "Finished");
features.close();
this.postMessage('DONE'); this.postMessage('DONE');
resolve(); resolve();
}).catch(reason => { }).catch(reason => {
logger('info', "Crashed"); logger('info', "Crashed");
logger('info', reason); logger('info', reason);
features.close()
}); });
//walkDir(p, f => { readGroundnet(f, features) }); //walkDir(p, f => { readGroundnet(f, features) });
@ -127,13 +125,11 @@ async function scanTrafficFiles(p, features) {
} }
}).then(t => { }).then(t => {
logger('info', "Finished"); logger('info', "Finished");
features.close();
resolve(); resolve();
this.postMessage('DONE'); this.postMessage('DONE');
}).catch(reason => { }).catch(reason => {
logger('info', "Crashed"); logger('info', "Crashed");
logger('info', reason); logger('info', reason);
features.close()
this.postMessage('DONE'); this.postMessage('DONE');
}); });
} }
@ -175,7 +171,6 @@ function scanTrafficIntoDB(p, features) {
//walkDir(p, f => { readAI(f, features) }); //walkDir(p, f => { readAI(f, features) });
logger('info', "Closing"); logger('info', "Closing");
features.close();
this.postMessage('DONE'); this.postMessage('DONE');
logger('info', "End Traffic"); logger('info', "End Traffic");
} catch (error) { } catch (error) {
@ -265,7 +260,6 @@ function readAI(f, apts) {
resolve(); resolve();
}).catch(reason => { }).catch(reason => {
logger('error', "Crashed", reason); logger('error', "Crashed", reason);
features.close()
}); });
//for (var key in counts) { //for (var key in counts) {
// store(key, airline[0], counts[key]); // store(key, airline[0], counts[key]);
@ -497,7 +491,7 @@ async function readGroundnet(f, features) {
function createFeature(icao) { function createFeature(icao) {
return { return {
"type": "Feature", "type": "Feature",
'properties': { 'icao': icao, 'twr': false, 'threshold': false, 'flights': 0, airlines: [] }, 'properties': { 'icao': icao, 'name': '', 'twr': false, 'threshold': false, 'flights': 0, airlines: [] },
'geometry': { 'geometry': {
"type": "Point" "type": "Point"
} }

View File

@ -76,10 +76,10 @@ async function scanai(fdir) {
return promise; return promise;
} }
async function scanAPT() { async function scanAPT(fdir) {
var promise = new Promise(function (resolve, reject) { var promise = new Promise(function (resolve, reject) {
return initDB().then(features => { return initDB().then(features => {
var d = path.join(homedir, 'Documents/apt.dat'); var d = path.join(fdir);
scanAPTIntoDB(d, features); scanAPTIntoDB(d, features);
}); });
}); });