Skip to content

How to use

Håvard Hellem edited this page May 11, 2018 · 9 revisions

Vapi example scripts

Start the server again:

sudo make

To run our example road segmenter example_roadnet_to_db.py, open a new terminal, then make a bash-shell in your container with:

sudo docker exec -t -i vapi_django_1 /bin/bash

When you're inside, run:

python /vapi/apps/data/road_segmenting/example_roadnet_to_db.py

You can also run example_create_test_prod_data.py to simulate production data input here, which requires you to have a apps/Driftsdata_SubSet_Small.geojson file:

python /vapi/apps/data/example_create_test_prod_data.py

Other make commands

sudo make start

Generally speaking, you will only need to build your containers when updating the Docker configurations, or new dependencies have been added. For general use, sudo make start will be faster and sufficient.

sudo make test

This will run our tests and lint the backend locally. We advice you to run this before pushing your code to Github, to ensure your code will pass our Travis CI build.

sudo make migrations

This will run python manage.py makemigrations, creating new migrations based on changes made to models.

sudo make shell

This will start up a Django shell within the container.

Other other make commands

sudo make build

This will build the containers.

sudo make stop

This will stop your containers if they're running in detached mode.

sudo make restart

This will stop and start (restart) your containers if they're running in detached mode.

sudo make status

This will display the status of your containers.

Input production data

An example is provided in backend/data/example_create_test_prod_data.py

Inputting production data is done by doing a POST request to /api/prod-data/. An example written in python is shown below.

url = 'http://localhost:8000/api/prod-data/'

r = requests.post(url, json=data, auth=(username, password))
print("Status: {}\n{}".format(r.status_code, r.text))

The data variable is on the format:

[
    {
        "time": "YYYY-MM-DDTHH:MM:SS+HH:MM",
        "startlat": <float>,
        "startlong": <float>,
        "endlat": <float>,
        "endlong": <float>,

        # The fields below are optional
        "dry_spreader_active": <True/False>,
        "plow_active": <True/False>,
        "wet_spreader_active": <True/False>,
        "brush_active": <True/False>
        "material_type_code": <Integer>
    },
    ...
]

The production data will be mapped to the road network. The map matching prioritizes segments that are close in distance and as parallel as possible. Production data points that don't map will be ignored and if none if the data points map a 200 OK response will be returned as opposed to 201 CREATED and the number of mapped data if any of the production data get added.

Clone this wiki locally