From d02936c04f03e6cec579ea8cca1fb600305ca850 Mon Sep 17 00:00:00 2001 From: "Xun(Perry) Liu" Date: Fri, 8 May 2020 11:10:57 -0700 Subject: [PATCH] Add duration record for station connectivity graph (#331) * feat: implement station connectivity graph based on pre-build data issue: https://github.com/Telenav/osrm-backend/issues/242 --- CHANGELOG-FORK.md | 3 +- .../service/oasis/connectivitymap/builder.go | 28 ++-- .../oasis/connectivitymap/builder_test.go | 94 +++++++----- .../oasis/connectivitymap/connectivity_map.go | 18 ++- .../connectivitymap/connectivity_map_mock.go | 136 ++++++++++++------ .../oasis/connectivitymap/statistic.go | 41 ++++-- .../oasis/connectivitymap/statistic_test.go | 3 + .../service/oasis/spatialindexer/interface.go | 1 + .../spatialindexer/ranker/osrm_ranker_test.go | 6 + .../rank_by_great_circle_distance_impl.go | 11 +- .../ranker/rank_by_osrm_shortest_path_impl.go | 7 +- .../rank_by_osrm_shortest_path_impl_test.go | 40 +++--- .../ranker/simple_ranker_test.go | 15 +- .../station_conn_querier.go | 8 +- .../station_conn_querier_test.go | 14 +- 15 files changed, 283 insertions(+), 142 deletions(-) diff --git a/CHANGELOG-FORK.md b/CHANGELOG-FORK.md index 7c736cd6da2..9d4db6b5236 100644 --- a/CHANGELOG-FORK.md +++ b/CHANGELOG-FORK.md @@ -17,10 +17,11 @@ Changes from v10.2.0 - ADDED versioning on golang binaries [#320](https://github.com/Telenav/osrm-backend/pull/320) - ADDED package `util/appversion` to share versioning among many golang binaries [#328](https://github.com/Telenav/osrm-backend/pull/328) - ADDED package `stationconnquerier` which builds station connectivity graph based on pre-build data [#323](https://github.com/Telenav/osrm-backend/pull/323) + - ADDED `Duration` for pre-generated charge station connectivity data [#326](https://github.com/Telenav/osrm-backend/issues/326) - CHANGED for internal refactoring, use `osrm.xxx` to invoke OSRM APIs, e.g. `osrm.Coordinate` instead of `coordinate.Coordinate` [#327](https://github.com/Telenav/osrm-backend/pull/327) - CHANGED for epsilon of util/floatequals, use different epsilon for float32 compare and float64 compare [#332](https://github.com/Telenav/osrm-backend/issues/332) - - ADDED interface test for `trafficapplyingmodel` implementation(both `appendspeedonly` and `preferlivetraffic`) [#330](https://github.com/Telenav/osrm-backend/pull/330) + - Bugfix: - CHANGED `osrm-ranking` parsing of OSRM route response to compatible with `string` array `annotation/nodes` [#296](https://github.com/Telenav/osrm-backend/pull/296) - FIXED wrong variable `docker-entrypoint.sh` [#311](https://github.com/Telenav/osrm-backend/pull/311) diff --git a/integration/service/oasis/connectivitymap/builder.go b/integration/service/oasis/connectivitymap/builder.go index 2d494b0c9d5..867a01add49 100644 --- a/integration/service/oasis/connectivitymap/builder.go +++ b/integration/service/oasis/connectivitymap/builder.go @@ -49,7 +49,9 @@ func newConnectivityMapBuilder(iterator spatialindexer.PointsIterator, finder sp Input Iterator(channel) ---> worker (fetch task -> find -> rank) ---> aggregatorChannel -> feed to map \ / \ / - -> worker (fetch task -> find -> rank) + -> worker (fetch task -> find -> rank) + + . . .(more workers) */ func (builder *connectivityMapBuilder) build() ID2NearByIDsMap { @@ -80,11 +82,14 @@ func (builder *connectivityMapBuilder) work(workerID int, source <-chan spatiali nearbyIDs := builder.finder.FindNearByPointIDs(p.Location, builder.distanceLimit, spatialindexer.UnlimitedCount) rankedResults := builder.ranker.RankPointIDsByShortestDistance(p.Location, nearbyIDs) - ids := make([]IDAndDistance, 0, len(rankedResults)) + ids := make([]IDAndWeight, 0, len(rankedResults)) for _, r := range rankedResults { - ids = append(ids, IDAndDistance{ - ID: r.ID, - Distance: r.Distance, + ids = append(ids, IDAndWeight{ + ID: r.ID, + Weight: Weight{ + Distance: r.Distance, + Duration: r.Duration, + }, }) } @@ -120,7 +125,7 @@ func (builder *connectivityMapBuilder) wait() { type placeIDWithNearByPlaceIDs struct { id spatialindexer.PointID - ids []IDAndDistance + ids []IDAndWeight } func (builder *connectivityMapBuilder) buildInSerial() ID2NearByIDsMap { @@ -133,11 +138,14 @@ func (builder *connectivityMapBuilder) buildInSerial() ID2NearByIDsMap { nearbyIDs := builder.finder.FindNearByPointIDs(p.Location, builder.distanceLimit, spatialindexer.UnlimitedCount) rankedResults := builder.ranker.RankPointIDsByGreatCircleDistance(p.Location, nearbyIDs) - ids := make([]IDAndDistance, 0, len(rankedResults)) + ids := make([]IDAndWeight, 0, len(rankedResults)) for _, r := range rankedResults { - ids = append(ids, IDAndDistance{ - ID: r.ID, - Distance: r.Distance, + ids = append(ids, IDAndWeight{ + ID: r.ID, + Weight: Weight{ + Distance: r.Distance, + Duration: r.Duration, + }, }) } internalResult <- placeIDWithNearByPlaceIDs{ diff --git a/integration/service/oasis/connectivitymap/builder_test.go b/integration/service/oasis/connectivitymap/builder_test.go index cf490a8f859..0a1bfd0f255 100644 --- a/integration/service/oasis/connectivitymap/builder_test.go +++ b/integration/service/oasis/connectivitymap/builder_test.go @@ -31,52 +31,82 @@ func TestBuilderWithMockIteratorAndFinder(t *testing.T) { // construct expect map expect := make(ID2NearByIDsMap) - var idAndDistanceArray = []IDAndDistance{ - IDAndDistance{ - ID: 3, - Distance: 345.220003472554, + var idAndWeightArray = []IDAndWeight{ + { + 3, + Weight{ + 345.220003472554, + 15.550450606871804, + }, }, - IDAndDistance{ - ID: 2, - Distance: 402.8536530341791, + { + 2, + Weight{ + 402.8536530341791, + 18.146560947485547, + }, }, - IDAndDistance{ - ID: 4, - Distance: 1627.1858848458571, + { + 4, + Weight{ + 1627.1858848458571, + 73.29666147954312, + }, }, - IDAndDistance{ - ID: 5, - Distance: 4615.586636153461, + { + 5, + Weight{ + 4615.586636153461, + 207.9093079348406, + }, }, - IDAndDistance{ - ID: 1, - Distance: 5257.70008125706, + { + 1, + Weight{ + 5257.70008125706, + 236.8333369935613, + }, }, - IDAndDistance{ - ID: 6, - Distance: 6888.7486674247, + { + 6, + Weight{ + 6888.7486674247, + 310.30399402813964, + }, }, - IDAndDistance{ - ID: 7, - Distance: 7041.893747628621, + { + 7, + Weight{ + 7041.893747628621, + 317.2024210643523, + }, }, - IDAndDistance{ - ID: 10, - Distance: 8622.213424347745, + { + 10, + Weight{ + 8622.213424347745, + 388.3879920877363, + }, }, - IDAndDistance{ - ID: 9, - Distance: 9438.804320070916, + { + 9, + Weight{ + 9438.804320070916, + 425.1713657689602, + }, }, - IDAndDistance{ - ID: 8, - Distance: 9897.44482638937, + { + 8, + Weight{ + 9897.44482638937, + 445.8308480355572, + }, }, } for i := 0; i < 100; i++ { index := i + 1000 - expect[(spatialindexer.PointID(index))] = idAndDistanceArray + expect[(spatialindexer.PointID(index))] = idAndWeightArray } if !reflect.DeepEqual(actual, expect) { diff --git a/integration/service/oasis/connectivitymap/connectivity_map.go b/integration/service/oasis/connectivitymap/connectivity_map.go index 6c10257ed12..9c547cf38b0 100644 --- a/integration/service/oasis/connectivitymap/connectivity_map.go +++ b/integration/service/oasis/connectivitymap/connectivity_map.go @@ -5,14 +5,20 @@ import ( "github.com/golang/glog" ) -// IDAndDistance wraps ID and distance information -type IDAndDistance struct { - ID spatialindexer.PointID +// Weight represent weight information +type Weight struct { Distance float64 + Duration float64 +} + +// IDAndWeight wraps ID and weight information +type IDAndWeight struct { + ID spatialindexer.PointID + Weight Weight } // ID2NearByIDsMap is a mapping between ID and its nearby IDs -type ID2NearByIDsMap map[spatialindexer.PointID][]IDAndDistance +type ID2NearByIDsMap map[spatialindexer.PointID][]IDAndWeight // Connectivity Map used to query connectivity for given placeID type ConnectivityMap struct { @@ -69,8 +75,8 @@ func (cm *ConnectivityMap) Load(folderPath string) *ConnectivityMap { } // QueryConnectivity answers connectivity query for given placeID -// Return true and IDAndDistance array for given placeID, otherwise false and nil -func (cm *ConnectivityMap) QueryConnectivity(placeID spatialindexer.PointID) ([]IDAndDistance, bool) { +// Return true and IDAndWeight array for given placeID, otherwise false and nil +func (cm *ConnectivityMap) QueryConnectivity(placeID spatialindexer.PointID) ([]IDAndWeight, bool) { if result, ok := cm.id2nearByIDs[placeID]; ok { return result, true } diff --git a/integration/service/oasis/connectivitymap/connectivity_map_mock.go b/integration/service/oasis/connectivitymap/connectivity_map_mock.go index 5d01ada8092..7a2f60dc138 100644 --- a/integration/service/oasis/connectivitymap/connectivity_map_mock.go +++ b/integration/service/oasis/connectivitymap/connectivity_map_mock.go @@ -1,81 +1,123 @@ package connectivitymap var fakeID2NearByIDsMap1 = ID2NearByIDsMap{ - 1: []IDAndDistance{ - IDAndDistance{ - ID: 2, - Distance: 3, + 1: []IDAndWeight{ + { + ID: 2, + Weight: Weight{ + Distance: 3, + Duration: 3, + }, }, - IDAndDistance{ - ID: 5, - Distance: 4, + { + ID: 5, + Weight: Weight{ + Distance: 4, + Duration: 4, + }, }, - IDAndDistance{ - ID: 7, - Distance: 6, + { + ID: 7, + Weight: Weight{ + Distance: 6, + Duration: 61, + }, }, - IDAndDistance{ - ID: 8, - Distance: 12, + { + ID: 8, + Weight: Weight{ + Distance: 12, + Duration: 12, + }, }, }, - 2: []IDAndDistance{ - IDAndDistance{ - ID: 1, - Distance: 3, + 2: []IDAndWeight{ + { + ID: 1, + Weight: Weight{ + Distance: 3, + Duration: 3, + }, }, - IDAndDistance{ - ID: 7, - Distance: 23, + { + ID: 7, + Weight: Weight{ + Distance: 23, + Duration: 23, + }, }, }, - 5: []IDAndDistance{ - IDAndDistance{ - ID: 1, - Distance: 4, + 5: []IDAndWeight{ + { + ID: 1, + Weight: Weight{ + Distance: 4, + Duration: 4, + }, }, - IDAndDistance{ - ID: 8, - Distance: 5, + { + ID: 8, + Weight: Weight{ + Distance: 5, + Duration: 5, + }, }, }, - 7: []IDAndDistance{ - IDAndDistance{ - ID: 1, - Distance: 6, + 7: []IDAndWeight{ + { + ID: 1, + Weight: Weight{ + Distance: 6, + Duration: 6, + }, }, - IDAndDistance{ - ID: 2, - Distance: 23, + { + ID: 2, + Weight: Weight{ + Distance: 23, + Duration: 23, + }, }, }, - 8: []IDAndDistance{ - IDAndDistance{ - ID: 5, - Distance: 5, + 8: []IDAndWeight{ + { + ID: 5, + Weight: Weight{ + Distance: 5, + Duration: 5, + }, }, - IDAndDistance{ - ID: 1, - Distance: 12, + { + ID: 1, + Weight: Weight{ + Distance: 12, + Duration: 12, + }, }, }, } var fakeID2NearByIDsMap2 = ID2NearByIDsMap{ - 1: []IDAndDistance{ + 1: []IDAndWeight{ { - ID: 2, - Distance: 1, + ID: 2, + Weight: Weight{ + Distance: 1, + Duration: 1, + }, }, }, - 2: []IDAndDistance{ + 2: []IDAndWeight{ { - ID: 3, - Distance: 2, + ID: 3, + Weight: Weight{ + Distance: 2, + Duration: 2, + }, }, }, } diff --git a/integration/service/oasis/connectivitymap/statistic.go b/integration/service/oasis/connectivitymap/statistic.go index ddcf528f976..897a2c37bde 100644 --- a/integration/service/oasis/connectivitymap/statistic.go +++ b/integration/service/oasis/connectivitymap/statistic.go @@ -21,6 +21,9 @@ type statistic struct { AverageMaxDistance float64 `json:"average_value_max_distance"` MaxOfMaxDistance float64 `json:"max_value_max_distance"` MinOfMaxDistance float64 `json:"min_value_max_distance"` + AverageMaxDuration float64 `json:"average_value_max_duration"` + MaxOfMaxDuration float64 `json:"max_value_max_duration"` + MinOfMaxDuration float64 `json:"min_value_max_duration"` MaxRange float64 `json:"maxrange_set_by_preprocessing"` } @@ -34,6 +37,9 @@ func newStatistic() *statistic { AverageMaxDistance: 0.0, MaxOfMaxDistance: 0.0, MinOfMaxDistance: math.MaxFloat64, + AverageMaxDuration: 0.0, + MaxOfMaxDuration: 0.0, + MinOfMaxDuration: math.MaxFloat64, MaxRange: 0.0, } } @@ -47,6 +53,9 @@ func (s *statistic) init() { s.AverageMaxDistance = 0.0 s.MaxOfMaxDistance = 0.0 s.MinOfMaxDistance = math.MaxFloat64 + s.AverageMaxDuration = 0.0 + s.MaxOfMaxDuration = 0.0 + s.MinOfMaxDuration = math.MaxFloat64 s.MaxRange = 0.0 } @@ -56,27 +65,33 @@ func (s *statistic) build(m ID2NearByIDsMap, MaxRange float64) *statistic { totalNearByIDsCount := 0 totalMaxDistance := 0.0 - for _, idAndDistanceArray := range m { + totalMaxDuration := 0.0 + for _, idAndWeightArray := range m { s.Count += 1 - if len(idAndDistanceArray) == 0 { + if len(idAndWeightArray) == 0 { continue } s.ValidCount += 1 prevTotalNearByIDsCount := totalNearByIDsCount - totalNearByIDsCount += len(idAndDistanceArray) + totalNearByIDsCount += len(idAndWeightArray) if prevTotalNearByIDsCount > totalNearByIDsCount { glog.Fatalf("Overflow during accumulate totalNearByIDsCount, before accumulate value = %v, after add %v new value is %v\n", - prevTotalNearByIDsCount, len(idAndDistanceArray), totalNearByIDsCount) + prevTotalNearByIDsCount, len(idAndWeightArray), totalNearByIDsCount) } - s.MaxNearByIDsCount = max(s.MaxNearByIDsCount, len(idAndDistanceArray)) - s.MinNearByIDsCount = min(s.MinNearByIDsCount, len(idAndDistanceArray)) + s.MaxNearByIDsCount = max(s.MaxNearByIDsCount, len(idAndWeightArray)) + s.MinNearByIDsCount = min(s.MinNearByIDsCount, len(idAndWeightArray)) prevTotalMaxDistance := totalMaxDistance + prevTotalMaxDuration := totalMaxDuration maxDistance := 0.0 - for _, item := range idAndDistanceArray { - maxDistance = math.Max(maxDistance, item.Distance) + for _, item := range idAndWeightArray { + maxDistance = math.Max(maxDistance, item.Weight.Distance) + } + maxDuration := 0.0 + for _, item := range idAndWeightArray { + maxDuration = math.Max(maxDuration, item.Weight.Duration) } totalMaxDistance += maxDistance @@ -84,8 +99,17 @@ func (s *statistic) build(m ID2NearByIDsMap, MaxRange float64) *statistic { glog.Fatalf("Overflow during accumulate totalMaxDistance, before accumulate value = %#v, after add %v new value is %#v\n", prevTotalMaxDistance, maxDistance, totalMaxDistance) } + totalMaxDuration += maxDuration + if prevTotalMaxDuration > totalMaxDuration { + glog.Fatalf("Overflow during accumulate totalMaxDuration, before accumulate value = %#v, after add %v new value is %#v\n", + prevTotalMaxDuration, maxDuration, totalMaxDuration) + } + s.MaxOfMaxDistance = math.Max(s.MaxOfMaxDistance, maxDistance) s.MinOfMaxDistance = math.Min(s.MinOfMaxDistance, maxDistance) + + s.MaxOfMaxDuration = math.Max(s.MaxOfMaxDuration, maxDuration) + s.MinOfMaxDuration = math.Min(s.MinOfMaxDuration, maxDuration) } if s.ValidCount == 0 { @@ -95,6 +119,7 @@ func (s *statistic) build(m ID2NearByIDsMap, MaxRange float64) *statistic { s.AverageNearByIDsCount = totalNearByIDsCount / s.ValidCount s.AverageMaxDistance = totalMaxDistance / (float64)(s.ValidCount) + s.AverageMaxDuration = totalMaxDuration / (float64)(s.ValidCount) glog.Infof("Build statistic for ID2NearByIDsMap finished. %+v\n", s) return s diff --git a/integration/service/oasis/connectivitymap/statistic_test.go b/integration/service/oasis/connectivitymap/statistic_test.go index e7cd23c1f4f..964b6794484 100644 --- a/integration/service/oasis/connectivitymap/statistic_test.go +++ b/integration/service/oasis/connectivitymap/statistic_test.go @@ -15,6 +15,9 @@ var fakeStatisticResult1 = statistic{ AverageMaxDistance: 15, MaxOfMaxDistance: 23, MinOfMaxDistance: 5, + AverageMaxDuration: 24.8, + MaxOfMaxDuration: 61, + MinOfMaxDuration: 5, MaxRange: 123, } diff --git a/integration/service/oasis/spatialindexer/interface.go b/integration/service/oasis/spatialindexer/interface.go index d587762a3d5..d6eb7bc158b 100644 --- a/integration/service/oasis/spatialindexer/interface.go +++ b/integration/service/oasis/spatialindexer/interface.go @@ -24,6 +24,7 @@ type PointInfo struct { type RankedPointInfo struct { PointInfo Distance float64 + Duration float64 } // PointID defines ID for given point(location, point of interest) diff --git a/integration/service/oasis/spatialindexer/ranker/osrm_ranker_test.go b/integration/service/oasis/spatialindexer/ranker/osrm_ranker_test.go index 4a6a442a40e..43b105f72d7 100644 --- a/integration/service/oasis/spatialindexer/ranker/osrm_ranker_test.go +++ b/integration/service/oasis/spatialindexer/ranker/osrm_ranker_test.go @@ -79,6 +79,7 @@ func TestRankerInterfaceViaOSRMRanker(t *testing.T) { }, }, Distance: 1.1, + Duration: 1.1, }, &spatialindexer.RankedPointInfo{ PointInfo: spatialindexer.PointInfo{ @@ -89,6 +90,7 @@ func TestRankerInterfaceViaOSRMRanker(t *testing.T) { }, }, Distance: 2.2, + Duration: 2.2, }, &spatialindexer.RankedPointInfo{ PointInfo: spatialindexer.PointInfo{ @@ -99,6 +101,7 @@ func TestRankerInterfaceViaOSRMRanker(t *testing.T) { }, }, Distance: 3.3, + Duration: 3.3, }, &spatialindexer.RankedPointInfo{ PointInfo: spatialindexer.PointInfo{ @@ -109,6 +112,7 @@ func TestRankerInterfaceViaOSRMRanker(t *testing.T) { }, }, Distance: 4.4, + Duration: 4.4, }, &spatialindexer.RankedPointInfo{ PointInfo: spatialindexer.PointInfo{ @@ -119,6 +123,7 @@ func TestRankerInterfaceViaOSRMRanker(t *testing.T) { }, }, Distance: 5.5, + Duration: 5.5, }, &spatialindexer.RankedPointInfo{ PointInfo: spatialindexer.PointInfo{ @@ -129,6 +134,7 @@ func TestRankerInterfaceViaOSRMRanker(t *testing.T) { }, }, Distance: 6.6, + Duration: 6.6, }, }, }, diff --git a/integration/service/oasis/spatialindexer/ranker/rank_by_great_circle_distance_impl.go b/integration/service/oasis/spatialindexer/ranker/rank_by_great_circle_distance_impl.go index f41316e6edd..6593fb34a62 100644 --- a/integration/service/oasis/spatialindexer/ranker/rank_by_great_circle_distance_impl.go +++ b/integration/service/oasis/spatialindexer/ranker/rank_by_great_circle_distance_impl.go @@ -6,6 +6,10 @@ import ( "github.com/golang/glog" ) +// defaultSpeed is 22.2 meter/second +// 22.2 m/s = 50 miles/hour +const defaultSpeed = 22.2 + func rankPointsByGreatCircleDistanceToCenter(center spatialindexer.Location, targets []*spatialindexer.PointInfo) []*spatialindexer.RankedPointInfo { if len(targets) == 0 { glog.Warningf("When try to rankPointsByGreatCircleDistanceToCenter, input array is empty, center = %+v\n", center) @@ -17,13 +21,16 @@ func rankPointsByGreatCircleDistanceToCenter(center spatialindexer.Location, tar defer close(pointWithDistanceC) for _, p := range targets { + // geo.Haversin's unit is kilometer, convert to meter + length := geo.Haversin(center.Lon, center.Lat, p.Location.Lon, p.Location.Lat) * 1000 + pointWithDistanceC <- &spatialindexer.RankedPointInfo{ PointInfo: spatialindexer.PointInfo{ ID: p.ID, Location: p.Location, }, - // geo.Haversin's unit is kilometer, convert to meter - Distance: geo.Haversin(center.Lon, center.Lat, p.Location.Lon, p.Location.Lat) * 1000, + Distance: length, + Duration: length / defaultSpeed, } } }() diff --git a/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl.go b/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl.go index 81eda41c55f..ee39b4808d6 100644 --- a/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl.go +++ b/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl.go @@ -84,7 +84,11 @@ func calcCenter2TargetsDistanceViaShortestPath(center spatialindexer.Location, t } if len(resp.Resp.Distances[0]) != endIndex-startIndex+1 { - err := fmt.Errorf("incorrect table response for request %+v, expect %d items but returns %d", req.RequestURI(), endIndex-startIndex+1, len(resp.Resp.Distances[0])) + err := fmt.Errorf("incorrect table response for request %+v, expect %d items of distance but returns %d", req.RequestURI(), endIndex-startIndex+1, len(resp.Resp.Distances[0])) + return nil, err + } + if len(resp.Resp.Durations[0]) != endIndex-startIndex+1 { + err := fmt.Errorf("incorrect table response for request %+v, expect %d items of distance but returns %d", req.RequestURI(), endIndex-startIndex+1, len(resp.Resp.Durations[0])) return nil, err } @@ -99,6 +103,7 @@ func calcCenter2TargetsDistanceViaShortestPath(center spatialindexer.Location, t Location: targets[startIndex+i].Location, }, Distance: resp.Resp.Distances[0][i], + Duration: resp.Resp.Durations[0][i], }) } return result, nil diff --git a/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl_test.go b/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl_test.go index 26acac797fa..95888298049 100644 --- a/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl_test.go +++ b/integration/service/oasis/spatialindexer/ranker/rank_by_osrm_shortest_path_impl_test.go @@ -117,35 +117,35 @@ func TestGenerateTableRequest(t *testing.T) { Lon: 0, }, targets: []*spatialindexer.PointInfo{ - &spatialindexer.PointInfo{ + { ID: 1, Location: spatialindexer.Location{ Lat: 1.1, Lon: 1.1, }, }, - &spatialindexer.PointInfo{ + { ID: 2, Location: spatialindexer.Location{ Lat: 2.2, Lon: 2.2, }, }, - &spatialindexer.PointInfo{ + { ID: 3, Location: spatialindexer.Location{ Lat: 3.3, Lon: 3.3, }, }, - &spatialindexer.PointInfo{ + { ID: 4, Location: spatialindexer.Location{ Lat: 4.4, Lon: 4.4, }, }, - &spatialindexer.PointInfo{ + { ID: 5, Location: spatialindexer.Location{ Lat: 5.5, @@ -218,42 +218,42 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { Lon: 0, }, targets: []*spatialindexer.PointInfo{ - &spatialindexer.PointInfo{ + { ID: 1, Location: spatialindexer.Location{ Lat: 1.1, Lon: 1.1, }, }, - &spatialindexer.PointInfo{ + { ID: 2, Location: spatialindexer.Location{ Lat: 2.2, Lon: 2.2, }, }, - &spatialindexer.PointInfo{ + { ID: 3, Location: spatialindexer.Location{ Lat: 3.3, Lon: 3.3, }, }, - &spatialindexer.PointInfo{ + { ID: 4, Location: spatialindexer.Location{ Lat: 4.4, Lon: 4.4, }, }, - &spatialindexer.PointInfo{ + { ID: 5, Location: spatialindexer.Location{ Lat: 5.5, Lon: 5.5, }, }, - &spatialindexer.PointInfo{ + { ID: 6, Location: spatialindexer.Location{ Lat: 6.6, @@ -262,7 +262,7 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, expect: []*spatialindexer.RankedPointInfo{ - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 1, Location: spatialindexer.Location{ @@ -271,8 +271,9 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, Distance: 1.1, + Duration: 1.1, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 2, Location: spatialindexer.Location{ @@ -281,8 +282,9 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, Distance: 2.2, + Duration: 2.2, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 3, Location: spatialindexer.Location{ @@ -291,8 +293,9 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, Distance: 3.3, + Duration: 3.3, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 4, Location: spatialindexer.Location{ @@ -301,8 +304,9 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, Distance: 4.4, + Duration: 4.4, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 5, Location: spatialindexer.Location{ @@ -311,8 +315,9 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, Distance: 5.5, + Duration: 5.5, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 6, Location: spatialindexer.Location{ @@ -321,6 +326,7 @@ func TestRankPointsByOSRMShortestPathWithDifferentPointThreshold(t *testing.T) { }, }, Distance: 6.6, + Duration: 6.6, }, }, }, diff --git a/integration/service/oasis/spatialindexer/ranker/simple_ranker_test.go b/integration/service/oasis/spatialindexer/ranker/simple_ranker_test.go index 02e951c6274..99b67437663 100644 --- a/integration/service/oasis/spatialindexer/ranker/simple_ranker_test.go +++ b/integration/service/oasis/spatialindexer/ranker/simple_ranker_test.go @@ -19,21 +19,21 @@ func TestRankerInterfaceViaSimpleRanker(t *testing.T) { Lon: -121.976633, }, targets: []*spatialindexer.PointInfo{ - &spatialindexer.PointInfo{ + { ID: 1, Location: spatialindexer.Location{ Lat: 37.388840, Lon: -121.981736, }, }, - &spatialindexer.PointInfo{ + { ID: 2, Location: spatialindexer.Location{ Lat: 37.375515, Lon: -121.942812, }, }, - &spatialindexer.PointInfo{ + { ID: 3, Location: spatialindexer.Location{ Lat: 37.336954, @@ -42,7 +42,7 @@ func TestRankerInterfaceViaSimpleRanker(t *testing.T) { }, }, expect: []*spatialindexer.RankedPointInfo{ - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 1, Location: spatialindexer.Location{ @@ -51,8 +51,9 @@ func TestRankerInterfaceViaSimpleRanker(t *testing.T) { }, }, Distance: 1213.445757354474, + Duration: 54.65971879975108, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 2, Location: spatialindexer.Location{ @@ -61,8 +62,9 @@ func TestRankerInterfaceViaSimpleRanker(t *testing.T) { }, }, Distance: 3965.986474110687, + Duration: 178.64803937435528, }, - &spatialindexer.RankedPointInfo{ + { PointInfo: spatialindexer.PointInfo{ ID: 3, Location: spatialindexer.Location{ @@ -71,6 +73,7 @@ func TestRankerInterfaceViaSimpleRanker(t *testing.T) { }, }, Distance: 12281.070927352637, + Duration: 553.2013931239927, }, }, }, diff --git a/integration/service/oasis/stationconnquerier/station_conn_querier.go b/integration/service/oasis/stationconnquerier/station_conn_querier.go index 377d5e0be8c..1b64909ff68 100644 --- a/integration/service/oasis/stationconnquerier/station_conn_querier.go +++ b/integration/service/oasis/stationconnquerier/station_conn_querier.go @@ -72,8 +72,7 @@ func (querier *StationConnectivityQuerier) connectEndIntoStationGraph(stationFin StationID: stationfindertype.DestLocationID, StationLocation: end, Distance: rankedPointInfo.Distance, - //TODO codebear801 https://github.com/Telenav/osrm-backend/issues/321 - Duration: rankedPointInfo.Distance, + Duration: rankedPointInfo.Duration, } } @@ -112,9 +111,8 @@ func (querier *StationConnectivityQuerier) NearByStationQuery(stationID string) tmp := &connectivitymap.QueryResult{ StationID: idAndWeight.ID.String(), StationLocation: querier.GetLocation(idAndWeight.ID.String()), - Distance: idAndWeight.Distance, - //TODO codebear801 https://github.com/Telenav/osrm-backend/issues/321 - Duration: idAndWeight.Distance, + Distance: idAndWeight.Weight.Distance, + Duration: idAndWeight.Weight.Duration, } results = append(results, tmp) } diff --git a/integration/service/oasis/stationconnquerier/station_conn_querier_test.go b/integration/service/oasis/stationconnquerier/station_conn_querier_test.go index 64b7e580a8c..aa08e751834 100644 --- a/integration/service/oasis/stationconnquerier/station_conn_querier_test.go +++ b/integration/service/oasis/stationconnquerier/station_conn_querier_test.go @@ -117,14 +117,14 @@ func TestStationConnQuerier(t *testing.T) { { StationID: "2", StationLocation: mockStation2Location, - Distance: 1, - Duration: 1, + Distance: 1, // hard code value from mock ConnectivityMap + Duration: 1, // hard code value from mock ConnectivityMap }, { StationID: stationfindertype.DestLocationID, StationLocation: mockDestLocation, Distance: 4873.817197753869, - Duration: 4873.817197753869, + Duration: 219.54131521413822, }, }, }, @@ -134,14 +134,14 @@ func TestStationConnQuerier(t *testing.T) { { StationID: "3", StationLocation: mockStation3Location, - Distance: 2, - Duration: 2, + Distance: 2, // hard code value from mock ConnectivityMap + Duration: 2, // hard code value from mock ConnectivityMap }, { StationID: stationfindertype.DestLocationID, StationLocation: mockDestLocation, Distance: 7277.313067724465, - Duration: 7277.313067724465, + Duration: 327.80689494254347, }, }, }, @@ -152,7 +152,7 @@ func TestStationConnQuerier(t *testing.T) { StationID: stationfindertype.DestLocationID, StationLocation: mockDestLocation, Distance: 7083.8672907090095, - Duration: 7083.8672907090095, + Duration: 319.0931212031085, }, }, },