Planning (the Design canvas' Plan and GridToday, ideas from azedler/roadplanner): a stop's type as its NPS pictogram (marker and list), notes on the trip, its days and stops, + on a leg inserts the next point there; a parking spot per stop (P marker, the route goes there, the walk shown); a link pasted into the search becomes a place (/api/link: the URL's coordinates, else the page's geo meta / JSON-LD / a map link; public addresses only, logged in), added on the leg it lengthens least; avoids for the trip (+ ferries, unpaved) or a day (routed in pieces, joined); Check and Costs folds in the Route panel (no leave time, long days, arriving after sunset, long walks, missing vignettes; fuel from km × consumption × price, stop costs / paid, the budget); Today in drive mode's Menu (stops left, tonight, sunset, Open-Meteo weather, the day's notes, Skip next, Tomorrow). Plugins along the trip's route (Maptool::Corridor, a corridor width; Overpass around:) and plugin settings saved server-side; p4n via a host Firefox's cookies (docs/deployment.adoc). The recording's days (cut where the car stood ≥ 4 h, or by hand) and their export (days, a piece A–B, the whole trip; GPX with times). Track replay in the GNSS simulator. Step advance 5 m past a maneuver. The level gauge (drive mode, from Terrain): lift per wheel to the ramps' steps from roll, pitch, wheelbase and track
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-12-03 23:34:25 +01:00
1 parent 5e31dfaba9
commit 87d7bd2463
36 files changed
+2047 -123

No files matched your search

