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

+53 -10
View File
@@ -12,8 +12,14 @@ module Maptool
EMPTY = { version: 0, points: [], vehicle: nil, avoid: {}, editing: nil, route: nil, error: nil }.freeze
# The itinerary: the trip's name, when it starts (local "YYYY-MM-DDTHH:MM")
# and when a day after a night stop starts ("HH:MM"); per point a night
# stop (the day ends there), the stay in minutes and a note.
# stop (the day ends there), the stay in minutes, a note, its type (an
# NPS pictogram's name, public/js/route.js STOP_TYPES) and, on a day's
# first point, the day's note; park: where the car stays ({ lngLat:,
# name: }, the route goes there, the place is a walk away); on a day's
# first point avoid: the day's own (AVOIDS), else the trip's; cost / paid:
# € planned there and paid; the trip's own note, budget and fuel price.
MAX_STAY_MIN = 7 * 24 * 60
AVOIDS = %i[tolls highways ferries unpaved].freeze
DATE_TIME = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}\z/
TIME = /\A\d{2}:\d{2}\z/
@@ -21,17 +27,38 @@ module Maptool
stay = p[:stay].nil? || p[:stay].to_s.empty? ? nil : Integer(p[:stay], exception: false)
raise ArgumentError, "stay must be 0–#{MAX_STAY_MIN} minutes" if stay && !(0..MAX_STAY_MIN).cover?(stay)
note = p[:note].to_s.strip[0, 500]
note, day_note = [p[:note], p[:day_note]].map { |n| n.to_s.strip[0, 500] }
type = p[:type].to_s
raise ArgumentError, "type must be an icon name" unless type.empty? || type.match?(/\A[a-z0-9-]{1,60}\z/)
cost, paid = [p[:cost], p[:paid]].map { |v| money(v) }
avoid = (p[:avoid].to_h.slice(*AVOIDS).to_h { |k, v| [k, !!v] } if p[:avoid].is_a?(Hash))
park = ({ lngLat: p[:park].fetch(:lngLat).map { |v| Float(v) }, name: p[:park][:name]&.to_s&.strip&.[](0, 120) }.compact if p[:park].is_a?(Hash))
{ lngLat: p.fetch(:lngLat).map { |v| Float(v) }, name: p[:name], nav: !!p[:nav], passed: !!p[:passed],
night: (true if p[:night]), stay: (stay if stay&.positive?), note: (note unless note.empty?) }.compact
night: (true if p[:night]), stay: (stay if stay&.positive?), note: (note unless note.empty?),
type: (type unless type.empty?), day_note: (day_note unless day_note.empty?), park: park, avoid: avoid, cost: cost, paid: paid }.compact
end
def self.itinerary(name:, start:, day_start:)
# € or nil; ArgumentError past MAX_MONEY or below 0.
MAX_MONEY = 1_000_000
def self.money(value)
return nil if value.nil? || value.to_s.strip.empty?
amount = Float(value, exception: false)
raise ArgumentError, "amounts must be 0–#{MAX_MONEY}" unless amount && (0..MAX_MONEY).cover?(amount)
amount.round(2)
end
def self.itinerary(name:, start:, day_start:, note: nil, budget: nil, fuel_price: nil)
name = name.to_s.strip[0, 80]
note = note.to_s.strip[0, 2000]
raise ArgumentError, "start must be YYYY-MM-DDTHH:MM" unless start.to_s.empty? || start.to_s.match?(DATE_TIME)
raise ArgumentError, "day_start must be HH:MM" unless day_start.to_s.empty? || day_start.to_s.match?(TIME)
{ name: (name unless name.empty?), start: (start unless start.to_s.empty?), day_start: (day_start unless day_start.to_s.empty?) }
{ name: (name unless name.empty?), start: (start unless start.to_s.empty?), day_start: (day_start unless day_start.to_s.empty?),
note: (note unless note.empty?), budget: money(budget), fuel_price: money(fuel_price) }.compact
end
def initialize(path)
@@ -134,25 +161,41 @@ module Maptool
[here, GnssSim.bearing(GnssSim.point_at(coords, km, [to - 0.02, 0].max), GnssSim.point_at(coords, km, [to + 0.02, km.last].min)).round(1)]
end
# The points to route, in pieces of the same avoids: [[locations,
# avoid], ...] — one piece unless a day has avoids of its own (on its
# first point in the list, the one after the night spot). A leg takes
# the avoids of the day it's driven in.
def self.pieces(points, avoid)
day = points.first&.dig(:avoid) || avoid
legs = points.each_with_index.filter_map do |p, i|
day = points[i + 1]&.dig(:avoid) || avoid if p[:night] # the next day leaves from the night spot
[p.dig(:park, :lngLat) || p[:lngLat], day] unless p[:passed]
end
legs.each_cons(2).chunk_while { |x, y| x[0][1] == y[0][1] }.map do |run|
[[run.first[0][0], *run.map { |_, to| to[0] }], run.first[0][1]]
end
end
# points: [{ lngLat: [lon, lat], name:, nav:, passed: }]. Routes through
# the ones not passed with the block (locations, vehicle id, avoid → the
# /api/route Feature, may raise Routing errors) unless only names/nav
# changed — the old route stays then. Passed points stay in the trip
# (shown dimmed, still editable: a stop missed out added afterwards),
# just not routed. Last write wins.
def update(points:, vehicle:, avoid:, editing:, name: nil, start: nil, day_start: nil)
def update(points:, vehicle:, avoid:, editing:, name: nil, start: nil, day_start: nil, note: nil, budget: nil, fuel_price: nil)
points = points.map { |p| self.class.point(p) }
itinerary = self.class.itinerary(name: name, start: start, day_start: day_start)
itinerary = self.class.itinerary(name: name, start: start, day_start: day_start, note: note, budget: budget, fuel_price: fuel_price)
avoid = (avoid || {}).to_h { |k, v| [k.to_sym, !!v] }
before = get
routed = ->(list) { list.reject { |p| p[:passed] }.map { |p| p[:lngLat] } }
same_route = routed.(before[:points]) == routed.(points) &&
routed = ->(list) { list.reject { |p| p[:passed] }.map { |p| p.dig(:park, :lngLat) || p[:lngLat] } }
same_route = self.class.pieces(before[:points], before[:avoid]) == self.class.pieces(points, avoid) &&
before[:vehicle] == vehicle && before[:avoid] == avoid && !before[:error]
route, error = if same_route then [before[:route], nil]
elsif routed.(points).size < 2 then [nil, nil]
else
begin
[yield(routed.(points), vehicle, avoid), nil]
pieces = self.class.pieces(points, avoid)
[Routing.merge(pieces.map { |locations, day_avoid| yield(locations, vehicle, day_avoid) }), nil]
rescue Routing::RouteError, Routing::Unavailable => e
[nil, e.message]
end