Skip to content

Commit

Permalink
refactor: Add script to delete routes from the test Portland gtfs dat…
Browse files Browse the repository at this point in the history
…a set.

This script can be used to debug test witch only uses a subset of the trips - removing the other
trips makes it easier to debug.
  • Loading branch information
t2gran committed Aug 27, 2024
1 parent 7044c27 commit eafb374
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions script/test-portland-gtfs-rm-routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

# This script can be used to delete routes from the Portland GTFS test data set.
# The script can remove a singe route or a range. Run the script from the OTP root.
# The script assume trip ida are constructed in a particular way; Hence can not
# be ysed on other gtfs data-set.
#
# To remove a single route with ID 4:
#
# > script/test-portland-gtfs-rm-routes 4
#
#
# To remove all routes with ID 9(inclusive) to 73(exclusive):
#
# > script/test-portland-gtfs-rm-routes 9 73
#

pushd src/test/resources/portland/gtfs

SERVICE_CODES="2fdkpABCKUPSWX"

# This function takes one argument, the route ID
function removeRoute() {
TRIP_ID="${1}[01][${SERVICE_CODES}]"
echo "Remove route $1 and trips witch match: ${TRIP_ID}"
grep -v -E "^${1}," routes.txt > routes2.txt
mv routes2.txt routes.txt

grep -v -E "^$1," trips.txt > trips2.txt
mv trips2.txt trips.txt

grep -v -E "^${TRIP_ID}" stop_times.txt > stop_times2.txt
mv stop_times2.txt stop_times.txt

grep -v -E "^\d+,\d+,${1}," transfers.txt > transfers2.txt
grep -v -E "^\d+,\d+,\d+,${1}," transfers2.txt > transfers3.txt
mv transfers3.txt transfers.txt
rm transfers2.txt

grep -v -E "\d+,${1}," fare_rules.txt > fare_rules2.txt
mv fare_rules2.txt fare_rules.txt
}


if [ "$1" == "" ]
then
echo "Specify a route to remove or an range!"
popd
exit 1
fi

if [ "$2" == "" ]
then
removeRoute $1
else
for ((i=$1; i <$2; ++i))
do
removeRoute $i
done
fi

popd

0 comments on commit eafb374

Please sign in to comment.