Skip to content

Commit

Permalink
Try again to re-add link.json
Browse files Browse the repository at this point in the history
Also:
- try to fix benchmarking/coverage reports #394
- Fix bug in build osm roadnet.py
  • Loading branch information
e-lo committed Oct 18, 2024
1 parent 8bed3cc commit 7483fd6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
55 changes: 13 additions & 42 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Push Workflow
on: [push]

jobs:
build:
tests:

runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -32,56 +32,27 @@ jobs:
pip install -r requirements.docs.txt
- name: Install package
run: |
pip install -e .[test]
pip install -e .
- name: Run Ruff
run: ruff check --output-format=github network_wrangler
- name: Run tests with coverage and benchmarking
run: |
set -o pipefail
pytest --junitxml=pytest.xml \
pytest --junitxml=coverage.xml \
--benchmark-save=pr_benchmark \
--benchmark-json=pr_benchmark.json \
--cov-report=term-missing:skip-covered \
--cov=network_wrangler tests/ 2>&1 | \
tee -a pytest-coverage.txt
--cov=network_wrangler tests
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
tool: 'pytest'
output-file-path: pr_benchmark.json
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: true
summary-always: true
- name: Pytest coverage comment
if: github.event_name == 'pull_request'
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
- name: If a pull request, add a comment about coverage
if: github.event_name == 'pull_request'
uses: coroo/[email protected]
- name: Retrieve benchmark results from base branch
if: github.event_name == 'pull_request'
id: compare
run: |
git checkout ${{ github.event.pull_request.base.ref }}
if [ -f "tests/.benchmarks/benchmark_results.json" ]; then
cp tests/.benchmarks/benchmark_results.json base_benchmark.json
echo "::set-output name=benchmark_exists::true"
else
echo "::set-output name=benchmark_exists::false"
fi
- name: Compare benchmarks
if: steps.compare.outputs.benchmark_exists == 'true'
run: |
pytest-benchmark compare base_benchmark.json pr_benchmark.json --csv=comparison.csv --json=comparison.json --histogram=histogram.png
- name: Post comparison comment on pull request
if: steps.compare.outputs.benchmark_exists == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: 'Benchmark Comparison'
message: |
## Benchmark Results
![Benchmark Comparison](./histogram.png)
| Test name | PR Benchmark | Base Benchmark | Difference |
| --------- | ------------ | -------------- | ---------- |
```bash
pytest-benchmark compare base_benchmark.json pr_benchmark.json --csv --diff
```
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
junitxml-path: ./coverage.xml
2 changes: 1 addition & 1 deletion examples/stpaul/link.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions network_wrangler/bin/build_basic_osm_roadnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
from network_wrangler.utils.utils import make_slug

ACCESS_LOOKUPS = {
"rail_only": ["railway"],
"walk_access": ["footway", "path", "steps", "residential"],
"bike_access": ["path", "cycleway", "service", "tertiary", "residential"],
"drive_access": ~["footway", "path", "steps", "cycleway", None],
"truck_access": ~["footway", "path", "steps", "cycleway", None],
"rail_only": {"allow": ["railway"]},
"walk_access": {"allow": ["footway", "path", "steps", "residential"]},
"bike_access": {"allow": ["path", "cycleway", "service", "tertiary", "residential"]},
"drive_access": {"deny": ["footway", "path", "steps", "cycleway"]},
"truck_access": {"deny": ["footway", "path", "steps", "cycleway"]},
}

LANES_LOOKUPS = {
Expand Down Expand Up @@ -89,8 +89,13 @@ def osm_edges_to_wr_links(edges, access_lookups=ACCESS_LOOKUPS, lanes_lookup=LAN
"""Converts OSM edges to Wrangler links."""
links_df = edges.reset_index()
links_df = links_df.loc[:, list(link_field_dict.keys())].rename(columns=link_field_dict)
for access_field, access_values in access_lookups.items():
links_df[access_field] = links_df.roadway.isin(access_values)
for access_field, allow_deny in access_lookups.items():
if allow_deny.get("allow"):
access_values = allow_deny["allow"]
links_df[access_field] = links_df.roadway.isin(access_values)
elif allow_deny.get("deny"):
noaccess_values = allow_deny["deny"]
links_df[access_field] = ~links_df.roadway.isin(noaccess_values)
links_df["lanes"] = links_df["roadway"].map(lanes_lookup)
links_df.A = links_df.A.astype(int)
links_df.B = links_df.B.astype(int)
Expand Down

0 comments on commit 7483fd6

Please sign in to comment.