Skip to content

Commit

Permalink
Optionally inherit wheelchair boarding from parent station
Browse files Browse the repository at this point in the history
  • Loading branch information
cedarbaum committed Sep 18, 2024
1 parent d57d457 commit 51bde3b
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
16 changes: 15 additions & 1 deletion static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
105 changes: 105 additions & 0 deletions static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 51bde3b

Please sign in to comment.