Skip to content

Commit

Permalink
Add dev docs and prepare transpiler module
Browse files Browse the repository at this point in the history
  • Loading branch information
villasv committed Sep 20, 2023
1 parent 3f24763 commit 0e4f40d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
"BROUTER",
"Ceperley",
"Danbo",
"defaultaccess",
"Dunsmuir",
"extraglobs",
"footaccess",
"Hornby",
"initialcost",
"lonlats",
"motorroad",
"nodeaccessgranted",
"Smithe",
"vancycling"
]
Expand Down
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ eventually learn that there are longer but welcoming alternatives.
For example, consider searching for a route from Ramen Danbo at Robson to Jam
Café at Beatty.

| ⠀ |
:-----------------------:|:------------------------:|:-------------------------:
![](/docs/img/gmaps.jpg) | ![](/docs/img/amaps.jpg) | ![](/docs/img/brouter.jpg)
| | | |
| :------------------------: | :------------------------: | :--------------------------: |
| ![](/docs/case1/gmaps.jpg) | ![](/docs/case1/amaps.jpg) | ![](/docs/case1/brouter.jpg) |

Google Maps suggests going down at Robson - one of the busiest streets in
Downtown Vancouver - until it finally takes protected bike paths at Hornby and
Expand All @@ -25,8 +25,7 @@ left at Beatty? For some reason, Google Maps estimates that going straight at
Smithe up until Beatty St would take 6 more minutes. Maybe they know that
cyclists fearing for their lives will arrive faster? Sometimes Google Maps will
simply suggest going down at Robson all the way towards Beatty St, so it seems
some transient feature (like traffic) is factoring in the routing choices, but
we'll never know.
some transient feature (like traffic) is factoring in the routing choices.

Apple maps suggests going down at Robson until it takes a protected bike path at
Hornby; then taking the protected bike path at Dunsmuir. A decent balance of
Expand All @@ -39,4 +38,33 @@ The custom profile for BRouter in this repository offers that route: merely 300m
longer but immediately leaving Robson for Jervis and Haro which are residential
streets plus Smithe, Horny and Dunsmuir protected paths. The goal of this
project is researching a routing profile that is highly biased towards pleasant
and accessible routes, even if takes longer or it has more hills.
rides.

## Case Study

[brouter]: https://brouter.de/brouter-web/#map=14/49.2853/-123.1407/standard&lonlats=-123.126559,49.289796;-123.097153,49.278784;-123.124914,49.279419;-123.135149,49.291143;-123.156363,49.303125;-123.148831,49.272573

||||
| :------------------------: | :------------------------: | :--------------------------: |
| ![](/docs/case2/gmaps.jpg) | ![](/docs/case2/amaps.jpg) | ![](/docs/case2/brouter.jpg) |

## Development

### Build

Until BRouter Web supports permalink/perennial profiles, we need to export the
profile definition for users to import on their browsers:

```bash
poetry run python vancycling_brouter_profile/transpiler.py
```

This command updates the root `vancycling.brf` profile with the current router.

### Test

Tests always use live definitions, so there's no need to build beforehand.

```bash
poetry run python vancycling_brouter_profile/router.py
```
File renamed without changes
File renamed without changes
File renamed without changes
13 changes: 2 additions & 11 deletions vancycling.brf
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Full Example
# https://brouter.de/brouter-web/#map=14/49.2853/-123.1407/standard&lonlats=-123.126559,49.289796;-123.097153,49.278784;-123.124914,49.279419;-123.135149,49.291143;-123.156363,49.303125;-123.148831,49.272573

---context:global

assign validForBikes = true
assign processUnusedTags = false # %processUnusedTags% | Set true to output unused tags in data tab | boolean

---context:way

assign impracticality_penalty =
Expand Down Expand Up @@ -119,12 +114,10 @@ assign costfactor
1

---context:node # following code refers to node tags

assign defaultaccess =
if ( access= ) then true # add default barrier restrictions here!
if ( access= ) then true
else if ( access=private|no ) then false
else true

assign bike_access =
if nodeaccessgranted=yes then true
else if bicycle= then
Expand All @@ -133,12 +126,10 @@ assign bike_access =
else not vehicle=private|no
)
else not bicycle=private|no|dismount

assign footaccess =
if bicycle=dismount then true
else if foot= then defaultaccess
else not foot=private|no

assign initialcost =
if bike_access then 0
else ( if footaccess then 100 else 1000000 )
else ( if footaccess then 10 else 1000000 )
5 changes: 5 additions & 0 deletions vancycling_brouter_profile/brouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from config import log

BROUTER_BASE_URL = "https://www.brouter.de/"
WEB_PREFIX = "brouter-web/#map=13/49.2743/-123.1351/standard"
PROFILE_ID = "custom_1694894568334"


Expand All @@ -24,6 +25,10 @@ def get_route_geojson(points: List[Tuple[int, int]]):
"alternativeidx": 0,
"format": "geojson",
}
log.debug(
f"{BROUTER_BASE_URL}{WEB_PREFIX}&lonlats=%s",
";".join([f"{p.lon},{p.lat}" for p in points]),
)
request = Request("GET", resource_url, params=params).prepare()
response = session.send(request)
route_props = response.json()["features"][0]["properties"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def compile(self):
return Path(DEFAULT_PROFILE_PATH).read_text()

def eval(self, points: List[LonLat]):
log.debug("Routing %s", points)
geojson = brouter.get_route_geojson(points)
route_feature = geojson["features"][0]
data_labels = route_feature["properties"]["messages"][0]
Expand Down
37 changes: 37 additions & 0 deletions vancycling_brouter_profile/transpiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
BEFORE = """
---context:global
assign validForBikes = true
assign processUnusedTags = false # %processUnusedTags% | Set true to output unused tags in data tab | boolean
---context:way
"""

AFTER = """
---context:node # following code refers to node tags
assign defaultaccess =
if ( access= ) then true
else if ( access=private|no ) then false
else true
assign bike_access =
if nodeaccessgranted=yes then true
else if bicycle= then
(
if vehicle= then defaultaccess
else not vehicle=private|no
)
else not bicycle=private|no|dismount
assign footaccess =
if bicycle=dismount then true
else if foot= then defaultaccess
else not foot=private|no
assign initialcost =
if bike_access then 0
else ( if footaccess then 10 else 1000000 )
"""


def transpile():
pass


if __name__ == "__main__":
transpile()

0 comments on commit 0e4f40d

Please sign in to comment.