Skip to content

Commit

Permalink
Output metadata from the pipeline, then gather it in the run_all scri…
Browse files Browse the repository at this point in the history
…pt to make a table. #33
  • Loading branch information
dabreegster committed Oct 6, 2023
1 parent ec42039 commit 983ed9c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
37 changes: 24 additions & 13 deletions aggregate_routes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct Args {
#[clap(long)]
no_output_pmtiles: bool,

/// Create an `output/metadata.json` file summarizing the run.
#[clap(long)]
output_metadata: bool,

/// 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
/// and take lots of disk if you specify a large number.
Expand Down Expand Up @@ -188,20 +192,11 @@ fn main() -> Result<()> {

drop(timer);
println!("");
output_metadata.describe();

println!("Input: {}", output_metadata.config.requests.description);
for (label, count) in [
("Origins", output_metadata.num_origins),
("Destinations", output_metadata.num_destinations),
("Requests", output_metadata.num_requests),
(
"Requests (succeeded)",
output_metadata.num_succeeded_requests,
),
("Requests (failed)", output_metadata.num_failed_requests),
("Edges with a count", output_metadata.num_edges_with_count),
] {
println!("- {label}: {}", HumanCount(count as u64));
if args.output_metadata {
let mut file = fs_err::File::create("output/metadata.json")?;
serde_json::to_writer(&mut file, &output_metadata)?;
}

Ok(())
Expand All @@ -218,3 +213,19 @@ pub struct OutputMetadata {
num_failed_requests: usize,
num_edges_with_count: usize,
}

impl OutputMetadata {
fn describe(&self) {
println!("Input: {}", self.config.requests.description);
for (label, count) in [
("Origins", self.num_origins),
("Destinations", self.num_destinations),
("Requests", self.num_requests),
("Requests (succeeded)", self.num_succeeded_requests),
("Requests (failed)", self.num_failed_requests),
("Edges with a count", self.num_edges_with_count),
] {
println!("- {label}: {}", HumanCount(count as u64));
}
}
}
4 changes: 3 additions & 1 deletion examples/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function run_example {
python3 setup.py

# Run the pipeline
cargo run --release -- config.json
cargo run --release -- config.json --output-metadata
# TODO or with docker

cd ..
Expand Down Expand Up @@ -47,3 +47,5 @@ run_example london
# Huge
#run_example england_2011_home_to_work
#run_example seattle

python3 summarize_results.py */output/metadata.json
22 changes: 22 additions & 0 deletions examples/summarize_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import json
import sys
# This has a dependency on `pip install py-markdown-table`
from markdownTable import markdownTable

rows = []
for arg in sys.argv[1:]:
with open(arg) as f:
data = json.load(f)
# TODO Pipeline runtime
# TODO Just for routing
# TODO Just for tippecanoe
# TODO Prettyprint numbers
rows.append({
"name": arg.split("/")[0],
"num_requests": data["num_requests"],
"num_edges_with_count": data["num_edges_with_count"],
})

# Print as a Markdown table for convenience
with open("md_table", "w") as f:
f.write(markdownTable(rows).setParams(row_sep="markdown", quote=False).getMarkdown())

0 comments on commit 983ed9c

Please sign in to comment.