Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for extracting style statistics #747

Merged
merged 17 commits into from
Feb 9, 2023
Merged

Add script for extracting style statistics #747

merged 17 commits into from
Feb 9, 2023

Conversation

ZeLonewolf
Copy link
Member

This PR adds a script that offers a set of utilities for analyzing layers. Additionally, I have renamed a number of layers in order to logically group them for the purpose of statistics generation (since the choice of layer id is essentially arbitrary).

Usage examples:

  • npm run stats -- -a -s
  • npm run stats -- -c
  • npm run stats -- -pp -pl background
  • npm run stats -- -pg park
  • npm run stats -- --help
Usage: stats [options]

Options:
  -a, --all-layers                      summary layer stats
  -c, --layer-count                     count number of layers
  -s, --layer-size                      size of all layers
  -l, --layer <layer id>                stats about one layer
  -loc, --locales <locale1 locale2...>  language codes (default: ["mul"])
  -pp, --pretty                         pretty-print JSON output
  -pg, --print-group <group prefix>     print a list of the layers in a group
  -pl, --print-layer <layer id>         print the JSON of a layer
  -h, --help                            display help for command

@ZeLonewolf
Copy link
Member Author

Stats output samples:

-a

337 layers, grouped as follows:
background(1)........................122 bytes
urbanized-area(1)....................309 bytes
protected-area(3)..................2,370 bytes
airport(11)........................7,879 bytes
park(3)............................2,448 bytes
boundary(7)........................2,993 bytes
water(5)...........................5,564 bytes
waterway(3)........................3,548 bytes
pier(2)..............................566 bytes
rail(70).........................126,463 bytes
highway-construction(1)..............909 bytes
road(201)........................743,118 bytes
tunnel(2)............................959 bytes
ferry(1).............................284 bytes
building(1)..........................292 bytes
bridge(13).........................6,654 bytes
highway-shield(1)..................2,441 bytes
highway-exit(1)....................2,041 bytes
poi(1).............................2,882 bytes
place(9)..........................32,059 bytes

-c

337 layers

-s

Total layer size 944,239 bytes

let layer = layers[i];
layerMap.set(layer.id, layers[i]);
let layerSize = JSON.stringify(layer).length;
let layerGroup = layer.id.split("_", 1)[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this PR introduces a new naming convention for layer IDs that the statistics code depends on. We should document this naming convention.

Better yet, we should avail ourselves of the metadata property, which is an object that you can stuff arbitrary properties into. A style authored in Mapbox Studio inserts metadata in abundance, including for grouping layers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh 😅 that sounds like several KB worth of style JSON. Maybe let's document it for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - contributor's guide updated!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seems fragile, but let’s ticket out something less fragile as tail work. At a glance, we could group the layers by source layer to get pretty similar statistics, modulo some layer organization weirdness in OpenMapTiles.

scripts/stats.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants