diff --git a/Cargo.lock b/Cargo.lock index 3560d70ddd..cbb8f41f43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1532,6 +1532,17 @@ dependencies = [ "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "iotool" +version = "0.1.0" +dependencies = [ + "abstutil 0.1.0", + "geom 0.1.0", + "map_model 0.1.0", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "sim 0.1.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -3342,17 +3353,6 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "traffic_importer" -version = "0.1.0" -dependencies = [ - "abstutil 0.1.0", - "geom 0.1.0", - "map_model 0.1.0", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "sim 0.1.0", -] - [[package]] name = "try-lock" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index ab62ac4b9b..f67cb07c2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,11 @@ members = [ "geom", "headless", "importer", + "iotool", "kml", "map_editor", "map_model", "sim", - "traffic_importer", "updater", ] diff --git a/book/src/api.md b/book/src/api.md index 42bb2c65ee..6b05ae0417 100644 --- a/book/src/api.md +++ b/book/src/api.md @@ -37,3 +37,19 @@ are missing, etc. A summary of the commands available so far: mode, duration of trip in seconds). The mode is either a string like "Walk" or "Drive", or null if the trip was aborted (due to a simulation bug or disconnected map). + +## Related tools + +There's no API to create trips. Instead, you can +[import trips from your own data](https://dabreegster.github.io/abstreet/trafficsim/travel_demand.html#custom-import). + +If you need to deeply inspect the map, you can dump it to JSON: + +``` +cargo run --bin iotool -- dump_map --map=data/system/maps/montlake.bin +``` + +The format of the map isn't well-documented yet. See the +[generated API docs](https://dabreegster.github.io/abstreet/rustdoc/map_model/index.html) +and [the map model docs](https://dabreegster.github.io/abstreet/map/index.html) +in the meantime. diff --git a/book/src/howto/dev.md b/book/src/howto/dev.md index 7e8c706267..8d6a016943 100644 --- a/book/src/howto/dev.md +++ b/book/src/howto/dev.md @@ -23,6 +23,7 @@ One-time setup: ## Development tips +- [Generated API documentation](https://dabreegster.github.io/abstreet/rustdoc/map_model/index.html) - Compile faster by just doing `cargo run`. The executable will have debug stack traces and run more slowly. You can do `cargo run --release` to build in optimized release mode; compilation will be slower, but the executable much @@ -136,6 +137,7 @@ Common utilities: - `abstutil`: a grab-bag of IO helpers, timing and logging utilities, etc - `geom`: types for GPS and map-space points, lines, angles, polylines, polygons, circles, durations, speeds +- `iotool`: a catch-all tool to import/export data ## Code conventions diff --git a/book/src/trafficsim/travel_demand.md b/book/src/trafficsim/travel_demand.md index 398710074d..d030047e57 100644 --- a/book/src/trafficsim/travel_demand.md +++ b/book/src/trafficsim/travel_demand.md @@ -92,7 +92,7 @@ example: Run the tool: ``` -cargo run --bin traffic_importer -- --map=data/system/maps/montlake.bin --input=/path/to/input.json +cargo run --bin iotool -- import_traffic --map=data/system/maps/montlake.bin --input=/path/to/input.json ``` The tool matches input positions to the nearest building or border intersection, diff --git a/traffic_importer/Cargo.toml b/iotool/Cargo.toml similarity index 90% rename from traffic_importer/Cargo.toml rename to iotool/Cargo.toml index 9876eec942..ed49657793 100644 --- a/traffic_importer/Cargo.toml +++ b/iotool/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "traffic_importer" +name = "iotool" version = "0.1.0" authors = ["Dustin Carlino "] edition = "2018" diff --git a/traffic_importer/src/main.rs b/iotool/src/main.rs similarity index 81% rename from traffic_importer/src/main.rs rename to iotool/src/main.rs index 4eb0663f0f..767199c6a8 100644 --- a/traffic_importer/src/main.rs +++ b/iotool/src/main.rs @@ -6,10 +6,21 @@ use sim::{IndividTrip, PersonID, PersonSpec, Scenario, SpawnTrip, TripEndpoint, fn main() { let mut args = CmdArgs::new(); - let map = args.required("--map"); - let input = args.required("--input"); - args.done(); + match args.required_free().as_ref() { + "import_traffic" => { + import_traffic(args.required("--map"), args.required("--input")); + args.done(); + } + "dump_map" => { + let map = Map::new(args.required("--map"), &mut Timer::new("dump map")); + println!("{}", abstutil::to_json(&map)); + args.done(); + } + x => panic!("Unknown command {}. Try: import_traffic, dump_map", x), + } +} +fn import_traffic(map: String, input: String) { let mut timer = Timer::new("import traffic demand data"); let map = Map::new(map, &mut timer); let input: Input = abstutil::read_json(input, &mut timer);