Skip to content

Commit

Permalink
Stop-gap to improve web app perf: skip low-count edges. #14
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Sep 8, 2023
1 parent 3ee4f47 commit 2acb5a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions aggregate_routes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ struct Args {
/// Don't output OSM tags in the GeoJSON output, to reduce file size.
#[clap(long)]
no_output_osm_tags: bool,
/// Don't output edges with total counts below this threshold.
#[clap(long)]
skip_edges_with_low_count: Option<usize>,

/// Instead of doing what this tool normally does, instead calculate this many routes and write
/// a separate GeoJSON file for each of them, with full segment-level detail. This will be slow
Expand Down Expand Up @@ -160,6 +163,7 @@ fn main() -> Result<()> {
counts,
!args.no_output_od_points,
!args.no_output_osm_tags,
args.skip_edges_with_low_count,
config.lts,
)?;
timer.stop();
Expand Down
10 changes: 9 additions & 1 deletion aggregate_routes/src/osm2network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ impl Network {
counts: Counts,
output_od_points: bool,
output_osm_tags: bool,
skip_edges_with_low_count: Option<usize>,
lts: LtsMapping,
) -> Result<()> {
// Write one feature at a time to avoid memory problems
Expand All @@ -350,6 +351,13 @@ impl Network {
let mut skipped = 0;
let mut id_counter = 0;
for ((node1, node2), count) in counts.count_per_edge {
if let Some(min) = skip_edges_with_low_count {
if (count as usize) < min {
skipped += 1;
continue;
}
}

// TODO Track forwards and backwards counts separately, and optionally merge later?
if let Some(edge) = self
.edges
Expand All @@ -367,7 +375,7 @@ impl Network {
}
}
println!(
"Skipped {} edges (started/ended mid-edge)",
"Skipped {} edges (started/ended mid-edge, or count too low)",
HumanCount(skipped)
);

Expand Down

0 comments on commit 2acb5a6

Please sign in to comment.