Skip to content

Commit

Permalink
Linter passes + adds travis integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ibesora committed Oct 21, 2018
1 parent 18f3aa5 commit ae1fc22
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 66 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
cache:
directories:
- node_modules
node_js:
- 8
before_script:
- npm install
script:
- npm test
67 changes: 34 additions & 33 deletions src/UI.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
/*eslint camelcase: ["error", {allow: ["zoom_level", "tile_row", "tile_column"]}]*/
"use strict";

const Inquirer = require("inquirer");
Expand Down Expand Up @@ -31,25 +32,25 @@ class UI {

}

static printSummaryTable(vtSummary, tiles, avgTileSizeLimit, avgTileSizeWarning) {
static printSummaryTable(vtSummary, tiles, avgTileSizeLimit, avgTileSizeWarning, tileSizeLimit) {

const data = UI.createSummaryTableData(vtSummary, tiles, avgTileSizeLimit, avgTileSizeWarning);
const data = UI.createSummaryTableData(vtSummary, tiles, avgTileSizeLimit, avgTileSizeWarning, tileSizeLimit);

Log.log("");
Log.title("Vector Tile Summary");
Log.table(["Zoom level", "Tiles", "Total level size (KB)", "Average tile size (KB)", "Max tile size (KB)", ""], data);

}

static createSummaryTableData(vtSummary, tiles, avgTileSizeLimit, avgTileSizeWarning) {
static createSummaryTableData(vtSummary, tiles, avgTileSizeLimit, avgTileSizeWarning, tileSizeLimit) {

const data = [];
const bigTiles = tiles.reduce((obj, tile) => {

obj[tile["zoom_level"]] = tile;
return obj;

},
},
{}
);

Expand Down Expand Up @@ -77,7 +78,7 @@ class UI {

if (currentBigTile) {

levelComment = `${levelComment} ${ColoredString.red(`Error: A total of ${currentBigTile.num} tiles are bigger than ${VTReader.tileSizeLimit}KB`)}`;
levelComment = `${levelComment} ${ColoredString.red(`Error: A total of ${currentBigTile.num} tiles are bigger than ${tileSizeLimit}KB`)}`;

}

Expand All @@ -102,9 +103,9 @@ class UI {

Inquirer.prompt([
{
type: "confirm",
name: "extraInfo",
message: "Do you want to get more information about a given level?",
type: "confirm",
name: "extraInfo",
message: "Do you want to get more information about a given level?",
default: false
}
]).then(answers => {
Expand All @@ -119,7 +120,7 @@ class UI {

static selectLevelPrompt(vtSummary, avgTileSizeLimit, avgTileSizeWarning) {

const levels = vtSummary.map((elem) =>
const levels = vtSummary.map((elem) =>
UI.formatLevelElement(elem, avgTileSizeLimit, avgTileSizeWarning)
);

Expand Down Expand Up @@ -158,17 +159,17 @@ class UI {

}

return `${elem["zoom_level"]} (${elem.tiles} tiles - ${avgSizeMessage}) `
return `${elem["zoom_level"]} (${elem.tiles} tiles - ${avgSizeMessage}) `;

}

static showTileDistributionData(data, avgTileSizeLimit, avgTileSizeWarning) {

const dataToPrint = data.map((elem, index) =>
const dataToPrint = data.map((elem, index) =>
UI.formatTileDistributionElement(elem, index, avgTileSizeLimit, avgTileSizeWarning)
);

Log.title("Tile size distribution")
Log.title("Tile size distribution");
Log.table(["#", "Bucket min (KB)", "Bucket max (KB)", "Nº of tiles", "Running avg size (KB)", "% of tiles in this level", "% of level size", "Accum % of tiles", "Accum % size"], dataToPrint);

}
Expand All @@ -190,7 +191,7 @@ class UI {

}

return [index+1, elem.minSize, elem.maxSize, elem.length, avgSizeMessage, elem.currentPc, elem.currentBucketSizePc, elem.accumPc, elem.accumBucketSizePc];
return [index + 1, elem.minSize, elem.maxSize, elem.length, avgSizeMessage, elem.currentPc, elem.currentBucketSizePc, elem.accumPc, elem.accumBucketSizePc];

}

Expand All @@ -200,13 +201,13 @@ class UI {

Inquirer.prompt([
{
type: "confirm",
name: "extraInfo",
message: "Do you want to see which tiles are in a bucket?",
type: "confirm",
name: "extraInfo",
message: "Do you want to see which tiles are in a bucket?",
default: false
}
]).then(answers => {

resolve(answers["extraInfo"]);

});
Expand All @@ -218,9 +219,9 @@ class UI {
static selectBucketPrompt(bucketData) {

const bucketNames = [];
for(let index = 1; index <= bucketData.length; ++index) {
for (let index = 1; index <= bucketData.length; ++index) {

const currBucketData = bucketData[index-1];
const currBucketData = bucketData[index - 1];
bucketNames.push(`${index} ${currBucketData.minSize} < Size <= ${currBucketData.maxSize} (${currBucketData.length} tiles)`);

}
Expand All @@ -232,11 +233,11 @@ class UI {
name: "bucket",
message: "Select a bucket",
choices: bucketNames
}]).then( (answers) => {
}]).then((answers) => {

const bucketIndex = parseInt(answers["bucket"].split(" ")[0]) -1;
const bucketIndex = parseInt(answers["bucket"].split(" ")[0]) - 1;
resolve(bucketIndex);

});

});
Expand All @@ -245,7 +246,7 @@ class UI {

static showBucketInfo(bucket, tileSizeLimit) {

const info = bucket.sort((a, b) => b.size - a.size).map((tile) =>
const info = bucket.sort((a, b) => b.size - a.size).map((tile) =>
UI.formatBucketInfo(tile, tileSizeLimit)
);

Expand All @@ -267,13 +268,13 @@ class UI {

Inquirer.prompt([
{
type: "confirm",
name: "extraTileInfo",
message: "Do you want to get more info about a tile?",
type: "confirm",
name: "extraTileInfo",
message: "Do you want to get more info about a tile?",
default: false
}
]).then(answers => {

resolve(answers["extraTileInfo"]);

});
Expand All @@ -284,7 +285,7 @@ class UI {

static selectTilePrompt(bucket, tileSizeLimit) {

const tiles = bucket.map((tile) =>
const tiles = bucket.map((tile) =>
UI.formatBucketInfo(tile, tileSizeLimit)
);

Expand All @@ -295,12 +296,12 @@ class UI {
name: "tile",
message: "Select a tile",
choices: tiles
}]).then( (answers) => {
}]).then((answers) => {

const tileIndex = answers["tile"].split(" ")[0].split("/");
const tile = {zoom_level: tileIndex[0], tile_column: tileIndex[1], tile_row: tileIndex[2]};
resolve(tile);

});

});
Expand All @@ -313,7 +314,7 @@ class UI {
let totalKeys = 0;
let totalValues = 0;

const info = tileData.layers.sort((a,b) => b.features.length - a.features.length).map((layer) => {
const info = tileData.layers.sort((a, b) => b.features.length - a.features.length).map((layer) => {

totalFeatures += layer.features.length;
totalKeys += layer.keys.length;
Expand All @@ -322,7 +323,7 @@ class UI {

});

Log.title("Tile information")
Log.title("Tile information");
Log.log(
ColoredString.format(ColoredString.green, "Layers in this tile: "),
ColoredString.format(ColoredString.white, info.length)
Expand Down
58 changes: 29 additions & 29 deletions src/core/VTProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class VTProcessor {
const taskRunner = new Listr(tasks);
taskRunner.run().then(
async () => {

const {vtSummary, tiles} = await VTProcessor.logInfo(reader);
UI.printMetadata(reader.metadata.minzoom, reader.metadata.mazoom, reader.metadata.format,
UI.printMetadata(reader.metadata.minzoom, reader.metadata.mazoom, reader.metadata.format,
reader.metadata.center, reader.layers);
VTProcessor.infoLoop(reader, vtSummary, tiles);

},
err => Log.error(err)
);
Expand All @@ -53,28 +53,28 @@ class VTProcessor {

} catch (err) {

Log.error(err)
Log.error(err);

}

}

static async infoLoop(reader, vtSummary, tiles) {

UI.printSummaryTable(vtSummary, tiles, VTProcessor.avgTileSizeLimit, VTProcessor.avgTileSizeWarning);
UI.printSummaryTable(vtSummary, tiles, VTProcessor.avgTileSizeLimit, VTProcessor.avgTileSizeWarning, reader.tileSizeLimit);

while(await UI.wantMoreInfoQuestion()) {
while (await UI.wantMoreInfoQuestion()) {

const selectedLevel = await UI.selectLevelPrompt(vtSummary, VTProcessor.avgTileSizeLimit, VTProcessor.avgTileSizeWarning);
const {data, buckets} = await VTProcessor.computeLevelInfo(reader, selectedLevel);
UI.showTileDistributionData(data, VTProcessor.avgTileSizeLimit, VTProcessor.avgTileSizeWarning);
while(await UI.tilesInBucketQuestion()) {

while (await UI.tilesInBucketQuestion()) {

const selectedBucket = await UI.selectBucketPrompt(data);
UI.showBucketInfo(buckets[selectedBucket], reader.tileSizeLimit);

while(await UI.tileInfoQuestion()) {
while (await UI.tileInfoQuestion()) {

const tileIndex = await UI.selectTilePrompt(buckets[selectedBucket], reader.tileSizeLimit);
const tileData = await VTProcessor.computeTileData(reader, tileIndex.zoom_level, tileIndex.tile_column, tileIndex.tile_row);
Expand All @@ -90,7 +90,7 @@ class VTProcessor {
UI.printSummaryTable(vtSummary, tiles, VTProcessor.avgTileSizeLimit, VTProcessor.avgTileSizeWarning);

}

}

static async computeLevelInfo(reader, zoomLevel) {
Expand All @@ -106,19 +106,19 @@ class VTProcessor {
const maxSize = levelTiles[levelTiles.length - 1].size;
const totalSize = levelTiles.reduce((accum, elem) => accum + elem.size, 0);
const totalNumTiles = levelTiles.length;
const bucketSize = (maxSize - minSize)/numBuckets;
const bucketSize = (maxSize - minSize) / numBuckets;
let currentBucketMaxSize = minSize + bucketSize;
let processedTilesSize = 0;

for(let i=0; i<totalNumTiles; ++i) {
for (let i = 0; i < totalNumTiles; ++i) {

if(levelTiles[i].size<=currentBucketMaxSize) {
if (levelTiles[i].size <= currentBucketMaxSize) {

tiles.push(levelTiles[i]);

} else {

VTProcessor.addTilesToBucket(minSize, currentBucketMaxSize, totalNumTiles,
VTProcessor.addTilesToBucket(minSize, currentBucketMaxSize, totalNumTiles,
totalSize, tiles, i, processedTilesSize, buckets, data);

tiles = [levelTiles[i]];
Expand All @@ -131,7 +131,7 @@ class VTProcessor {

}

VTProcessor.addTilesToBucket(minSize, currentBucketMaxSize, totalNumTiles,
VTProcessor.addTilesToBucket(minSize, currentBucketMaxSize, totalNumTiles,
totalSize, tiles, totalNumTiles, processedTilesSize, buckets, data);

return {data, buckets};
Expand All @@ -141,30 +141,30 @@ class VTProcessor {
static addTilesToBucket(minSize, maxSize, totalNumTiles, totalSize, tiles, processedTiles, processedTilesSize, buckets, data) {

const currentBucketSize = tiles.reduce((accum, elem) => accum + elem.size, 0);
const currentBucketSizePc = (currentBucketSize/totalSize) * 100.0;
const currentPc = (tiles.length/totalNumTiles) * 100.0;
let runningAvgSize = (processedTilesSize / processedTiles);
const currentBucketSizePc = (currentBucketSize / totalSize) * 100.0;
const currentPc = (tiles.length / totalNumTiles) * 100.0;
const runningAvgSize = (processedTilesSize / processedTiles);
let accumPc = 0;
let accumBucketSizePc = 0;

if(data.length !== 0) {
if (data.length !== 0) {

accumPc = data[data.length-1].accumPc; // Restore previous accumulated %
accumBucketSizePc = data[data.length-1].accumBucketSizePc; // Restore previous accumulated bucket size %
accumPc = data[data.length - 1].accumPc; // Restore previous accumulated %
accumBucketSizePc = data[data.length - 1].accumBucketSizePc; // Restore previous accumulated bucket size %

}

accumPc += currentPc;
accumBucketSizePc += currentBucketSizePc
accumBucketSizePc += currentBucketSizePc;

data.push({
minSize,
maxSize,
length: tiles.length,
runningAvgSize,
currentPc,
currentBucketSizePc,
accumPc,
minSize,
maxSize,
length: tiles.length,
runningAvgSize,
currentPc,
currentBucketSizePc,
accumPc,
accumBucketSizePc
});
buckets.push(tiles);
Expand Down
8 changes: 6 additions & 2 deletions src/core/VTReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class VTReader {
const rowData = await self.db.get(`SELECT tile_data, length(tile_data) as size FROM tiles WHERE zoom_level=${zoomLevel} AND tile_column=${column} AND tile_row=${row}`);
const data = await new Promise((resolve) => {

self.unzipTileData(rowData["tile_data"], resolve, reject)
self.unzipTileData(rowData["tile_data"], resolve, reject);

});

Expand Down Expand Up @@ -262,7 +262,11 @@ class VTReader {

self.db.all(`SELECT zoom_level, tile_column, tile_row, length(tile_data) as size FROM tiles WHERE zoom_level=${level}`).then((rows) => {

resolve(rows.map(row => { return { zoom_level: row.zoom_level, tile_column: row.tile_column, tile_row: row.tile_row, size: row.size/1024.0} }));
resolve(rows.map(row => {

return { zoom_level: row.zoom_level, tile_column: row.tile_column, tile_row: row.tile_row, size: row.size / 1024.0};

}));

});

Expand Down
Loading

0 comments on commit ae1fc22

Please sign in to comment.