+43 -1
View File
@@ -499,7 +499,7 @@ class AppTest < Minitest::Test
def test_plugins_lists_whatever_is_on_disk
response = request.get("/api/plugins")
assert_equal 200, response.status
assert_equal [{ "name" => "test-plugin", "label" => "Test plugin" }], json_body(response)
assert_equal [{ "name" => "test-plugin", "label" => "Test plugin", "route" => false, "settings" => [], "set" => [] }], json_body(response)
end
def test_plugins_run_imports_the_output_into_a_folder_of_its_own
@@ -516,6 +516,22 @@ class AppTest < Minitest::Test
assert_equal "Test POI", saved["features"][0]["properties"]["name"]
end
# Along the trip's route: what lies further off than the corridor dropped.
def test_plugins_run_along_the_route_keeps_the_corridor
store = Maptool::App::TRIP_STORE
saved = store.instance_variable_get(:@trip)
run = lambda do |line|
store.instance_variable_set(:@trip, saved.merge(route: { geometry: { coordinates: line } }))
json_body(request.post("/api/plugins/test-plugin/run", params: { route: "1", corridor_km: "2" }, **logged_in_env))["count"]
end
assert_equal 1, run.([[17.0, 47.99], [17.1, 47.99]]) # the POI ~1.1 km off
assert_equal 0, run.([[17.0, 47.95], [17.1, 47.95]]) # ~5.6 km off
store.instance_variable_set(:@trip, saved.merge(route: nil))
assert_equal 422, request.post("/api/plugins/test-plugin/run", params: { route: "1", corridor_km: "2" }, **logged_in_env).status
ensure
store.instance_variable_set(:@trip, saved)
end
def test_plugins_run_requires_a_bbox
response = request.post("/api/plugins/test-plugin/run", **logged_in_env)
assert_equal 400, response.status
@@ -696,6 +712,32 @@ class AppTest < Minitest::Test
latest.clear
end
# The recording's days and its export: a GPX with a track per day, or a .zip.
def test_trip_log_days_and_export
log = Maptool::App::TRIP_LOG
log.stop
assert_equal 200, request.post("/api/trip/log", input: JSON.generate(name: "Export test"), "CONTENT_TYPE" => "application/json", **logged_in_env).status
t0 = Time.new(2026, 12, 1, 10).to_f
10.times { |i| log.record(17.0, 48.0 + i * 0.001, 100.0, t0 + i * 60) }
10.times { |i| log.record(17.0, 48.1 + i * 0.001, 100.0, t0 + 10 * 3600 + i * 60) } # stood 10 h
log.record(17.0, 48.2, 100.0, t0 + 11 * 3600)
days = json_body(request.get("/api/trip/log/days?track=1", **logged_in_env))
assert_equal [true, 2, "auto"], [days["active"], days["days"].size, days["days"][0]["cut"]["kind"]]
assert_equal 21, days["track"].size
gpx = request.get("/api/trip/log/export?pauses=1", **logged_in_env)
assert_equal 2, gpx.body.scan("<trk>").size
assert_includes gpx.body, "Stood "
one = request.get("/api/trip/log/export?days=2", **logged_in_env).body
assert_equal 1, one.scan("<trk>").size
zip = request.get("/api/trip/log/export?per_day=1", **logged_in_env)
assert_equal "application/zip", zip.content_type
assert_equal 200, request.post("/api/trip/log/days", input: JSON.generate(join: days["track"][10][2]), "CONTENT_TYPE" => "application/json", **logged_in_env).status
assert_equal 1, json_body(request.get("/api/trip/log/days", **logged_in_env))["days"].size
ensure
log.stop
end
# A tunnel: no fix for a while, the position carried along the trip's
# route — at the average speed it was entered at, by the CAN speed when there is one.
def test_no_fix_on_the_route_is_dead_reckoned_along_it
+28
View File
@@ -0,0 +1,28 @@
require_relative "test_helper"
require "maptool/corridor"
class CorridorTest < Minitest::Test
C = Maptool::Corridor
# 30 km east along 48° N, as a vertex every ~0.75 km
LINE = (0..40).map { |i| [17.0 + i * 0.01, 48.0] }
def test_circles_cover_the_corridor_with_no_gap
circles = C.circles(LINE, 2.0)
assert_in_delta 2.5, circles.first[1], 1e-9
# every point 2 km off the line, all along it, inside a circle
(0..300).each do |i|
lon = 17.0 + i * 0.4 / 300
edge = [lon, 48.0 + 2.0 / C::KM_PER_DEG]
assert circles.any? { |center, r| C.km(center, edge) <= r + 1e-6 }, "gap at #{lon}"
end
assert_operator circles.size, :<=, (C.km(LINE.first, LINE.last) / 3.0).ceil + 2
end
def test_distance_to_the_line_and_thinning
assert_in_delta 1.0, C.distance_km([17.2, 48.0 + 1.0 / C::KM_PER_DEG], LINE), 1e-3
assert_in_delta C.km([16.99, 48.0], LINE.first), C.distance_km([16.99, 48.0], LINE), 1e-9 # past an end: to the end
thin = C.thin(LINE, 2.0)
assert_equal [LINE.first, LINE.last], [thin.first, thin.last]
assert thin.each_cons(2).to_a[0..-2].all? { |a, b| C.km(a, b) >= 2.0 }
end
end
+13
View File
@@ -22,6 +22,19 @@ class GnssSimTest < Minitest::Test
assert_in_delta (1000 / (36 / 3.6) / 2 + 500 / (45 / 3.6)) / Maptool::GnssSim::TICK_S, fixes.size, 3 # a fix every TICK_S
end
# A track replayed at its own pace: 100 m in 10 s (10 m/s), a stop of an
# hour cut to MAX_GAP_S, another 100 m in 20 s; ends at its end.
def test_replays_a_track_at_its_own_speed
fixes = []
step = 100.0 / 111_320
track = [[17.0, 48.0, 1000], [17.0, 48.0 + step, 1010], [17.0, 48.0 + step, 4610], [17.0, 48.0 + 2 * step, 4630]]
Maptool::GnssSim.new("http://valhalla", sleep: ->(_s) {}).replay(track) { |fix| fixes << fix }
assert_in_delta 10.0, fixes.first[:speed], 0.01
assert_in_delta 5.0, fixes.last[:speed], 0.01
assert_in_delta 48.0 + 2 * step, fixes.last[:lat], 1e-9
assert_in_delta (10 + Maptool::GnssSim::MAX_GAP_S + 20) / Maptool::GnssSim::TICK_S, fixes.size, 2
end
# Started with the trip's route: from its start along it, before any random trip.
def test_starts_along_a_given_route
fixes = Queue.new
+28
View File
@@ -0,0 +1,28 @@
require_relative "test_helper"
require_relative "../lib/maptool/link_place"
class LinkPlaceTest < Minitest::Test
def test_coordinates_in_the_link
place = Maptool::LinkPlace.from_url("https://www.google.com/maps/place/Hallstatt/@47.5622,13.6493,15z/data=!3m1!4b1!4m6!3m5!1s0x0:0x0!8m2!3d47.5622!4d13.6493")
assert_equal({ name: "Hallstatt", lat: 47.5622, lng: 13.6493, url: place[:url] }, place)
assert_equal [48.15, 17.11], Maptool::LinkPlace.from_url("https://maps.google.com/?q=48.15,17.11").values_at(:lat, :lng)
assert_equal [48.15, 17.11], Maptool::LinkPlace.from_url("geo:48.15,17.11").values_at(:lat, :lng)
assert_nil Maptool::LinkPlace.from_url("https://park4night.com/en/place/313577")
end
def test_coordinates_in_the_page
meta = %(<title>x</title><meta property="og:title" content="Stellplatz &amp; See"><meta property="place:location:latitude" content="47.7395"><meta property="place:location:longitude" content="13.4482">)
assert_equal({ name: "Stellplatz & See", lat: 47.7395, lng: 13.4482 }, Maptool::LinkPlace.from_html(meta))
ld = %(<title> Camp </title><script type="application/ld+json">{"geo":{"latitude": 46.1, "longitude": 14.2}}</script>)
assert_equal({ name: "Camp", lat: 46.1, lng: 14.2 }, Maptool::LinkPlace.from_html(ld))
link = %(<a href="https://www.google.com/maps?daddr=45.5,13.7">go</a>)
assert_equal [45.5, 13.7], Maptool::LinkPlace.from_html(link).values_at(:lat, :lng)
assert_nil Maptool::LinkPlace.from_html("<p>nothing</p>")
end
def test_no_private_addresses
assert_raises(Maptool::LinkPlace::Error) { Maptool::LinkPlace.fetch("http://127.0.0.1/") }
assert_raises(Maptool::LinkPlace::Error) { Maptool::LinkPlace.fetch("http://192.168.1.1/") }
assert_raises(Maptool::LinkPlace::Error) { Maptool::LinkPlace.fetch("file:///etc/passwd") }
end
end
+5
View File
@@ -120,4 +120,9 @@ class OverpassPoisTest < Minitest::Test
assert_includes query, %(["amenity"="drinking_water"])
assert_includes query, %(["natural"="spring"])
end
def test_build_query_along_a_line_uses_around
query = Maptool::OverpassPois.build_query(nil, around: [5000.0, [[17.1, 48.1], [17.2, 48.15]]])
assert_includes query, %(node["amenity"="drinking_water"](around:5000,48.1,17.1,48.15,17.2);)
end
end
+21 -3
View File
@@ -18,7 +18,7 @@ class PluginsTest < Minitest::Test
end
def test_list_finds_plugins_by_their_manifest
assert_equal [{ "name" => "hello", "label" => "Hello" }], Maptool::Plugins.list(@dir)
assert_equal [{ "name" => "hello", "label" => "Hello", "route" => false, "settings" => [] }], Maptool::Plugins.list(@dir)
end
def test_list_is_empty_for_a_directory_with_no_plugins
@@ -76,7 +76,7 @@ class PluginsTest < Minitest::Test
plugins = Maptool::Plugins.list([@dir, other_dir])
assert_equal [{ "name" => "hello", "label" => "Hello" }, { "name" => "private", "label" => "Private" }], plugins
assert_equal [{ "name" => "hello", "label" => "Hello", "route" => false, "settings" => [] }, { "name" => "private", "label" => "Private", "route" => false, "settings" => [] }], plugins
ensure
FileUtils.remove_entry(other_dir)
end
@@ -88,7 +88,7 @@ class PluginsTest < Minitest::Test
plugins = Maptool::Plugins.list([@dir, other_dir])
assert_equal [{ "name" => "hello", "label" => "Hello" }], plugins
assert_equal [{ "name" => "hello", "label" => "Hello", "route" => false, "settings" => [] }], plugins
ensure
FileUtils.remove_entry(other_dir)
end
@@ -97,4 +97,22 @@ class PluginsTest < Minitest::Test
result = Maptool::Plugins.run([Dir.mktmpdir, @dir], "hello", [1, 2, 3, 4])
assert_equal({ "type" => "FeatureCollection", "features" => [] }, result)
end
# A route and settings: --route/--corridor-km and the settings as env vars,
# only the keys the plugin.json declares saved.
def test_route_args_and_saved_settings_reach_the_command
File.write(File.join(@plugin_dir, "plugin.json"), JSON.generate(label: "Hello", command: "./run.sh", route: true,
settings: [{ key: "TOKEN", label: "Token" }, { key: "bad key" }]))
File.write(File.join(@plugin_dir, "run.sh"), "#!/bin/sh\necho \"{\\\"type\\\":\\\"FeatureCollection\\\",\\\"features\\\":[],\\\"args\\\":\\\"$5 $6\\\",\\\"token\\\":\\\"$TOKEN\\\"}\"\n")
assert_equal [{ "name" => "hello", "label" => "Hello", "route" => true, "settings" => [{ "key" => "TOKEN", "label" => "Token" }] }], Maptool::Plugins.list(@dir)
path = File.join(@dir, "settings.json")
assert_equal ["TOKEN"], Maptool::Plugins.save_settings(path, @dir, "hello", { "TOKEN" => " abc ", "OTHER" => "x" })
assert_equal 0o600, File.stat(path).mode & 0o777
env = Maptool::Plugins.saved_settings(path)["hello"]
result = Maptool::Plugins.run(@dir, "hello", [1, 2, 3, 4], route: "/tmp/r.geojson", corridor_km: 5.0, env: env)
assert_equal "--route=/tmp/r.geojson --corridor-km=5.0", result["args"]
assert_equal "abc", result["token"]
assert_empty Maptool::Plugins.save_settings(path, @dir, "hello", { "TOKEN" => "" })
end
end
+3 -2
View File
@@ -115,13 +115,14 @@ class RoutingTest < Minitest::Test
def test_a_car_keeps_its_fuel_euro_class_stickers_and_vignettes
Maptool::Routing.save_vehicles(@data, [{ "id" => "van", "name" => "Van", "fuel" => "diesel", "euro" => "6d", "stickers" => " DE green ",
"wheelbase" => "3.45", "track" => 1.75, "ramps" => "9, 3 6,5",
"vignettes" => [{ "country" => "sk", "until" => "2027-01-31" }, { "country" => "AT", "kind" => "toll" }] },
{ "id" => "b", "name" => "B", "type" => "bicycle", "fuel" => "diesel" }])
assert_equal({ id: "van", name: "Van", type: "car", fuel: "diesel", euro: "6d", stickers: "DE green",
assert_equal({ id: "van", name: "Van", type: "car", fuel: "diesel", euro: "6d", stickers: "DE green", wheelbase: 3.45, track: 1.75, ramps: "3 6.5 9",
vignettes: [{ country: "SK", kind: "vignette", until: "2027-01-31" }, { country: "AT", kind: "toll" }] }, Maptool::Routing.vehicle(@data, "van"))
assert_equal({ id: "b", name: "B", type: "bicycle" }, Maptool::Routing.vehicle(@data, "b")) # a bike burns nothing
[{ "fuel" => "coal" }, { "euro" => "7" }, { "vignettes" => [{ "country" => "Slovakia" }] }, { "vignettes" => [{ "country" => "SK", "until" => "soon" }] },
{ "vignettes" => [{ "country" => "SK", "kind" => "sticker" }] }].each do |bad|
{ "vignettes" => [{ "country" => "SK", "kind" => "sticker" }] }, { "ramps" => "3 60" }, { "track" => "5" }].each do |bad|
assert_raises(ArgumentError) { Maptool::Routing.save_vehicles(@data, [{ "id" => "x", "name" => "X", **bad }]) }
end
end
+33 -4
View File
@@ -33,16 +33,45 @@ class TripTest < Minitest::Test
router = ->(*) { calls += 1; { type: "Feature" } }
points = [{ lngLat: [17.1, 48.1] }, { lngLat: [17.2, 48.2] }]
store.update(points: points, vehicle: nil, avoid: {}, editing: nil, &router)
points[1] = { lngLat: [17.2, 48.2], night: true, stay: "90", note: " call ahead " }
trip = store.update(points: points, vehicle: nil, avoid: {}, editing: nil, name: "Alps", start: "2026-12-12T08:00", day_start: "09:30", &router)
points[1] = { lngLat: [17.2, 48.2], night: true, stay: "90", note: " call ahead ", type: "campground", day_note: "" }
points[0] = { lngLat: [17.1, 48.1], day_note: "leave early" }
trip = store.update(points: points, vehicle: nil, avoid: {}, editing: nil, name: "Alps", start: "2026-12-12T08:00", day_start: "09:30", note: " chains ", &router)
assert_equal 1, calls # an itinerary change isn't a route change
assert_equal({ lngLat: [17.2, 48.2], name: nil, nav: false, passed: false, night: true, stay: 90, note: "call ahead" }.compact, trip[:points][1])
assert_equal ["Alps", "2026-12-12T08:00", "09:30"], trip.values_at(:name, :start, :day_start)
assert_equal({ lngLat: [17.2, 48.2], name: nil, nav: false, passed: false, night: true, stay: 90, note: "call ahead", type: "campground" }.compact, trip[:points][1])
assert_equal "leave early", trip[:points][0][:day_note]
assert_equal ["Alps", "2026-12-12T08:00", "09:30", "chains"], trip.values_at(:name, :start, :day_start, :note)
assert_raises(ArgumentError) { store.update(points: [{ lngLat: [1, 2], type: "<b>" }], vehicle: nil, avoid: {}, editing: nil, &router) }
assert_raises(ArgumentError) { store.update(points: [{ lngLat: [1, 2], cost: "-1" }], vehicle: nil, avoid: {}, editing: nil, &router) }
trip = store.update(points: [{ lngLat: [1, 2], cost: "32", paid: "" }], vehicle: nil, avoid: {}, editing: nil, budget: "250", fuel_price: "1.619", &router)
assert_equal [32.0, nil, 250.0, 1.62], [trip[:points][0][:cost], trip[:points][0][:paid], trip[:budget], trip[:fuel_price]]
# a parking spot: the route goes there instead of the place
seen = nil
points[1] = points[1].merge(park: { lngLat: [17.21, 48.19], name: "P2" })
trip = store.update(points: points, vehicle: nil, avoid: {}, editing: nil) { |locations, *| seen = locations; { type: "Feature" } }
assert_equal [[17.1, 48.1], [17.21, 48.19]], seen
assert_equal({ lngLat: [17.21, 48.19], name: "P2" }, trip[:points][1][:park])
assert_raises(ArgumentError) { store.update(points: [{ lngLat: [1, 2], stay: "-5" }], vehicle: nil, avoid: {}, editing: nil, &router) }
assert_raises(ArgumentError) { store.update(points: points, vehicle: nil, avoid: {}, editing: nil, start: "tomorrow", &router) }
end
end
# A day with avoids of its own: its legs routed apart, joined into one route.
def test_a_days_own_avoids_route_it_apart
points = [{ lngLat: [0, 0] }, { lngLat: [1, 0], night: true }, { lngLat: [2, 0], avoid: { highways: true } }, { lngLat: [3, 0] }]
assert_equal [[[[0, 0], [1, 0]], { tolls: true }], [[[1, 0], [2, 0], [3, 0]], { highways: true }]], Maptool::TripStore.pieces(points, { tolls: true })
assert_equal [[[[0, 0], [1, 0], [2, 0], [3, 0]], {}]], Maptool::TripStore.pieces(points.map { |p| p.except(:avoid) }, {})
part = ->(from, to) { { type: "Feature", geometry: { coordinates: [[from, 0], [to, 0]] },
properties: { distance_km: 10.0, time_s: 600, legs_km: [10.0], legs_s: [600], maneuvers: [{ km: 10 }],
roads: [[0.0, "motorway", "AT"]], signals: [[from, 0, 5.0]], countries: [{ code: "AT", km: 10.0, motorway_km: 10.0, toll_km: 0.0 }] } } }
route = Maptool::Routing.merge([part.(0, 1), part.(1, 2)])
assert_equal [[0, 0], [1, 0], [2, 0]], route[:geometry][:coordinates]
assert_equal [20.0, 1200, [10.0, 10.0]], route[:properties].values_at(:distance_km, :time_s, :legs_km)
assert_equal [[0.0, "motorway", "AT"], [10.0, "motorway", "AT"]], route[:properties][:roads]
assert_equal [[0, 0, 5.0], [1, 0, 15.0]], route[:properties][:signals]
assert_equal [{ code: "AT", km: 20.0, motorway_km: 20.0, toll_km: 0.0 }], route[:properties][:countries]
end
# Off the route while driving for 3 fixes: routed again from the position
# to the points not reached yet (the first via passed: dropped).
def test_following_reroutes_from_the_position_off_the_route
+43
View File
@@ -0,0 +1,43 @@
require_relative "test_helper"
require "maptool/trip_days"
class TripDaysTest < Minitest::Test
D = Maptool::TripDays
# A drive: a point a minute from `start` (local time), `n` of them, going north.
def drive(start, n, lat0 = 48.0)
t0 = Time.new(*start).to_f
(0...n).map { |i| [17.0, lat0 + i * 0.01, 100.0 + i, t0 + i * 60] }
end
def test_a_night_stood_cuts_a_day_and_a_night_drive_cuts_at_three
points = drive([2026, 12, 1, 18, 0], 60) + drive([2026, 12, 2, 8, 0], 30, 49.0) # stood 13 h
assert_equal [[60, "auto"]], D.cuts(points)
night = drive([2026, 12, 1, 23, 0], 300) # through the night, no stop
assert_equal [[240, "night"]], D.cuts(night) # 23:00 + 240 min = 03:00
end
def test_cuts_by_hand_and_joined
points = drive([2026, 12, 1, 10, 0], 60) + drive([2026, 12, 1, 20, 0], 10, 49.0)
hand = points[30][3] - 20 # between two points: the day starts at the next one
cuts = D.cuts(points, hand: [hand])
assert_equal [[30, "hand"], [60, "auto"]], cuts
assert_equal [[30, "hand"]], D.cuts(points, hand: [hand], joined: [points[60][3]])
days = D.days(points, cuts)
assert_equal [1, 2, 3], days.map { |d| d[:index] }
assert_equal [0, 30, 60], days.map { |d| d[:from] }
assert_equal "auto", days[1][:cut][:kind]
assert_equal 9 * 3600 + 60, days[1][:cut][:stood_s] # from 10:59 to 20:00
assert_in_delta 29 * 60, days[0][:driving_s], 1
assert_nil days.last[:cut]
end
def test_gpx_has_a_track_per_piece_with_times_and_pauses
points = drive([2026, 12, 1, 10, 0], 3) + drive([2026, 12, 1, 11, 0], 3, 48.1)
gpx = D.gpx([["Day 1", points.first(3)], ["Day 2", points.last(3)]], D.pauses(points))
assert_equal 2, gpx.scan("<trk>").size
assert_includes gpx, "<time>#{Time.at(points[0][3]).utc.iso8601}</time>"
assert_includes gpx, "Stood 58 min"
end
end
+23
View File
@@ -65,4 +65,27 @@ class TripLogTest < Minitest::Test
refute Maptool::TripLog.new(log_dir, library: lib).active? # ended stays ended
end
end
# The days' cuts by hand and the joins go into the journal — while it
# runs and after it ended — and a restart doesn't take them for a trip.
def test_cuts_and_joins_are_journaled_running_or_ended
Dir.mktmpdir do |dir|
log = Maptool::TripLog.new(File.join(dir, "trip_log"), library: library(dir))
assert_nil log.recording
log.start("Days", now: Time.utc(2026, 12, 1, 8))
log.record(17.0, 48.0, nil, 1000)
log.record(17.001, 48.0, nil, 1010)
log.mark(:cut, 1005)
rec = log.recording
assert rec[:active]
assert_equal [[1005.0], 2], [rec[:hand], rec[:points].size]
log.stop
log.mark(:join, 1010)
rec = log.recording
refute rec[:active]
assert_equal [[1005.0], [1010.0], "Trips/2026-12-01 Days"], rec.values_at(:hand, :joined, :folder)
refute Maptool::TripLog.new(File.join(dir, "trip_log"), library: library(dir)).active?
assert_raises(ArgumentError) { log.mark(:other, 1) }
end
end
end