Skip to content

Commit

Permalink
Move the dev-data docs to an executable script
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Feb 7, 2025
1 parent d7072f6 commit 0197992
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
48 changes: 3 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,9 @@ with the latest OSM data. For speed and for deterministic tests, there are also
automatically use the latest OSM data. These are manually managed and hosted by
Dustin on assets.od2net.org.

If you're developing locally, you can avoid hitting od2net.org by setting up
two directories in `web/public/`: `severance_pbfs` and `boundaries`. If
`web/public/severance_pbfs/areas.json` exists, then the Svelte app will load
from localhost, not od2net.org. You can copy from od2net.org to set this up,
choosing what study areas to cache:

```
AREAS="bristol edinburgh strasbourg ut_dallas"
cd web/public
mkdir boundaries severance_pbfs
cd severance_pbfs
wget https://assets.od2net.org/severance_pbfs/areas.json
for x in $AREAS; do
wget https://assets.od2net.org/severance_pbfs/$x.pbf
done
cd ../boundaries
for x in $AREAS; do
wget https://assets.od2net.org/boundaries/$x.geojson
done
cd ..
```

There are four more directories particular to Scotland. To cache all of that data:

```
# Still in web/public
mkdir cnt_osm cnt_boundaries cnt_demand cnt_layers
jq '.features[] | .properties.kind + "_" + .properties.name' ../../data_prep/scotland/boundaries.geojson | sed 's/"//g' | while read x; do
wget https://assets.od2net.org/cnt_boundaries/$x.geojson
wget https://assets.od2net.org/cnt_osm/$x.osm.pbf
wget https://assets.od2net.org/cnt_demand/$x.bin
mv $x.geojson cnt_boundaries
mv $x.osm.pbf cnt_osm
mv $x.bin cnt_demand
done
cd cnt_layers
for x in cbd.pmtiles gp_practices.geojson hospitals.geojson population.pmtiles route_network.pmtiles schools.geojson; do
wget https://assets.od2net.org/cnt_layers/$x
done
```
If you're developing locally, you can avoid hitting od2net.org by running
`bin/download-local-dev-data.sh` to download some pre-clipped application
data locally, then the Svelte app will load from localhost, not od2net.org.

### Tests

Expand Down
39 changes: 39 additions & 0 deletions bin/download-local-dev-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# "normally" the app downloads the latest data from Overpass API based on the
# user's clipped areas.
#
# For expediency and deterministic tests, this script downloads some
# pre-configured areas, which the web app will load from localhost.

cd "$(git rev-parse --show-toplevel)"

download_to_subdir() {
local subdir=$1
local url=$2

mkdir -p "$subdir"
(wget -P "$subdir" --timestamping "$url" && echo "$url") \
|| echo "❌ Download failed: $url"
}

cd web/public

download_to_subdir osm https://assets.od2net.org/severance_pbfs/areas.json

# Global data used for tests and demo data
AREAS="bristol edinburgh strasbourg ut_dallas"
for x in $AREAS; do
download_to_subdir severance_pbfs "https://assets.od2net.org/severance_pbfs/$x.pbf"
download_to_subdir boundaries "https://assets.od2net.org/boundaries/$x.geojson"
done

# Scotland specific data
jq '.features[] | .properties.kind + "_" + .properties.name' ../../data_prep/scotland/boundaries.geojson | sed 's/"//g' | while read x; do
download_to_subdir cnt_boundaries "https://assets.od2net.org/cnt_boundaries/$x.geojson"
download_to_subdir cnt_osm "https://assets.od2net.org/cnt_osm/$x.osm.pbf"
# OD Demand model
download_to_subdir cnt_demand "https://assets.od2net.org/cnt_demand/demand_$x.bin"
done

for x in cbd.pmtiles gp_practices.geojson hospitals.geojson population.pmtiles route_network.pmtiles schools.geojson; do
download_to_subdir cnt_layers https://assets.od2net.org/cnt_layers/$x
done

0 comments on commit 0197992

Please sign in to comment.