From 8285eeaf7d46a2b50e169df2690ae2e990e2c517 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 21 Dec 2020 14:49:06 +0100 Subject: use objects in wagon list --- README.md | 50 +++++++++++++++++++++++------------------------ bin/db-zugbildung-to-json | 7 ++++++- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 5b7a57e..d7e142f 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ Graphical cycle maps are available on This README documents **version 0** of the format. It is not stable yet; data layout or semantic changes may not be reflected in the version number. -Starting with v1, schema and semantics will be stable. +Starting with v1, schema and semantics will be stable. See also the +[OpenAPI spec](https://lib.finalrewind.org/dbdb/db_zugbildung_v0.yml). ```js { @@ -248,30 +249,29 @@ expressions and may miss rarely used wagon types. ```js { "wagons": [ - [ - "DBpbzfa", - "1" - ], - [ - "DBpza", - "2" - ], - [ - "DBpza", - "3" - ], - [ - "DBpza", - "4" - ], - [ - "DApza", - "5" - ], - [ - "147.5", - null - ] + { + "type": "DBpbzfa", + "number": 1 + }, + { + "type": "DBpza", + "number": 2 + }, + { + "type": "DBpza", + "number": 3 + }, + { + "type": "DBpza", + "number": 4 + }, + { + "type": "DApza", + "number": 5 + }, + { + type: "147.5", + } ] } ``` diff --git a/bin/db-zugbildung-to-json b/bin/db-zugbildung-to-json index f5439d1..849d685 100755 --- a/bin/db-zugbildung-to-json +++ b/bin/db-zugbildung-to-json @@ -574,7 +574,12 @@ for my $train_number ( keys %map ) { for my $wagon ( @{ $wagon_map{$train_number} // [] } ) { my ( $wagon_type, $wagon_number ) = @{$wagon}; - push( @{ $map{$train_number}{wagons} }, $wagon ); + my $json_wagon = { type => $wagon_type }; + if ($wagon_number) { + $json_wagon->{number} = 0 + $wagon_number; + } + + push( @{ $map{$train_number}{wagons} }, $json_wagon ); if ( $wagon_type =~ m{ 40[1-9] | 14[67] }x ) { next; -- cgit v1.2.3