a-b-street / docs

Technical and user documentation for A/B Street
Apache License 2.0
12 stars 7 forks source link

Use minimal example json to show how to import .json files #19

Open Robinlovelace opened 3 years ago

Robinlovelace commented 3 years ago

It's worth doing but currently I get the following error message:

cargo run --bin import_traffic -- \
  --map=data/system/us/seattle/maps/montlake.bin \
  --input=minimal_scenario2.json
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/import_traffic --map=data/system/us/seattle/maps/montlake.bin --input=minimal_scenario2.json`
import traffic demand data...
Read data/system/us/seattle/maps/montlake.bin (3)... 0.4303s
parse minimal_scenario2.json...
parse minimal_scenario2.json took 0.0001s
thread 'main' panicked at 'Couldn't read_json(minimal_scenario2.json): invalid type: floating point `10800`, expected i32 at line 7 column 30', /mnt/57982e2a-2874-4246-a6fe-115
Robinlovelace commented 3 years ago

Using the larger example in #17. Will try on the minimal one also...

Robinlovelace commented 3 years ago

Fixed the issue by multiplying by 1000 and making it an integer. Next issue is easier to debug:

cargo run --bin import_traffic -- \             
  --map=data/system/us/seattle/maps/montlake.bin \
  --input=minimal_scenario.json
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/import_traffic --map=data/system/us/seattle/maps/montlake.bin --input=minimal_scenario.json`
import traffic demand data...
Read data/system/us/seattle/maps/montlake.bin (3)... 0.4319s
parse minimal_scenario.json...
parse minimal_scenario.json took 0.0001s
thread 'main' panicked at 'Couldn't read_json(minimal_scenario.json): unknown variant `Leisure`, expected one of `Home`, `Work`, `School`, `Escort`, `PersonalBusiness`, `Shopping`, `Meal`, `Social`, `Recreation`, `Medical`, `ParkAndRideTransfer` at line 38 column 30', /mnt/57982e2a-2874-4246-a6fe-115c199bc6bd/orgs/a-b-street/abstreet/abstio/src/io.rs:26:21
Robinlovelace commented 3 years ago

PR incoming...

dabreegster commented 3 years ago

Oops, should probably check JSON in the docs more carefully. cargo run --bin dump_scenario -- data/system/us/seattle/scenarios/montlake/weekday.bin serializes a real working scenario as JSON, so copying from / comparing with that is the safest bet...

Edit: got the file path wrong, it is not my day...

Robinlovelace commented 3 years ago

Awesome. It works!

  ...
        {
          "depart": 541800000,
          "origin": {
            "Bldg": 457
          },
          "destination": {
            "Border": 499
          },
          "mode": "Drive",
          "purpose": "Work",
          "cancelled": false,
          "modified": false
        }
      ]
    }
  ],
  "only_seed_buses": null
}
dabreegster commented 3 years ago

Wait I'm really not thinking clearly. The Scenario format and the ExternalPerson format are totally different. Ignore what I just said. Multiplying by 1000 and fixing the mode enum was fine.

Robinlovelace commented 3 years ago

All good. I'm looking at a landscape screen friendly scenario now...

image

Robinlovelace commented 3 years ago

Associated json below. Seem reasonable?

{
  "scenario_name": "monday",
  "people": [
    {
      "trips": [
        {
          "departure": 391200000,
          "origin": {
            "Position": {
              "longitude": -122.303723,
              "latitude": 47.6372834
            }
          },
          "destination": {
            "Position": {
             "longitude": -122.3190500,
              "latitude": 47.6378600
        }
          },
          "mode": "Drive",
          "purpose": "Shopping"
        },
        {
          "departure": 430800000,
          "origin": {
            "Position": {
              "longitude": -122.3075948,
              "latitude": 47.6394773
        }
          },
          "destination": {
            "Position": {
             "longitude": -122.3190500,
              "latitude": 47.6378600
        }
          },
          "mode": "Walk",
          "purpose": "Recreation"
        }
      ]
    }
  ]
}
Robinlovelace commented 3 years ago

Although I would replace Drive with Bike as the distances are small.

dabreegster commented 3 years ago

Is origin and destination swapped for the second trip?

Robinlovelace commented 3 years ago

Looks like it...

Robinlovelace commented 3 years ago

Also, when I import it nothing shows. Any ideas why?

Robinlovelace commented 3 years ago

Reproducible example...

cargo run --bin import_traffic -- \\n  --map=data/system/us/seattle/maps/montlake.bin \\n  --input=minimal_scenario.json
cargo run --bin game -- --dev data/system/us/seattle/maps/montlake.bin\n
Robinlovelace commented 3 years ago

That's with:

{
  "scenario_name": "monday",
  "people": [
    {
      "trips": [
        {
          "departure": 391200000,
          "origin": {
            "Position": {
              "longitude": -122.303723,
              "latitude": 47.6372834
            }
          },
          "destination": {
            "Position": {
             "longitude": -122.3190500,
              "latitude": 47.6378600
        }
          },
          "mode": "Bike",
          "purpose": "Shopping"
        },
        {
          "departure": 430800000,
          "origin": {
            "Position": {
             "longitude": -122.3190500,
              "latitude": 47.6378600
        }
          },
          "destination": {
            "Position": {
              "longitude": -122.3075948,
              "latitude": 47.6394773
        }
          },
          "mode": "Walk",
          "purpose": "Recreation"
        }
      ]
    }
  ]
}

as minimal_scenario.json.

Robinlovelace commented 3 years ago

I've updated the times, e.g. to "departure": 10800000,

Robinlovelace commented 3 years ago

It's working! Slightly random time but that's fine...

Robinlovelace commented 3 years ago

image

Robinlovelace commented 3 years ago

Follow-up question, guess there's a simple question to this one, why don't they go by Bike as per the JSON (guess: there is not bike nearby or it's too near to cycle)?

Robinlovelace commented 3 years ago

Apologies, they are biking :tada:

Robinlovelace commented 3 years ago

On a midnight food mission.

image