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

View File

@ -1,37 +1,60 @@
/* eslint-disable */
const lineReader = require('readline');
const zlib = require('zlib');
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 = {
1: (l, apts) => {
logger('info', 'Airport:', l);
icao = l[4];
saveName(apts, l[4], l.slice(5).join(' ').replace('\t', ' '));
1: async (l, apts) => {
var promise = new Promise(function (resolve, reject) {
logger('info', 'Airport:', l);
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) => {
logger('info','Viewport:', l);
saveCoordinates(apts, icao, l[1], l[2]);
14: async (l, apts) => {
var promise = new Promise(function (resolve, reject) {
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');
}
};
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 index = objectStore.index('icaoIndex');
var objectStoreRequest = index.get(icao);
var objectGetRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) {
logger('info',event);
objectGetRequest.onsuccess = function (event) {
logger('info', 'objectGetRequest', event);
var feature = event.target.result;
if (!feature) {
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': {
"type": "Point"
}
@ -39,25 +62,25 @@ async function saveName(features, icao, name) {
}
feature.properties.name = name;
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
var updateAirportRequest = objectStore.put(feature);
// 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
updateAirportRequest.onsuccess = function () {
logger('info',"Stored");
resolve();
updateAirportRequest.onsuccess = function (event) {
logger('info',"Stored Name : " + event.target.result);
resolve(event.target.result);
};
updateAirportRequest.onerror = function (event) {
logger('info',"Error " + event);
logger('info',"Error ", event);
reject(event);
};
};
objectStoreRequest.onerror = function (event) {
logger('info',"Error " + event);
objectGetRequest.onerror = function (event) {
logger('info',"Error ", event);
reject(event);
};
});
@ -73,12 +96,12 @@ async function saveCoordinates(features, icao, lat, lon) {
var objectStoreRequest = index.get(icao);
objectStoreRequest.onsuccess = function (event) {
logger('info',event);
logger('info', 'objectStoreRequest',event);
var feature = event.target.result;
if (!feature) {
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': {
"type": "Point"
}
@ -90,12 +113,12 @@ async function saveCoordinates(features, icao, lat, lon) {
var updateAirportRequest = objectStore.put(feature);
// 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
updateAirportRequest.onsuccess = function (event) {
logger('info',"Stored", event);
resolve();
logger('info',"Stored Position : " + event.target.result);
resolve("Stored Position : " + event.target.result);
};
updateAirportRequest.onerror = function (event) {
logger('info',"Error ", event);
@ -116,7 +139,8 @@ async function scanAPTIntoDB(f, features) {
var i;
var count = 0;
var postMessage = this.postMessage;
require('fs').createReadStream(f)
var lines = [];
require('fs').createReadStream(f).pipe(zlib.createGunzip())
.on('data', function(chunk) {
for (i=0; i < chunk.length; ++i)
if (chunk[i] == 10) count++;
@ -125,30 +149,46 @@ async function scanAPTIntoDB(f, features) {
postMessage(['max', count]);
console.log('Line Count',count);
lineReader.createInterface({
input: fs.createReadStream(f)
input: fs.createReadStream(f).pipe(zlib.createGunzip())
}).on('line', function (line) {
postMessage(['progress', 1]);
lines.push(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, features);
}
else {
if (fields[0] == '99') {
lineReader.close();
}
// logger('info','Ignored:', line);
if (fields[0] == '99') {
logger('info',"End Reading");
}
}).on('error', function (err) {
logger('info',err);
lr.close();
}).on('close', function () {
logger('info',"End");
features.close();
postMessage('DONE');
}).on('close', async function () {
logger('info',"End File Read");
asyncForEach(lines, async line => {
//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) {

View File

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

View File

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