Skip to content

Commit 7250faf

Browse files
authored
Merge pull request #24 from opentraffic/more_stats
More stats
2 parents 5f0a6fc + 9c81562 commit 7250faf

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

include/osmlr/output/tiles.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef OSMLR_OUTPUT_TILES_HPP
22
#define OSMLR_OUTPUT_TILES_HPP
33

4+
#include <unordered_map>
45
#include <osmlr/output/output.hpp>
56
#include <osmlr/util/tile_writer.hpp>
67

@@ -63,6 +64,8 @@ struct tiles : public output {
6364
util::tile_writer m_writer;
6465
uint32_t m_max_length;
6566

67+
std::unordered_map<valhalla::baldr::GraphId, uint32_t> m_counts;
68+
6669
std::vector<lrp> build_segment_descriptor(const valhalla::baldr::merge::path &p);
6770
std::vector<lrp> build_segment_descriptor(const std::vector<valhalla::midgard::PointLL>& shape,
6871
const valhalla::baldr::DirectedEdge* edge,

include/osmlr/util/tile_writer.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct tile_writer {
2727

2828
const std::string m_base_dir, m_suffix;
2929
const size_t m_max_fds;
30-
const valhalla::baldr::TileHierarchy m_tile_hierarchy;
3130

3231
struct lru_fd {
3332
// the file descriptor itself

src/osmlr.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <valhalla/midgard/logging.h>
22
#include <valhalla/baldr/graphreader.h>
3+
#include <valhalla/baldr/tilehierarchy.h>
34
#include <valhalla/baldr/merge.h>
45

56
#include <boost/program_options.hpp>
@@ -42,7 +43,7 @@ bool allow_edge_pred(const vb::DirectedEdge *edge) {
4243
}
4344

4445
struct tiles_max_level {
45-
typedef std::vector<vb::TileHierarchy::TileLevel> levels_t;
46+
typedef std::vector<vb::TileLevel> levels_t;
4647
levels_t m_levels;
4748

4849
struct const_iterator {
@@ -100,8 +101,8 @@ struct tiles_max_level {
100101
}
101102
};
102103

103-
tiles_max_level(vb::GraphReader &reader, unsigned int max_level) {
104-
for (auto level : reader.GetTileHierarchy().levels() | bra::map_values) {
104+
tiles_max_level(unsigned int max_level) {
105+
for (auto level : vb::TileHierarchy::levels() | bra::map_values) {
105106
if (level.level <= max_level) {
106107
m_levels.push_back(level);
107108
}
@@ -279,7 +280,7 @@ int main(int argc, char** argv) {
279280
assert(max_level <= std::numeric_limits<uint8_t>::max());
280281

281282
auto filtered_tiles = tile_exists_filter<tiles_max_level>(
282-
tiles_max_level(reader, max_level), reader);
283+
tiles_max_level(max_level), reader);
283284

284285
vb::merge::merge(
285286
filtered_tiles, reader, allow_merge_pred, allow_edge_pred,

src/output/tiles.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ void tiles::output_segment(std::vector<lrp>& lrps,
354354
if (!tile.SerializeToString(&buf)) {
355355
throw std::runtime_error("Unable to serialize Tile message.");
356356
}
357+
m_counts[tile_id]++;
357358
m_writer.write_to(tile_id, buf);
358359
}
359360

@@ -366,6 +367,19 @@ void tiles::finish() {
366367
std::cout << "chunks " << chunks << std::endl;
367368
std::cout << "average length = " << avg << std::endl;
368369

370+
uint32_t total = 0;
371+
uint32_t max_count = 0;
372+
for (auto tile : m_counts) {
373+
if (tile.second > max_count) {
374+
max_count = tile.second;
375+
}
376+
total += tile.second;
377+
//std::cout << tile.first << " count = " << tile.second << std::endl;
378+
}
379+
std::cout << "Max OSMLR segments within a tile = " << max_count << std::endl;
380+
std::cout << "Average OSMLR count per tile = " << (total / m_counts.size()) << std::endl;
381+
std::cout << "Tile count = " << m_counts.size() << std::endl;
382+
369383
// because protobuf Tile messages can be concatenated and there's no footer to
370384
// write, the only thing to ensure is that all the files are flushed to disk.
371385
m_writer.close_all();

src/util/tile_writer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace util {
1414
tile_writer::tile_writer(std::string base_dir, std::string suffix, size_t max_fds)
1515
: m_base_dir(base_dir)
1616
, m_suffix(suffix)
17-
, m_max_fds(max_fds)
18-
, m_tile_hierarchy(m_base_dir) {
17+
, m_max_fds(max_fds) {
1918
if (bfs::exists(base_dir) && !bfs::is_empty(base_dir)) {
2019
LOG_WARN("Non-empty " + base_dir + " will be purged of data.");
2120
bfs::remove_all(base_dir);
@@ -55,7 +54,7 @@ void tile_writer::close_all() {
5554
}
5655

5756
std::string tile_writer::get_name_for_tile(vb::GraphId tile_id) {
58-
auto suffix = vb::GraphTile::FileSuffix(tile_id, m_tile_hierarchy);
57+
auto suffix = vb::GraphTile::FileSuffix(tile_id);
5958
auto path = bfs::path(m_base_dir) / suffix;
6059
return path.replace_extension(m_suffix).string();
6160
}

0 commit comments

Comments
 (0)