From 65dace7235f0a158ea5729683425090417d366b0 Mon Sep 17 00:00:00 2001 From: Sam Cedarbaum Date: Wed, 18 Sep 2024 12:14:14 -0400 Subject: [PATCH] Optionally inherit wheelchair boarding from parent station (#17) --- static.go | 16 +++++++- static_test.go | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/static.go b/static.go index dc50bd8..6858459 100644 --- a/static.go +++ b/static.go @@ -149,7 +149,11 @@ type Frequency struct { ExactTimes ExactTimes } -type ParseStaticOptions struct{} +type ParseStaticOptions struct { + // If true, wheelchair boarding information is inherited from parent station + // when unspecified for a child stop/platform, entrance, or exit. + InheritWheelchairBoarding bool +} // ParseStatic parses the content as a GTFS static feed. func ParseStatic(content []byte, opts ParseStaticOptions) (*Static, error) { @@ -278,6 +282,16 @@ func ParseStatic(content []byte, opts ParseStaticOptions) (*Static, error) { } } + // Inherit wheelchair boarding from parent stops if specified. + if opts.InheritWheelchairBoarding { + for i := range result.Stops { + stop := &result.Stops[i] + if stop.Parent != nil && stop.Parent.Type == StopType_Station && stop.WheelchairBoarding == WheelchairBoarding_NotSpecified { + stop.WheelchairBoarding = stop.Parent.WheelchairBoarding + } + } + } + return result, nil } diff --git a/static_test.go b/static_test.go index 36e04e7..4f7a59a 100644 --- a/static_test.go +++ b/static_test.go @@ -1011,6 +1011,111 @@ func TestParse(t *testing.T) { }, }, }, + { + desc: "stop inherits parent wheelchair boarding, accessible", + content: newZipBuilder().add( + "stops.txt", + "stop_id,location_type,parent_station,wheelchair_boarding", + "a,,b,", + "b,1,,1", + ).build(), + opts: ParseStaticOptions{ + InheritWheelchairBoarding: true, + }, + expected: &Static{ + Stops: []Stop{ + { + Id: "a", + Type: StopType_Platform, + Parent: &Stop{Id: "b", WheelchairBoarding: WheelchairBoarding_Possible, Type: StopType_Station}, + WheelchairBoarding: WheelchairBoarding_Possible, + }, + { + Id: "b", + Type: StopType_Station, + WheelchairBoarding: WheelchairBoarding_Possible, + }, + }, + }, + }, + { + desc: "stop inherits parent wheelchair boarding, inaccessible", + content: newZipBuilder().add( + "stops.txt", + "stop_id,location_type,parent_station,wheelchair_boarding", + "a,,b,", + "b,1,,2", + ).build(), + opts: ParseStaticOptions{ + InheritWheelchairBoarding: true, + }, + expected: &Static{ + Stops: []Stop{ + { + Id: "a", + Type: StopType_Platform, + Parent: &Stop{Id: "b", WheelchairBoarding: WheelchairBoarding_NotPossible, Type: StopType_Station}, + WheelchairBoarding: WheelchairBoarding_NotPossible, + }, + { + Id: "b", + Type: StopType_Station, + WheelchairBoarding: WheelchairBoarding_NotPossible, + }, + }, + }, + }, + { + desc: "stop doesn't inherit parent wheelchair boarding when option is false", + content: newZipBuilder().add( + "stops.txt", + "stop_id,location_type,parent_station,wheelchair_boarding", + "a,,b,", + "b,1,,1", + ).build(), + opts: ParseStaticOptions{ + InheritWheelchairBoarding: false, + }, + expected: &Static{ + Stops: []Stop{ + { + Id: "a", + Type: StopType_Platform, + Parent: &Stop{Id: "b", WheelchairBoarding: WheelchairBoarding_Possible, Type: StopType_Station}, + WheelchairBoarding: WheelchairBoarding_NotSpecified, + }, + { + Id: "b", + Type: StopType_Station, + WheelchairBoarding: WheelchairBoarding_Possible, + }, + }, + }, + }, + { + desc: "stop doesn't inherit parent wheelchair boarding by default", + content: newZipBuilder().add( + "stops.txt", + "stop_id,location_type,parent_station,wheelchair_boarding", + "a,,b,", + "b,1,,1", + ).build(), + expected: &Static{ + Stops: []Stop{ + { + Id: "a", + Type: StopType_Platform, + Parent: &Stop{Id: "b", WheelchairBoarding: WheelchairBoarding_Possible, Type: StopType_Station}, + WheelchairBoarding: WheelchairBoarding_NotSpecified, + }, + { + Id: "b", + Type: StopType_Station, + WheelchairBoarding: WheelchairBoarding_Possible, + }, + }, + }, + }, } { t.Run(tc.desc, func(t *testing.T) { actual, err := ParseStatic(tc.content, tc.opts)