Skip to content

Commit

Permalink
Transform scheduled stop point IDs before importing into OTP (#231)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
leonardehrenfried authored Jan 21, 2025
1 parent e225e9d commit 3a00a5d
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ journey/tmp
geocoder/.env

graph.obj

*.xml
*.zip
saxon
2 changes: 1 addition & 1 deletion .otp-version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: NOI Techpark <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0
export OTP_IMAGE="opentripplanner/opentripplanner:2.7.0_2024-11-19T11-28"
export OTP_IMAGE="lehrenfried/opentripplanner:siri-scheduled-stop-point"
28 changes: 27 additions & 1 deletion build-graph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ TRANSIT_NETEX_URL="https://rapuser:[email protected]/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
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/docker/otp/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 9 additions & 3 deletions router-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 47 additions & 0 deletions transform-scheduled-stop-point-ids.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: NOI Techpark <[email protected]>
SPDX-License-Identifier: CC0-1.0
-->
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:n="http://www.netex.org.uk/netex"
xsi:schemaLocation="http://www.netex.org.uk/netex https://raw.githubusercontent.com/NeTEx-CEN/NeTEx/master/xsd/NeTEx_publication.xsd"
exclude-result-prefixes="n" >

<!-- Identity template to copy every node and attribute by default -->
<xsl:mode on-no-match="shallow-copy"/>

<!--
Replace the IDs of ScheduledStopPoints from this format
it:apb:ScheduledStopPoint:it-22101-7010-51-32073:
to this
it:22101:7010:51:32073
.
This because the SIRI feeds use the latter format, and we need to match up the two sources.
-->
<xsl:template match="//n:ScheduledStopPoint/@id">
<xsl:attribute name="id">
<xsl:value-of select="replace(replace(., '.*ScheduledStopPoint:(.+?):$', '$1'), '-', ':')"/>
</xsl:attribute>
</xsl:template>

<xsl:template match="//n:RoutePointRef/@ref">
<xsl:attribute name="ref">
<xsl:value-of select="replace(replace(., '.*ScheduledStopPoint:(.+?):$', '$1'), '-', ':')"/>
</xsl:attribute>
</xsl:template>

<xsl:template match="//n:ScheduledStopPointRef/@ref">
<xsl:attribute name="ref">
<xsl:value-of select="replace(replace(., '.*ScheduledStopPoint:(.+?):$', '$1'), '-', ':')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 3a00a5d

Please sign in to comment.