Skip to content

Commit

Permalink
chore: update isochrone script
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ST0R committed Dec 10, 2024
1 parent cf5208c commit 20c5099
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
1 change: 0 additions & 1 deletion tools/isochrones/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ services:
- ISOCHRONE_DATE=${ISOCHRONE_DATE:-2024-12-16T05%3A00%3A00.000Z}
- CQLP_API=${CQLP_API:-http://host.docker.internal:5000}
- COMPUTE_POSTGRES_URI=${POSTGRES_URI}
- ISOCHRONES_MEMORY_LIMIT=${ISOCHRONES_MEMORY_LIMIT:-4g}
- GRAPHHOPPER_URL=${GRAPHHOPPER_URL:-http://graphhopper:8989}
container_name: isochrones
build:
Expand Down
1 change: 1 addition & 0 deletions tools/isochrones/graphhopper/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ graphhopper:
- bike.json
profiles_ch:
- profile: foot
- profile: bike
graph.encoded_values: foot_access, foot_average_speed, hike_rating, foot_priority, bike_priority, bike_access, roundabout, bike_average_speed,average_slope, hike_rating, country, road_class
import.osm.ignored_highways: motorway,trunk # ,primary

Expand Down
2 changes: 2 additions & 0 deletions tools/isochrones/graphhopper/gtfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function download_and_clean() {
cd gtfs-out
zip -0 $filename *
mv $filename ..
cd ..
rm -Rf gtfs-out
}

download_and_clean https://eu.ftp.opendatasoft.com/stif/GTFS/IDFM-gtfs.zip
Expand Down
2 changes: 2 additions & 0 deletions tools/isochrones/isochrones/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM debian:bookworm-slim
RUN apt-get update
RUN apt-get -y install jq parallel curl

WORKDIR /data

COPY entrypoint.sh entrypoint.sh

ENTRYPOINT ["bash", "entrypoint.sh"]
11 changes: 6 additions & 5 deletions tools/isochrones/isochrones/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#!/bin/bash
set -e

cd /data

curl ${CQLP_API}/api/etablissements >etablissements.json

mkdir -p isochrones

# Create isochrones scripts
readonly GRAPHHOPPER_URL=$GRAPHHOPPER_URL
readonly ISOCHRONE_DATE=$ISOCHRONE_DATE
readonly ISOCHRONE_PARALLEL=$ISOCHRONE_PARALLEL
readonly GRAPHHOPPER_PROFILE=${1:?"Merci de préciser un profil (ex: pt ou bike)"}

shift

TIMES=(5400 3600 2700 1800 900)
for TIME in ${TIMES[@]}; do
mkdir -p isochrones/${GRAPHHOPPER_PROFILE}/${TIME}
jq --raw-output '.[] | select(.latitude!=null)| "\(.uai),\(.latitude),\(.longitude)"' etablissements.json |
awk -F, -v GRAPHHOPPER_PROFILE="$GRAPHHOPPER_PROFILE" -v GRAPHHOPPER_URL="$GRAPHHOPPER_URL" -v DATE="$ISOCHRONE_DATE" -v TIME="$TIME" '{print "curl \""GRAPHHOPPER_URL"/isochrone?point="$2","$3"&profile="GRAPHHOPPER_PROFILE"&pt.earliest_departure_time="DATE"&time_limit="TIME"&buckets=1&result=multipolygon&reverse_flow=true\" > isochrones/"GRAPHHOPPER_PROFILE"/"TIME"/"$1".json"}' >liste_${GRAPHHOPPER_PROFILE}_${TIME}
jq --raw-output '.[] | select(.latitude!=null)| "\(.uai) \(.latitude) \(.longitude)"' etablissements.json |
awk -F, -v GRAPHHOPPER_PROFILE="$GRAPHHOPPER_PROFILE" -v DATE="$ISOCHRONE_DATE" -v TIME="$TIME" '{print GRAPHHOPPER_PROFILE" "DATE" "TIME" "$1" "$2" "$3}' >liste_${GRAPHHOPPER_PROFILE}_${TIME}
done

# Get isochrones
for TIME in ${TIMES[@]}; do
parallel -j $ISOCHRONE_PARALLEL bash -c "{}" <liste_${GRAPHHOPPER_PROFILE}_${TIME}
cat liste_${GRAPHHOPPER_PROFILE}_${TIME} | parallel --colsep ' ' --halt-on-error now,fail=1 -j $ISOCHRONE_PARALLEL bash isochrone.sh {1} {2} {3} {4} {5} {6}
done
18 changes: 18 additions & 0 deletions tools/isochrones/isochrones/isochrone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

readonly GRAPHHOPPER_URL=$GRAPHHOPPER_URL
readonly ISOCHRONE_DATE=$ISOCHRONE_DATE
readonly ISOCHRONE_PARALLEL=$ISOCHRONE_PARALLEL
readonly GRAPHHOPPER_PROFILE=${1:?"Merci de préciser un profil (ex: pt ou bike)"}
readonly DATE=${2:?"Merci de préciser une date"}
readonly TIME=${3:?"Merci de préciser un durée"}
readonly UAI=${4:?"Merci de préciser un uai"}
readonly LATITUDE=${5:?"Merci de préciser une latitude"}
readonly LONGITUDE=${6:?"Merci de préciser une longitude"}
readonly RESULT_FILE="done_${GRAPHHOPPER_PROFILE}_${TIME}"

mkdir -p isochrones/${GRAPHHOPPER_PROFILE}/${TIME}

curl --no-progress-meter "${GRAPHHOPPER_URL}/isochrone?point=${LATITUDE},${LONGITUDE}&profile=${GRAPHHOPPER_PROFILE}&pt.earliest_departure_time=${DATE}&time_limit=${TIME}&buckets=1&result=multipolygon&reverse_flow=true" >isochrones/${GRAPHHOPPER_PROFILE}/${TIME}/${UAI}.json
echo "done: ${UAI}" >>${RESULT_FILE}

0 comments on commit 20c5099

Please sign in to comment.