Skip to content

Commit

Permalink
Label roots in route types with parent = -1 (#348)
Browse files Browse the repository at this point in the history
Avoids parent=0 default zero value
  • Loading branch information
irees committed Jul 16, 2024
1 parent 22ac281 commit 61217a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tl/tt/routetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ package tt

// RouteType contains details on each possible route_type
type RouteType struct {
Code int
Name string
Category string
Parent int
Code int `json:"code"`
Name string `json:"name"`
Category string `json:"category"`
Parent int `json:"parent"`
}

// routeTypes is the list of all known extended route_types.
// See https://developers.google.com/transit/gtfs/reference/extended-route-types
// All types are mapped back to a basic GTFS primitive.
// Those that don't fit well are mapped to bus for compatibility.
var routeTypes = []RouteType{
{Code: 0, Name: "Tram"},
{Code: 1, Name: "Metro"},
{Code: 2, Name: "Rail"},
{Code: 3, Name: "Bus"},
{Code: 4, Name: "Ferry"},
{Code: 5, Name: "Cablecar"},
{Code: 6, Name: "Gondola"},
{Code: 7, Name: "Funicular"},
{Code: 11, Name: "Trolleybus"},
{Code: 12, Name: "Monorail"},
{Code: 0, Name: "Tram", Parent: -1},
{Code: 1, Name: "Metro", Parent: -1},
{Code: 2, Name: "Rail", Parent: -1},
{Code: 3, Name: "Bus", Parent: -1},
{Code: 4, Name: "Ferry", Parent: -1},
{Code: 5, Name: "Cablecar", Parent: -1},
{Code: 6, Name: "Gondola", Parent: -1},
{Code: 7, Name: "Funicular", Parent: -1},
{Code: 11, Name: "Trolleybus", Parent: -1},
{Code: 12, Name: "Monorail", Parent: -1},

{Code: 100, Name: "Railway Service", Parent: 2},
{Code: 101, Name: "High Speed Rail Service", Parent: 2},
Expand Down
11 changes: 11 additions & 0 deletions tl/tt/routetypes_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tt

import (
"encoding/json"
"sort"
"testing"
)
Expand Down Expand Up @@ -46,6 +47,16 @@ func TestGetBasicRouteType(t *testing.T) {
}
}

func Test_RouteTypeJson(t *testing.T) {
// This test exists only to dump the route type list to json
// for use in other applications.
jj, err := json.Marshal(routeTypes)
if err != nil {
t.Fatal(err)
}
t.Log(string(jj))
}

func TestGetRouteType(t *testing.T) {
tests := []struct {
code int
Expand Down

0 comments on commit 61217a2

Please sign in to comment.