diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-12-21 13:20:27 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-12-21 13:20:27 +0100 |
commit | b2d381a1267771a7045292acc2109f6ddab1fad5 (patch) | |
tree | 2a8aeac9434d0531b31f0cd3447ad79c7d83c527 | |
parent | a810aa9e4a3c42afc60c09e8ac7e82f92c7c3c41 (diff) |
Avoid null properties
-rw-r--r-- | README.md | 9 | ||||
-rwxr-xr-x | bin/db-zugbildung-to-json | 8 |
2 files changed, 12 insertions, 5 deletions
@@ -169,24 +169,23 @@ Otherwise, the property is not present. It is **reliable**. "Erfurt (07:40/07:45)", "Nürnberg" ], - "postEnd": null, "preStart": "Berlin-Rummelsburg (Triebzuganlage)", "start": "Berlin-Gesundbrunnen (05:53)" } } ``` -Scheduled route. It is divided into five parts: +Scheduled route. It contains up to five properties: -* **preStart**: Station (without passenger service) where the train is prepared / provisioned. May be null. +* **preStart**: Station (without passenger service) where the train is prepared / provisioned. * **start**: First station(s) with passenger service. Often contains the scheduled departure time. * **middle**: List of noteworthy stations along the route. May be empty. This is not the complete route. Individual stations may contain timestamps. * **end**: Terminal station(s) with passenger service. Often contains the scheduled arrival time. -* **postEnd**: Station (without passenger service) where the train is parked. May be null. +* **postEnd**: Station (without passenger service) where the train is parked. Station entries are taken as-is from the PDF file. They may differ from station -names used in iris-tts or HAFAS. A null preStart / postEnd entry does not +names used in iris-tts or HAFAS. A missing preStart / postEnd entry does not imply that the train is prepared / parked at the first / last station with passenger service. Station names may be surrounded by brackets. diff --git a/bin/db-zugbildung-to-json b/bin/db-zugbildung-to-json index c00b784..759f2f7 100755 --- a/bin/db-zugbildung-to-json +++ b/bin/db-zugbildung-to-json @@ -440,6 +440,14 @@ for my $train ( values %map ) { end => $end, postEnd => $post_end, }; + + for my $k ( keys %{ $train->{route} } ) { + if ( not defined $train->{route}{$k} ) { + + # avoid null values (leave out the property instead) + delete $train->{route}{$k}; + } + } } for my $train ( values %map ) { |