From b2d381a1267771a7045292acc2109f6ddab1fad5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 21 Dec 2020 13:20:27 +0100 Subject: Avoid null properties --- README.md | 9 ++++----- bin/db-zugbildung-to-json | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a6cb99f..5b7a57e 100644 --- a/README.md +++ b/README.md @@ -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 ) { -- cgit v1.2.3