2018-02-12 12:37:18 +00:00
|
|
|
const { promisify } = require('util');
|
|
|
|
const jsonfile = require('jsonfile');
|
|
|
|
const logger = require('log4js').getLogger();
|
2018-06-14 08:20:19 +00:00
|
|
|
const lz77 = require('lz77');
|
|
|
|
var lzw = require('json-lzw');
|
2018-02-12 12:37:18 +00:00
|
|
|
|
|
|
|
logger.level = 'trace';
|
|
|
|
|
2018-06-14 08:20:19 +00:00
|
|
|
const file = '../src/work/stations.json';
|
|
|
|
const outFile = '../src/work/stationsMap.json';
|
|
|
|
const compressed = '../src/work/stations.lzw';
|
2018-02-12 12:37:18 +00:00
|
|
|
|
|
|
|
const readFile = promisify(jsonfile.readFile);
|
|
|
|
const writeFile = promisify(jsonfile.writeFile);
|
|
|
|
|
|
|
|
function doConvert(obj) {
|
|
|
|
const tempArray = [];
|
|
|
|
for(const item of obj.locations)
|
|
|
|
|
2018-06-14 08:20:19 +00:00
|
|
|
if ((item.lat !== 0) && (item.lon !== 0))
|
|
|
|
// logger.debug(item.name);
|
|
|
|
tempArray.push({ 'crs':item.crs, 'name':item.name, 'lat':item.lat, 'long':item.lon });
|
2018-02-12 12:37:18 +00:00
|
|
|
|
2018-06-14 08:20:19 +00:00
|
|
|
// const locMap = new Map(tempArray);
|
2018-02-12 12:37:18 +00:00
|
|
|
|
|
|
|
// logger.debug(locMap);
|
|
|
|
|
2018-06-14 08:20:19 +00:00
|
|
|
const test = lz77.compress(JSON.stringify(tempArray), { 'minStringLength':3 });
|
|
|
|
|
|
|
|
console.log(test);
|
|
|
|
|
2018-02-12 12:37:18 +00:00
|
|
|
writeFile(outFile, tempArray)
|
|
|
|
.then( () => {
|
|
|
|
logger.debug('Saved...');
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Json failed to save');
|
|
|
|
logger.warn(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
readFile(file)
|
|
|
|
.then(obj => {
|
|
|
|
logger.info('json loaded....');
|
|
|
|
doConvert(obj);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Json failed to load');
|
|
|
|
logger.warn(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
jsonfile.readFile(file, (err, obj) => {
|
|
|
|
if (err) {
|
|
|
|
logger.error('Json failed to load');
|
|
|
|
logger.warn(err);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
logger.info('Json loaded...');
|
|
|
|
doConvert(obj);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|