@SuppressWarnings("java:S2142")
  TileWeights run(int threads, int topN, int maxZoom, List<LocalDate> toDownload) {
    CompletableFuture<TileWeights> result = new CompletableFuture<>();
    var timer = stats.startStage("top-osm-tiles");

    AtomicLong downloaded = new AtomicLong();

    var pipeline = WorkerPipeline.start("top-osm-tiles", stats)
      .readFromTiny("urls", toDownload).<Map.Entry<Integer, Long>>addWorker("download", threads,
        (prev, next) -> {
          for (var date : prev) {
            for (var line : readFile(maxZoom, date)) {
              next.accept(line);
            }
            downloaded.incrementAndGet();
          }
        })
      .addBuffer("lines", 100_000, 1_000)
      .sinkTo("collect", 1, lines -> {
        Map<Integer, Long> counts = new HashMap<>();
        for (var line : lines) {
          counts.merge(line.getKey(), line.getValue(), Long::sum);
        }
        LOGGER.info("Extracting top {} tiles from {} tiles", topN, counts.size());
        var tileWeights = new TileWeights();
        counts.entrySet().stream()
          .sorted(Comparator.comparingLong(e -> -e.getValue()))
          .limit(topN)
          .forEach(entry -> tileWeights.put(TileCoord.decode(entry.getKey()), entry.getValue()));
        result.complete(tileWeights);
      });

    ProgressLoggers progress = ProgressLoggers.create()
      .addPercentCounter("files", toDownload.size(), downloaded)
      .newLine()
      .addPipelineStats(pipeline)
      .newLine()
      .addProcessStats();

    pipeline.awaitAndLog(progress, config.logInterval());
    timer.stop();
    stats.printSummary();
    try {
      return result.get();
    } catch (InterruptedException | ExecutionException e) {
      return throwFatalException(e);
    }
  }
A utility for computing {@link TileWeights} from historic openstreetmap.org tile traffic.
<p>
To download raw data from OSM tile logs, run with:

<pre>
{@code
java -jar planetiler.jar top-osm-tiles --days=<# days to fetch> --top=<# tiles to include> --output=output.tsv.gz
}
</pre>
<p>
You can also fetch precomputed top-1m tile stats from summer 2023 using
{@link #downloadPrecomputed(PlanetilerConfig)}
planetiler-core/src/main/java/com/onthegomap/planetiler/util/TopOsmTiles.java