From 3a00a5d81217196c3f27085bdaa225a6ef10cea3 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 21 Jan 2025 09:58:08 +0100 Subject: [PATCH] Transform scheduled stop point IDs before importing into OTP (#231) * Implement XSLT for transforming ScheduledStopPoints * Add documentation * Add reuse headers * Run XLST during build * Use specific Saxon directory * Update input file name * use correct file name * Exclude Amarillo feed * Add artifact * Move transformed file into data * Add SIRI-Lite feeds * Add test for EntityResolver * Remove separate script * Use un-released version to use scheduled stop points * Re-enable Amarillo * Bump actions version --- .github/workflows/main.yml | 7 ++++ .gitignore | 4 +++ .otp-version | 2 +- build-graph.sh | 28 ++++++++++++++- infrastructure/docker/otp/Dockerfile | 2 +- router-config.json | 12 +++++-- transform-scheduled-stop-point-ids.xsl | 47 ++++++++++++++++++++++++++ 7 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 transform-scheduled-stop-point-ids.xsl diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c33a9c42..ec6351c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -140,6 +140,13 @@ jobs: # the script uses error handling with +e, so please don't run it with bash prepended in this line run: ./build-graph.sh + + - name: Store artifact for sta.netex.correct-ssids.xml + uses: actions/upload-artifact@v4 + with: + name: sta-netex-correct-ssids + path: data/sta.netex.correct-ssids.xml + - name: Build and push if: github.repository_owner == 'noi-techpark' uses: noi-techpark/github-actions/docker-build-and-push@v2 diff --git a/.gitignore b/.gitignore index 7ab46a8a..e875bf87 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ journey/tmp geocoder/.env graph.obj + +*.xml +*.zip +saxon diff --git a/.otp-version b/.otp-version index 4f886cd9..ec52d577 100644 --- a/.otp-version +++ b/.otp-version @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: NOI Techpark # # SPDX-License-Identifier: CC0-1.0 -export OTP_IMAGE="opentripplanner/opentripplanner:2.7.0_2024-11-19T11-28" \ No newline at end of file +export OTP_IMAGE="lehrenfried/opentripplanner:siri-scheduled-stop-point" \ No newline at end of file diff --git a/build-graph.sh b/build-graph.sh index 72112e31..1fa059c9 100755 --- a/build-graph.sh +++ b/build-graph.sh @@ -22,6 +22,15 @@ TRANSIT_NETEX_URL="https://rapuser:rappass@web01.sta.bz.it/netex/api/v4/download TRANSIT_NETEX_XML=data/sta-netex.xml TRANSIT_NETEX_GZ=${TRANSIT_NETEX_XML}.gz TRANSIT_NETEX_ZIP=${TRANSIT_NETEX_XML}.zip + +# config for transforming the ids of scheduled stop points +SAXON_URL="https://github.com/Saxonica/Saxon-HE/releases/download/SaxonHE12-5/SaxonHE12-5J.zip" +SAXON_ZIP="saxon.zip" +SAXON_JAR="saxon/saxon-he-12.5.jar" +XSL_FILE="transform-scheduled-stop-point-ids.xsl" + +SSIDS_TRANSFORMED_XML="data/sta.netex.correct-ssids.xml" + # parking PARKING_NETEX_URL=https://transmodel.api.opendatahub.com/netex/parking PARKING_NETEX_XML=data/shared-data.xml @@ -55,7 +64,24 @@ rm -f ${TRANSIT_NETEX_ZIP} echo "Downloading NeTEx transit data from ${TRANSIT_NETEX_URL}" ${CURL} "${TRANSIT_NETEX_URL}" -o ${TRANSIT_NETEX_GZ} gunzip --force ${TRANSIT_NETEX_GZ} -zip ${TRANSIT_NETEX_ZIP} ${TRANSIT_NETEX_XML} + +# Configuration + +if [ ! -f "${SAXON_JAR}" ]; then + $CURL $SAXON_URL -o $SAXON_ZIP + unzip $SAXON_ZIP -d saxon +fi + +# the scheduled stop point ids and the SIRI StopPointRefs do not match, so we have to transform +# the NeTEx feed so that they do: https://github.com/noi-techpark/odh-mentor-otp/issues/215 +echo "Running Saxon transformation..." +java -jar "$SAXON_JAR" -s:"${TRANSIT_NETEX_XML}" -xsl:"$XSL_FILE" -o:"$SSIDS_TRANSFORMED_XML" + + +zip ${TRANSIT_NETEX_ZIP} ${SSIDS_TRANSFORMED_XML} + +ls -lah +ls -lah data # download parking data and put it into a zip rm -f ${PARKING_NETEX_XML} ${PARKING_NETEX_ZIP} diff --git a/infrastructure/docker/otp/Dockerfile b/infrastructure/docker/otp/Dockerfile index 2ae52b4a..2987e045 100644 --- a/infrastructure/docker/otp/Dockerfile +++ b/infrastructure/docker/otp/Dockerfile @@ -1,5 +1,5 @@ # Simon, do you know how we could use the value from .otp-version here? -FROM opentripplanner/opentripplanner:2.7.0_2024-11-19T11-28 +FROM lehrenfried/opentripplanner:siri-scheduled-stop-point WORKDIR /var/otp diff --git a/router-config.json b/router-config.json index 0aafa0b0..3cab3cb3 100644 --- a/router-config.json +++ b/router-config.json @@ -78,9 +78,15 @@ }, "updaters": [ { - "type": "stop-time-updater", - "url": "https://mobility.api.opendatahub.testingmachine.eu/v2/GTFS-RT", - "feedId": "sta" + "type": "siri-et-lite", + "feedId": "sta", + "url": "https://efa.sta.bz.it/siri-lite/estimated-timetable/xml", + "fuzzyTripMatching": true + }, + { + "type": "siri-sx-lite", + "feedId": "sta", + "url": "https://efa.sta.bz.it/siri-lite/situation-exchange/xml" }, { "type" : "vehicle-rental", diff --git a/transform-scheduled-stop-point-ids.xsl b/transform-scheduled-stop-point-ids.xsl new file mode 100644 index 00000000..8538fcee --- /dev/null +++ b/transform-scheduled-stop-point-ids.xsl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file