Skip to content

Commit

Permalink
update oasis api (#136)
Browse files Browse the repository at this point in the history
* feat: Implement initial connector with telenav search
      Only support nearest charge station search for now.
issues: #132

* fix: update oasis api
     - Remove "Location field", add "Address" field which contains geo_coordinates + a list of nav_coordinates
     - Add field of detail_url, external user could retrieve all information related with specific charge station
     - Add field of estimate remaining range for each solution
issue: #132 (comment)
       #128

* fix: resolve conflict
issue: #128
  • Loading branch information
CodeBear801 authored and wangyoucao577 committed Jan 22, 2020
1 parent 1fce7e5 commit e6350eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
21 changes: 16 additions & 5 deletions integration/oasis/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/Telenav/osrm-backend/integration/pkg/api/oasis"
"github.com/Telenav/osrm-backend/integration/pkg/api/search/nearbychargestation"
)

type Handler struct {
Expand All @@ -23,31 +24,41 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}

func generateFakeOasisResponse() *oasis.Response {
// Fake solution 1
fakeSolution1 := new(oasis.Solution)
fakeSolution1.Distance = 90.0
fakeSolution1.Duration = 300.0
fakeSolution1.Weight = 300.0
fakeSolution1.RemainingRage = 100000.0
fakeSolution1.WeightName = "duration"

// Information realted with first charge station
fakeStation1 := new(oasis.ChargeStation)
fakeStation1.Location[0] = 13.39677
fakeStation1.Location[1] = 52.54366
address1 := new(nearbychargestation.Address)
address1.GeoCoordinate = nearbychargestation.Coordinate{Latitude: 37.78509, Longitude: -122.41988}
address1.NavCoordinates = append(address1.NavCoordinates, &nearbychargestation.Coordinate{Latitude: 37.78509, Longitude: -122.41988})
fakeStation1.Address = append(fakeStation1.Address, address1)
fakeStation1.WaitTime = 30.0
fakeStation1.ChargeTime = 100.0
fakeStation1.ChargeRange = 100.0
fakeStation1.DetailURL = "url"
fakeSolution1.ChargeStations = append(fakeSolution1.ChargeStations, fakeStation1)

// Information realted with second charge station
fakeStation2 := new(oasis.ChargeStation)
fakeStation2.Location[0] = 13.40677
fakeStation2.Location[1] = 52.53333
address2 := new(nearbychargestation.Address)
address2.GeoCoordinate = nearbychargestation.Coordinate{Latitude: 13.40677, Longitude: 52.53333}
address2.NavCoordinates = append(address2.NavCoordinates, &nearbychargestation.Coordinate{Latitude: 13.40677, Longitude: 52.53333})
fakeStation2.Address = append(fakeStation2.Address, address2)
fakeStation2.WaitTime = 100.0
fakeStation2.ChargeTime = 100.0
fakeStation2.ChargeRange = 100.0
fakeStation2.DetailURL = "url"
fakeSolution1.ChargeStations = append(fakeSolution1.ChargeStations, fakeStation2)

r := new(oasis.Response)
r.Code = "200"
r.Message = "Optimized charge station selection result:"
r.Message = "Success"
r.Solutions = append(r.Solutions, fakeSolution1)

return r
Expand Down
12 changes: 7 additions & 5 deletions integration/pkg/api/oasis/response.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package oasis

import "github.com/Telenav/osrm-backend/integration/pkg/api/osrm/route"
import "github.com/Telenav/osrm-backend/integration/pkg/api/search/nearbychargestation"

// Response for oasis service
type Response struct {
Expand All @@ -13,15 +13,17 @@ type Response struct {
type Solution struct {
Distance float64 `json:"distance"`
Duration float64 `json:"duration"`
RemainingRage float64 `json:"estimate_remaining_range"`
Weight float64 `json:"weight"`
WeightName string `json:"weight_name"`
ChargeStations []*ChargeStation `json:"charge_stations"`
}

// ChargeStation contains location, time and energy level, could be used as waypoints for routing request
type ChargeStation struct {
route.Waypoint
WaitTime float64 `json:"wait_time"`
ChargeTime float64 `json:"charge_time"`
ChargeRange float64 `json:"charge_range"`
Address []*nearbychargestation.Address `json:"address"`
WaitTime float64 `json:"wait_time"`
ChargeTime float64 `json:"charge_time"`
ChargeRange float64 `json:"charge_range"`
DetailURL string `json:"detail_url"`
}

0 comments on commit e6350eb

Please sign in to comment.