Dashboard overlay (Overlays → Live → Dashboard): one inclinometer (compass ring, roll and pitch), speed, the speed limit with an over-limit warning and, on the route, the next limit change, traffic signal, maneuver and its lanes; /api/route gains speed_limits, signals and lanes, POST /api/road gives the driven road's limit; GNSS simulation (random trips over Valhalla) for trying it without the car; the HMC5883L heading in can.json
This commit is contained in:
1 parent
5958ffd153
commit
190a8ad334
13 files changed
+713
-27
No files matched your search
@@ -0,0 +1,24 @@
|
||||
require_relative "test_helper"
|
||||
require_relative "../lib/maptool/gnss_sim"
|
||||
|
||||
class GnssSimTest < Minitest::Test
|
||||
# A 1 km route north, 36 km/h limit for the first half, untagged after.
|
||||
class FixedRoute < Maptool::GnssSim
|
||||
def random_route(_position)
|
||||
{ geometry: { coordinates: [[17.0, 48.0], [17.0, 48.0 + 1000.0 / 111_320]] },
|
||||
properties: { speed_limits: [[0.0, 40], [0.5, nil]] } }
|
||||
end
|
||||
end
|
||||
|
||||
def test_drives_the_route_at_its_limits_and_ends_at_its_end
|
||||
fixes = []
|
||||
sim = FixedRoute.new("http://valhalla", sleep: ->(_s) {})
|
||||
last = sim.drive([17.0, 48.0]) { |fix| fixes << fix }
|
||||
assert_in_delta 36 / 3.6, fixes.first[:speed], 0.01 # 90 % of 40
|
||||
assert_in_delta 45 / 3.6, fixes.last[:speed], 0.01 # 90 % of an untagged road's 50
|
||||
assert_in_delta 48.0 + 1000.0 / 111_320, fixes.last[:lat], 1e-9
|
||||
assert_equal [17.0, 48.0 + 1000.0 / 111_320], last
|
||||
assert fixes.each_cons(2).all? { |a, b| b[:lat] >= a[:lat] } # never backwards
|
||||
assert_in_delta 1000 / (36 / 3.6) / 2 + 500 / (45 / 3.6), fixes.size, 3 # ~1 fix a second
|
||||
end
|
||||
end
|
||||
+16
-5
@@ -145,18 +145,29 @@ class RoutingTest < Minitest::Test
|
||||
def test_a_route_sums_motorway_and_toll_km_per_country_and_can_avoid_tolls
|
||||
route = JSON.generate(trip: { summary: { length: 3, time: 90 }, legs: [{ shape: "wdg|xA{ubdQc@w@", maneuvers: [] }] })
|
||||
attributes = JSON.generate(admins: [{ country_code: "AT" }, { country_code: "SK" }],
|
||||
edges: [{ length: 1.0, road_class: "motorway", toll: false, end_node: { admin_index: 0 } },
|
||||
{ length: 0.5, road_class: "primary", toll: false, end_node: { admin_index: 0 } },
|
||||
{ length: 1.5, road_class: "motorway", toll: true, end_node: { admin_index: 1 } }])
|
||||
edges: [{ length: 1.0, road_class: "motorway", toll: false, speed_limit: 130, end_shape_index: 0, end_node: { admin_index: 0 } },
|
||||
{ length: 0.5, road_class: "primary", toll: false, speed_limit: 0, end_shape_index: 1, end_node: { admin_index: 0, traffic_signal: true } },
|
||||
{ length: 1.5, road_class: "motorway", toll: true, speed_limit: 130, end_shape_index: 1, end_node: { admin_index: 1 } }])
|
||||
ok = ->(body) { "HTTP/1.1 200 OK\r\nContent-Length: #{body.bytesize}\r\n\r\n#{body}" }
|
||||
request = serve_once(ok.(route), ok.(attributes)) do |url|
|
||||
countries = Maptool::Routing.route(url, [[1, 2], [3, 4]], { id: "car" }, { "tolls" => true })[:properties][:countries]
|
||||
assert_equal [{ code: "AT", km: 1.5, motorway_km: 1.0, toll_km: 0.0 }, { code: "SK", km: 1.5, motorway_km: 1.5, toll_km: 1.5 }], countries
|
||||
properties = Maptool::Routing.route(url, [[1, 2], [3, 4]], { id: "car" }, { "tolls" => true })[:properties]
|
||||
assert_equal [{ code: "AT", km: 1.5, motorway_km: 1.0, toll_km: 0.0 }, { code: "SK", km: 1.5, motorway_km: 1.5, toll_km: 1.5 }], properties[:countries]
|
||||
assert_equal [[0.0, 130], [1.0, nil], [1.5, 130]], properties[:speed_limits]
|
||||
assert_equal [[9.521034, 47.140974, 1.5]], properties[:signals]
|
||||
end
|
||||
assert_includes request, %("costing_options":{"auto":{"use_tolls":0.0}})
|
||||
assert_includes request, "/trace_attributes"
|
||||
end
|
||||
|
||||
def test_the_road_driven_is_the_last_matched_edge
|
||||
reply = JSON.generate(edges: [{ names: ["A"], road_class: "primary", speed_limit: 90 }, { names: ["B"], road_class: "motorway", speed_limit: "unlimited" }])
|
||||
request = serve_once("HTTP/1.1 200 OK\r\nContent-Length: #{reply.bytesize}\r\n\r\n#{reply}") do |url|
|
||||
assert_equal({ name: "B", road_class: "motorway", speed_limit: "unlimited" }, Maptool::Routing.road(url, [[17.1, 48.1], [17.2, 48.2]]))
|
||||
end
|
||||
assert_includes request, %("shape_match":"map_snap")
|
||||
assert_raises(Maptool::Routing::RouteError) { Maptool::Routing.road("http://x", [[17.1, 48.1]]) }
|
||||
end
|
||||
|
||||
def test_bicycle_and_foot_use_their_own_costing_without_the_country_lookup
|
||||
reply = JSON.generate(trip: { summary: { length: 1.5, time: 90 }, legs: [{ shape: "wdg|xA{ubdQc@w@", maneuvers: [] }] })
|
||||
request = serve_once("HTTP/1.1 200 OK\r\nContent-Length: #{reply.bytesize}\r\n\r\n#{reply}") do |url|
|
||||
|
||||
Reference in new issue
Block a user