Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Robinlovelace opened this issue Sep 1, 2021 · 20 comments
Open

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

Robinlovelace opened this issue Sep 1, 2021 · 20 comments

Comments

@Robinlovelace
Copy link
Contributor

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
Copy link
Contributor Author

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

@Robinlovelace
Copy link
Contributor Author

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
Copy link
Contributor Author

PR incoming...

@dabreegster
Copy link
Contributor

dabreegster commented Sep 1, 2021

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
Copy link
Contributor Author

Robinlovelace commented Sep 1, 2021

Awesome. It works!

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

@dabreegster
Copy link
Contributor

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
Copy link
Contributor Author

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

image

@Robinlovelace
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@dabreegster
Copy link
Contributor

Is origin and destination swapped for the second trip?

@Robinlovelace
Copy link
Contributor Author

Looks like it...

@Robinlovelace
Copy link
Contributor Author

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

@Robinlovelace
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@Robinlovelace
Copy link
Contributor Author

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

@Robinlovelace
Copy link
Contributor Author

image

@Robinlovelace
Copy link
Contributor Author

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
Copy link
Contributor Author

Apologies, they are biking 🎉

@Robinlovelace
Copy link
Contributor Author

On a midnight food mission.

image

Robinlovelace added a commit to Robinlovelace/docs that referenced this issue Sep 1, 2021
Robinlovelace added a commit to a-b-street/abstr that referenced this issue Sep 2, 2021
Robinlovelace added a commit that referenced this issue Sep 2, 2021
Update outdated json schema for #19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants