From c3a04f862619a2f8cf2660bc6c692c2d66c19ecf Mon Sep 17 00:00:00 2001 From: codebear801 Date: Thu, 14 May 2020 10:39:11 -0700 Subject: [PATCH] refactor: move solution, osrmhelper and searchhelper into oasis/internal issue: https://github.com/Telenav/osrm-backend/issues/342 --- integration/service/oasis/handler.go | 2 +- .../service/oasis/haversine/distance.go | 29 ------------------- .../service/oasis/haversine/distance_test.go | 16 ---------- .../oasis/{ => internal}/osrmhelper/helper.go | 0 .../{ => internal}/searchhelper/helper.go | 0 .../oasis/{ => internal}/solution/doc.go | 0 .../oasis/{ => internal}/solution/solution.go | 0 .../reachable_by_multiple_charge.go | 5 ++-- .../reachable_by_single_charge.go | 2 +- .../cloudfinder/dest_station_finder.go | 2 +- .../low_energy_location_station_finder.go | 2 +- .../cloudfinder/orig_station_finder.go | 2 +- .../stationfinderalg/stations_iterator_alg.go | 2 +- .../oasis/stationgraph/station_graph.go | 2 +- .../oasis/stationgraph/station_graph_test.go | 2 +- 15 files changed, 11 insertions(+), 55 deletions(-) delete mode 100644 integration/service/oasis/haversine/distance.go delete mode 100644 integration/service/oasis/haversine/distance_test.go rename integration/service/oasis/{ => internal}/osrmhelper/helper.go (100%) rename integration/service/oasis/{ => internal}/searchhelper/helper.go (100%) rename integration/service/oasis/{ => internal}/solution/doc.go (100%) rename integration/service/oasis/{ => internal}/solution/solution.go (100%) diff --git a/integration/service/oasis/handler.go b/integration/service/oasis/handler.go index 062a4de6632..a17e8d9ef92 100644 --- a/integration/service/oasis/handler.go +++ b/integration/service/oasis/handler.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/Telenav/osrm-backend/integration/api/oasis" - "github.com/Telenav/osrm-backend/integration/service/oasis/osrmhelper" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/osrmhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/selectionstrategy" "github.com/golang/glog" ) diff --git a/integration/service/oasis/haversine/distance.go b/integration/service/oasis/haversine/distance.go deleted file mode 100644 index 382e92400ad..00000000000 --- a/integration/service/oasis/haversine/distance.go +++ /dev/null @@ -1,29 +0,0 @@ -package haversine - -import ( - "math" -) - -const ( - // According to Wikipedia, the Earth's radius is about 6,371km - EARTH_RADIUS = 6371000 -) - -// GreatCircleDistance: Calculates the Haversine distance between two points in meters. -// Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html -func GreatCircleDistance(lat1, lon1, lat2, lon2 float64) float64 { - dLat := (lat2 - lat1) * (math.Pi / 180.0) - dLon := (lon2 - lon1) * (math.Pi / 180.0) - - lat1 = lat1 * (math.Pi / 180.0) - lat2 = lat2 * (math.Pi / 180.0) - - a1 := math.Sin(dLat/2) * math.Sin(dLat/2) - a2 := math.Sin(dLon/2) * math.Sin(dLon/2) * math.Cos(lat1) * math.Cos(lat2) - - a := a1 + a2 - - c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a)) - - return EARTH_RADIUS * c -} diff --git a/integration/service/oasis/haversine/distance_test.go b/integration/service/oasis/haversine/distance_test.go deleted file mode 100644 index ee146189d27..00000000000 --- a/integration/service/oasis/haversine/distance_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package haversine - -import ( - "testing" - - "github.com/Telenav/osrm-backend/integration/util" -) - -func TestGreatCircleDistance(t *testing.T) { - // expect value got from http://www.onlineconversion.com/map_greatcircle_distance.htm - expect := 111595.4865288326 - actual := GreatCircleDistance(32.333, 122.323, 31.333, 122.423) - if !util.Float64Equal(expect, actual) { - t.Errorf("Expected GreatCircleDistance returns %v, got %v", expect, actual) - } -} diff --git a/integration/service/oasis/osrmhelper/helper.go b/integration/service/oasis/internal/osrmhelper/helper.go similarity index 100% rename from integration/service/oasis/osrmhelper/helper.go rename to integration/service/oasis/internal/osrmhelper/helper.go diff --git a/integration/service/oasis/searchhelper/helper.go b/integration/service/oasis/internal/searchhelper/helper.go similarity index 100% rename from integration/service/oasis/searchhelper/helper.go rename to integration/service/oasis/internal/searchhelper/helper.go diff --git a/integration/service/oasis/solution/doc.go b/integration/service/oasis/internal/solution/doc.go similarity index 100% rename from integration/service/oasis/solution/doc.go rename to integration/service/oasis/internal/solution/doc.go diff --git a/integration/service/oasis/solution/solution.go b/integration/service/oasis/internal/solution/solution.go similarity index 100% rename from integration/service/oasis/solution/solution.go rename to integration/service/oasis/internal/solution/solution.go diff --git a/integration/service/oasis/selectionstrategy/reachable_by_multiple_charge.go b/integration/service/oasis/selectionstrategy/reachable_by_multiple_charge.go index 12a84834def..227e8dbca95 100644 --- a/integration/service/oasis/selectionstrategy/reachable_by_multiple_charge.go +++ b/integration/service/oasis/selectionstrategy/reachable_by_multiple_charge.go @@ -8,13 +8,13 @@ import ( "github.com/Telenav/osrm-backend/integration/api/oasis" "github.com/Telenav/osrm-backend/integration/api/osrm/route" "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" - "github.com/Telenav/osrm-backend/integration/service/oasis/haversine" "github.com/Telenav/osrm-backend/integration/service/oasis/osrmconnector" "github.com/Telenav/osrm-backend/integration/service/oasis/spatialindexer/ranker" "github.com/Telenav/osrm-backend/integration/service/oasis/stationconnquerier" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfinderalg" "github.com/Telenav/osrm-backend/integration/service/oasis/stationgraph" + "github.com/blevesearch/bleve/geo" "github.com/golang/glog" "github.com/twpayne/go-polyline" @@ -119,7 +119,8 @@ func findChargeLocation4Route(route *route.Route, result []*nav.Location, currEn tmp := 0.0 for i := 0; i < len(coords)-1; i++ { - tmp += haversine.GreatCircleDistance(coords[i][0], coords[i][1], coords[i+1][0], coords[i+1][1]) + // geo.Haversin's unit is kilometer, convert to meter + tmp += geo.Haversin(coords[i][1], coords[i][0], coords[i+1][1], coords[i+1][0]) * 1000 if currEnergy-tmp < preferLevel { currEnergy = maxRange result = append(result, &nav.Location{ diff --git a/integration/service/oasis/selectionstrategy/reachable_by_single_charge.go b/integration/service/oasis/selectionstrategy/reachable_by_single_charge.go index 3fa9ec08b74..41dfff0fe83 100644 --- a/integration/service/oasis/selectionstrategy/reachable_by_single_charge.go +++ b/integration/service/oasis/selectionstrategy/reachable_by_single_charge.go @@ -10,8 +10,8 @@ import ( "github.com/Telenav/osrm-backend/integration/api/osrm" "github.com/Telenav/osrm-backend/integration/api/osrm/table" "github.com/Telenav/osrm-backend/integration/api/search/nearbychargestation" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/osrmhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/osrmconnector" - "github.com/Telenav/osrm-backend/integration/service/oasis/osrmhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfinderalg" "github.com/golang/glog" ) diff --git a/integration/service/oasis/stationfinder/cloudfinder/dest_station_finder.go b/integration/service/oasis/stationfinder/cloudfinder/dest_station_finder.go index 52490e6ef8b..c79aff3ab25 100644 --- a/integration/service/oasis/stationfinder/cloudfinder/dest_station_finder.go +++ b/integration/service/oasis/stationfinder/cloudfinder/dest_station_finder.go @@ -3,8 +3,8 @@ package cloudfinder import ( "github.com/Telenav/osrm-backend/integration/api/oasis" "github.com/Telenav/osrm-backend/integration/api/search/searchcoordinate" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/searchhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/searchconnector" - "github.com/Telenav/osrm-backend/integration/service/oasis/searchhelper" ) //@todo: This number need to be adjusted based on charge station profile diff --git a/integration/service/oasis/stationfinder/cloudfinder/low_energy_location_station_finder.go b/integration/service/oasis/stationfinder/cloudfinder/low_energy_location_station_finder.go index c1ff88256cf..402ddb323fb 100644 --- a/integration/service/oasis/stationfinder/cloudfinder/low_energy_location_station_finder.go +++ b/integration/service/oasis/stationfinder/cloudfinder/low_energy_location_station_finder.go @@ -3,8 +3,8 @@ package cloudfinder import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/api/search/searchcoordinate" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/searchhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/searchconnector" - "github.com/Telenav/osrm-backend/integration/service/oasis/searchhelper" ) // LowEnergyLocationCandidateNumber indicates how much charge station to be searched for low energy point diff --git a/integration/service/oasis/stationfinder/cloudfinder/orig_station_finder.go b/integration/service/oasis/stationfinder/cloudfinder/orig_station_finder.go index aaf0996ba8c..2cec717a4f0 100644 --- a/integration/service/oasis/stationfinder/cloudfinder/orig_station_finder.go +++ b/integration/service/oasis/stationfinder/cloudfinder/orig_station_finder.go @@ -3,8 +3,8 @@ package cloudfinder import ( "github.com/Telenav/osrm-backend/integration/api/oasis" "github.com/Telenav/osrm-backend/integration/api/search/searchcoordinate" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/searchhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/searchconnector" - "github.com/Telenav/osrm-backend/integration/service/oasis/searchhelper" ) //@todo: This number need to be adjusted based on charge station profile diff --git a/integration/service/oasis/stationfinder/stationfinderalg/stations_iterator_alg.go b/integration/service/oasis/stationfinder/stationfinderalg/stations_iterator_alg.go index f8fb1aaa184..daf88ef5cb4 100644 --- a/integration/service/oasis/stationfinder/stationfinderalg/stations_iterator_alg.go +++ b/integration/service/oasis/stationfinder/stationfinderalg/stations_iterator_alg.go @@ -6,8 +6,8 @@ import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/api/osrm" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/osrmhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/osrmconnector" - "github.com/Telenav/osrm-backend/integration/service/oasis/osrmhelper" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype" "github.com/golang/glog" diff --git a/integration/service/oasis/stationgraph/station_graph.go b/integration/service/oasis/stationgraph/station_graph.go index fe2a86c06bf..6a306325648 100644 --- a/integration/service/oasis/stationgraph/station_graph.go +++ b/integration/service/oasis/stationgraph/station_graph.go @@ -4,7 +4,7 @@ import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" "github.com/Telenav/osrm-backend/integration/service/oasis/connectivitymap" - "github.com/Telenav/osrm-backend/integration/service/oasis/solution" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/solution" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype" "github.com/golang/glog" ) diff --git a/integration/service/oasis/stationgraph/station_graph_test.go b/integration/service/oasis/stationgraph/station_graph_test.go index 51ff6677071..f82b23d0534 100644 --- a/integration/service/oasis/stationgraph/station_graph_test.go +++ b/integration/service/oasis/stationgraph/station_graph_test.go @@ -7,7 +7,7 @@ import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" "github.com/Telenav/osrm-backend/integration/service/oasis/connectivitymap" - "github.com/Telenav/osrm-backend/integration/service/oasis/solution" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/solution" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype" "github.com/Telenav/osrm-backend/integration/util" "github.com/golang/glog"