Trip log: a trip is a library folder (Trips/<date> <name>) with the planned route and its stops; the car's GNSS recorded into its track there (10 m steps, written every minute and at the end), GET/POST/DELETE /api/trip/log; the Trip menu's Start / End and the line really driven (--route-driven); along-route POI mode for the plugins in TODO
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 02:25:20 +01:00
1 parent 809e88ab1a
commit 7d72e9eb63
7 files changed
+279 -1

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
require_relative "test_helper"
require "tmpdir"
require "maptool/library"
require "maptool/gpx_store"
require "maptool/trip_log"
class TripLogTest < Minitest::Test
# Start makes the folder with the plan and its named stops; fixes 10 m
# apart become the car's track (written on the first flush, replaced
# after); stop closes it.
def test_a_trip_records_into_its_folder
Dir.mktmpdir do |dir|
library = Maptool::Library.new(File.join(dir, "library.sqlite"), gpx_store: Maptool::GpxStore.new(File.join(dir, "gpx")), sources_dir: File.join(dir, "sources"))
log = Maptool::TripLog.new(File.join(dir, "trip_log.json"), library: library)
plan = { geometry: { type: "LineString", coordinates: [[17.0, 48.0], [17.1, 48.0]] }, properties: { distance_km: 7.4, time_s: 600 } }
folder = log.start("Tatry", plan: plan, stops: [{ lngLat: [17.0, 48.0], name: "My position" }, { lngLat: [17.1, 48.0], name: "Camp" }], now: Time.utc(2026, 12, 1, 8))
assert_equal "Trips/2026-12-01 Tatry", folder
assert_raises(ArgumentError) { log.start("again") }
log.record(17.0, 48.0, 150, 1000)
log.record(17.00001, 48.0, 150, 1001) # < 10 m: skipped
log.record(17.001, 48.0, 151, 1002)
log.record(17.002, 48.0, 152, 1100) # a minute on: flushed
assert_equal 3, log.status[:points]
assert_equal [[17.001, 48.0], [17.002, 48.0]], log.status(since: 1)[:coordinates]
assert_equal folder, log.stop
refute log.active?
names = library.nodes.flat_map { |label, _key, _stamp, read| [label, *JSON.parse(read.call)["features"].map { |f| f.dig("properties", "name") }] }.compact
assert(library.nodes.all? { |label, *| label.include?("2026-12-01 Tatry") }) # all in the trip's folder
assert_includes names.join(" "), "Camp"
assert_includes names.join(" "), "Car 2026-12-01"
assert_includes names.join(" "), "Plan"
refute_includes names.join(" "), "My position"
end
end
end