traintimesPWA/tools/convert.js

67 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2018-02-12 12:37:18 +00:00
const { promisify } = require('util');
const jsonfile = require('jsonfile');
const logger = require('log4js').getLogger();
const lz77 = require('lz77');
var lzw = require('json-lzw');
2018-02-12 12:37:18 +00:00
logger.level = 'trace';
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)
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
// const locMap = new Map(tempArray);
2018-02-12 12:37:18 +00:00
// logger.debug(locMap);
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);
}
});
*/