Skip to content

Commit

Permalink
Merge pull request #24 from opentraffic/more_stats
Browse files Browse the repository at this point in the history
More stats
  • Loading branch information
dnesbitt61 authored Apr 25, 2017
2 parents 5f0a6fc + 9c81562 commit 7250faf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/osmlr/output/tiles.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OSMLR_OUTPUT_TILES_HPP
#define OSMLR_OUTPUT_TILES_HPP

#include <unordered_map>
#include <osmlr/output/output.hpp>
#include <osmlr/util/tile_writer.hpp>

Expand Down Expand Up @@ -63,6 +64,8 @@ struct tiles : public output {
util::tile_writer m_writer;
uint32_t m_max_length;

std::unordered_map<valhalla::baldr::GraphId, uint32_t> m_counts;

std::vector<lrp> build_segment_descriptor(const valhalla::baldr::merge::path &p);
std::vector<lrp> build_segment_descriptor(const std::vector<valhalla::midgard::PointLL>& shape,
const valhalla::baldr::DirectedEdge* edge,
Expand Down
1 change: 0 additions & 1 deletion include/osmlr/util/tile_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct tile_writer {

const std::string m_base_dir, m_suffix;
const size_t m_max_fds;
const valhalla::baldr::TileHierarchy m_tile_hierarchy;

struct lru_fd {
// the file descriptor itself
Expand Down
9 changes: 5 additions & 4 deletions src/osmlr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <valhalla/midgard/logging.h>
#include <valhalla/baldr/graphreader.h>
#include <valhalla/baldr/tilehierarchy.h>
#include <valhalla/baldr/merge.h>

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

struct tiles_max_level {
typedef std::vector<vb::TileHierarchy::TileLevel> levels_t;
typedef std::vector<vb::TileLevel> levels_t;
levels_t m_levels;

struct const_iterator {
Expand Down Expand Up @@ -100,8 +101,8 @@ struct tiles_max_level {
}
};

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

auto filtered_tiles = tile_exists_filter<tiles_max_level>(
tiles_max_level(reader, max_level), reader);
tiles_max_level(max_level), reader);

vb::merge::merge(
filtered_tiles, reader, allow_merge_pred, allow_edge_pred,
Expand Down
14 changes: 14 additions & 0 deletions src/output/tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ void tiles::output_segment(std::vector<lrp>& lrps,
if (!tile.SerializeToString(&buf)) {
throw std::runtime_error("Unable to serialize Tile message.");
}
m_counts[tile_id]++;
m_writer.write_to(tile_id, buf);
}

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

uint32_t total = 0;
uint32_t max_count = 0;
for (auto tile : m_counts) {
if (tile.second > max_count) {
max_count = tile.second;
}
total += tile.second;
//std::cout << tile.first << " count = " << tile.second << std::endl;
}
std::cout << "Max OSMLR segments within a tile = " << max_count << std::endl;
std::cout << "Average OSMLR count per tile = " << (total / m_counts.size()) << std::endl;
std::cout << "Tile count = " << m_counts.size() << std::endl;

// because protobuf Tile messages can be concatenated and there's no footer to
// write, the only thing to ensure is that all the files are flushed to disk.
m_writer.close_all();
Expand Down
5 changes: 2 additions & 3 deletions src/util/tile_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace util {
tile_writer::tile_writer(std::string base_dir, std::string suffix, size_t max_fds)
: m_base_dir(base_dir)
, m_suffix(suffix)
, m_max_fds(max_fds)
, m_tile_hierarchy(m_base_dir) {
, m_max_fds(max_fds) {
if (bfs::exists(base_dir) && !bfs::is_empty(base_dir)) {
LOG_WARN("Non-empty " + base_dir + " will be purged of data.");
bfs::remove_all(base_dir);
Expand Down Expand Up @@ -55,7 +54,7 @@ void tile_writer::close_all() {
}

std::string tile_writer::get_name_for_tile(vb::GraphId tile_id) {
auto suffix = vb::GraphTile::FileSuffix(tile_id, m_tile_hierarchy);
auto suffix = vb::GraphTile::FileSuffix(tile_id);
auto path = bfs::path(m_base_dir) / suffix;
return path.replace_extension(m_suffix).string();
}
Expand Down

0 comments on commit 7250faf

Please sign in to comment.