Skip to content

Commit 2d62e6d

Browse files
committed
back to simpler
1 parent aba90a5 commit 2d62e6d

7 files changed

Lines changed: 6 additions & 150 deletions

File tree

server/directions/awsrouter/awsrouter.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ func NewRouter(lc LocationClient, calculator string) *Router {
6666
}
6767
}
6868

69-
func (h *Router) Capabilities() directions.Capabilities {
70-
return directions.Capabilities{
71-
SupportedModes: []model.StepMode{model.StepModeAuto, model.StepModeWalk},
72-
SupportsArriveBy: false,
73-
}
74-
}
75-
7669
func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*model.Directions, error) {
7770
// Input validation
7871
if err := directions.ValidateDirectionRequest(req); err != nil {

server/directions/directions.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ import (
1111
"github.com/interline-io/transitland-lib/server/model"
1212
)
1313

14-
// Capabilities describes what a routing handler supports.
15-
type Capabilities struct {
16-
SupportedModes []model.StepMode
17-
SupportsArriveBy bool
18-
}
19-
2014
type Handler interface {
2115
Request(context.Context, model.DirectionRequest) (*model.Directions, error)
22-
Capabilities() Capabilities
2316
}
2417

2518
type handlerFunc func() Handler
@@ -81,13 +74,6 @@ func HandleRequest(ctx context.Context, pref string, req model.DirectionRequest)
8174
return &model.Directions{Success: false, Exception: &a}, nil
8275
}
8376

84-
// Validate request against handler capabilities
85-
caps := handler.Capabilities()
86-
if req.ArriveBy != nil && *req.ArriveBy && !caps.SupportsArriveBy {
87-
a := "arrive_by is not supported by this routing provider"
88-
return &model.Directions{Success: false, Exception: &a}, nil
89-
}
90-
9177
// Call the handler
9278
h, err := handler.Request(ctx, req)
9379
a := log.For(ctx).Trace()

server/directions/directions_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

server/directions/directionstest/directionstest.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ func MakeBasicTests() map[string]model.DirectionRequest {
4242
To: &BaseTo,
4343
DepartAt: &BaseTime,
4444
},
45-
"transit_arrive_by": {
46-
Mode: model.StepModeTransit,
47-
From: &BaseFrom,
48-
To: &BaseTo,
49-
DepartAt: &BaseTime,
50-
ArriveBy: ptrBool(true),
51-
},
5245
"no_dest_fail": {
5346
Mode: model.StepModeWalk,
5447
From: &BaseFrom,
@@ -107,6 +100,3 @@ func HandlerTest(t *testing.T, h directions.Handler, tc TestCase) *model.Directi
107100
return ret
108101
}
109102

110-
func ptrBool(v bool) *bool {
111-
return &v
112-
}

server/directions/linerouter/linerouter.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ type Router struct {
2525
Clock clock.Clock
2626
}
2727

28-
func (h *Router) Capabilities() directions.Capabilities {
29-
return directions.Capabilities{
30-
SupportedModes: []model.StepMode{model.StepModeAuto, model.StepModeBicycle, model.StepModeWalk, model.StepModeTransit, model.StepModeLine},
31-
SupportsArriveBy: false,
32-
}
33-
}
34-
3528
func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*model.Directions, error) {
3629
// Prepare response
3730
ret := model.Directions{

server/directions/tlrouter/tlrouter.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ func NewRouter(client *http.Client, endpoint string, apikey string) *Router {
6060
}
6161
}
6262

63-
func (h *Router) Capabilities() directions.Capabilities {
64-
return directions.Capabilities{
65-
SupportedModes: []model.StepMode{model.StepModeTransit, model.StepModeWalk, model.StepModeBicycle},
66-
SupportsArriveBy: true,
67-
}
68-
}
69-
7063
func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*model.Directions, error) {
7164
if err := directions.ValidateDirectionRequest(req); err != nil {
7265
return &model.Directions{Success: false, Exception: aws.String("invalid input")}, nil

server/directions/valhalla/valhalla.go

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ func NewRouter(client *http.Client, endpoint string, apikey string) *Router {
5757
}
5858
}
5959

60-
func (h *Router) Capabilities() directions.Capabilities {
61-
return directions.Capabilities{
62-
SupportedModes: []model.StepMode{model.StepModeAuto, model.StepModeBicycle, model.StepModeWalk},
63-
SupportsArriveBy: true,
64-
}
65-
}
66-
6760
func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*model.Directions, error) {
6861
if err := directions.ValidateDirectionRequest(req); err != nil {
6962
return &model.Directions{Success: false, Exception: aws.String("invalid input")}, nil
@@ -78,7 +71,7 @@ func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*mode
7871
input.Costing = "auto"
7972
case model.StepModeBicycle:
8073
input.Costing = "bicycle"
81-
case model.StepModeWalk:
74+
case model.StepModeWalk, model.StepModeTransit:
8275
input.Costing = "pedestrian"
8376
default:
8477
return &model.Directions{Success: false, Exception: aws.String("unsupported travel mode")}, nil
@@ -97,27 +90,14 @@ func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*mode
9790
// Ensure we are in UTC
9891
departAt = departAt.In(time.UTC)
9992

100-
// Set date_time for time-aware routing
101-
arriveBy := req.ArriveBy != nil && *req.ArriveBy
102-
if req.DepartAt != nil {
103-
dtType := 1 // depart_at
104-
if arriveBy {
105-
dtType = 2 // arrive_by
106-
}
107-
input.DateTime = &DateTime{
108-
Type: dtType,
109-
Value: departAt.Format("2006-01-02T15:04"),
110-
}
111-
}
112-
11393
// Make request
11494
res, err := makeRequest(ctx, input, h.client, h.endpoint, h.apikey)
11595
if err != nil || len(res.Trip.Legs) == 0 {
11696
log.For(ctx).Error().Err(err).Msg("valhalla router failed to calculate route")
11797
return &model.Directions{Success: false, Exception: aws.String("could not calculate route")}, nil
11898
}
11999
// Prepare response
120-
ret := makeDirections(res, departAt, arriveBy)
100+
ret := makeDirections(res, departAt)
121101
ret.Origin = wpiWaypoint(req.From)
122102
ret.Destination = wpiWaypoint(req.To)
123103
ret.Success = true
@@ -154,7 +134,7 @@ func makeRequest(ctx context.Context, req Request, client *http.Client, endpoint
154134
return &res, nil
155135
}
156136

157-
func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *model.Directions {
137+
func makeDirections(res *Response, departAt time.Time) *model.Directions {
158138
// Create itinerary summary
159139
itin := model.Itinerary{}
160140

@@ -166,15 +146,8 @@ func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *mode
166146
ret.EndTime = &itin.EndTime
167147
ret.DataSource = aws.String("OSM")
168148

169-
// When arrive_by is set, requestedTime is the desired arrival time;
170-
// compute the actual start time by subtracting the total duration.
171-
startAt := requestedTime
172-
if arriveBy {
173-
startAt = requestedTime.Add(-time.Duration(res.Trip.Summary.Time) * time.Second)
174-
}
175-
176149
// Create legs for itinerary
177-
prevLegDepartAt := startAt
150+
prevLegDepartAt := departAt
178151
for _, vleg := range res.Trip.Legs {
179152
// Decode shape using custom 1e6 scale
180153
shapeDecoder := polyline.Codec{
@@ -255,8 +228,8 @@ func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *mode
255228
// Add summary
256229
itin.Duration = makeDuration(res.Trip.Summary.Time)
257230
itin.Distance = makeDistance(res.Trip.Summary.Length, res.Units)
258-
itin.StartTime = startAt
259-
itin.EndTime = startAt.Add(time.Duration(res.Trip.Summary.Time) * time.Second)
231+
itin.StartTime = departAt
232+
itin.EndTime = departAt.Add(time.Duration(res.Trip.Summary.Time) * time.Second)
260233
itin.From = itin.Legs[0].From
261234
itin.To = itin.Legs[0].To
262235
ret.Duration = itin.Duration
@@ -269,13 +242,6 @@ func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *mode
269242
type Request struct {
270243
Locations []RequestLocation `json:"locations"`
271244
Costing string `json:"costing"`
272-
DateTime *DateTime `json:"date_time,omitempty"`
273-
}
274-
275-
type DateTime struct {
276-
// Type: 0 = current depart, 1 = depart_at, 2 = arrive_by
277-
Type int `json:"type"`
278-
Value string `json:"value"`
279245
}
280246

281247
type RequestLocation struct {

0 commit comments

Comments
 (0)