Add activity type and a click-to-open track profile panel
CI / check (push) Successful in 41s
CI / deploy (push) Successful in 15s

Track properties gain activity_type (FIT: sport enum from the
session/sport message, Garmin's own table; GPX: <trk><type> passed
through as-is) alongside the existing distance/elevation/duration.

Clicking a track line now opens a bottom panel with a chart per
metric the track actually has (elevation always; speed/cadence/heart
rate only when present — FIT's record fields or GPX's device
extensions). TrackStats.build_profile computes cumulative distance
the same way for both formats so they're directly comparable. One
pointermove listener drives a synchronized crosshair across every
chart, a single tooltip listing all series, and a map marker at the
hovered point's position — hovering the chart shows where on the
track that moment was.
This commit is contained in:
randy committed 2026-09-07 13:38:49 +02:00
1 parent cd4eef342b
commit 105651f005
14 files changed
+655 -42

No files matched your search

+64
View File
@@ -57,4 +57,68 @@ class FitTest < Minitest::Test
assert_raises(Maptool::Fit::ParseError) { Maptool::Fit.to_geojson(path) }
end
# A second, richer fixture (session message with a sport enum, record
# messages carrying heart_rate/cadence/speed too) — kept separate from
# build_fit/write_fit above so those stay a minimal, easy-to-read
# position-only case.
def build_activity_fit(records, sport: nil)
body = +""
if sport
session_definition = [0, 0].pack("CC") + [18].pack("S<") + [1].pack("C") + [5, 1, 0x00].pack("C3")
body << [0b01000001].pack("C") << session_definition
body << [0b00000001].pack("C") << [sport].pack("C")
end
record_definition = [0, 0].pack("CC") + [20].pack("S<") + [5].pack("C") +
[0, 4, 0x85].pack("C3") + [1, 4, 0x85].pack("C3") +
[3, 1, 0x02].pack("C3") + [4, 1, 0x02].pack("C3") + [6, 2, 0x84].pack("C3")
body << [0b01000000].pack("C") << record_definition
records.each do |r|
body << [0b00000000].pack("C") << le32(r[:lat]) << le32(r[:lon])
body << [r[:heart_rate] || 0xFF].pack("C") << [r[:cadence] || 0xFF].pack("C")
speed_raw = r[:speed_mps] ? (r[:speed_mps] * 1000).round : 0xFFFF
body << [speed_raw].pack("S<")
end
header = [12, 16, 0, 0].pack("C2S<") + le32(body.bytesize) + ".FIT"
header + body + "\x00\x00"
end
def write_activity_fit(records, sport: nil)
path = File.join(Dir.mktmpdir, "activity.fit")
File.binwrite(path, build_activity_fit(records, sport: sport))
path
end
def test_activity_type_comes_from_the_session_messages_sport_enum
path = write_activity_fit([{ lat: 100_000_000, lon: 200_000_000 }], sport: 2)
geojson = Maptool::Fit.to_geojson(path)
assert_equal "cycling", geojson["features"][0]["properties"]["activity_type"]
end
def test_activity_type_is_nil_without_a_session_message
path = write_activity_fit([{ lat: 100_000_000, lon: 200_000_000 }])
geojson = Maptool::Fit.to_geojson(path)
assert_nil geojson["features"][0]["properties"]["activity_type"]
end
def test_profile_carries_heart_rate_cadence_and_speed_treating_0xff_as_absent
path = write_activity_fit([
{ lat: 100_000_000, lon: 200_000_000, heart_rate: 140, cadence: 80, speed_mps: 3.5 },
{ lat: 100_000_100, lon: 200_000_100 }, # no extras -> 0xFF/0xFFFF sentinels
])
profile = Maptool::Fit.to_geojson(path)["features"][0]["properties"]["profile"]
assert_equal 140, profile[0]["heart_rate_bpm"]
assert_equal 80, profile[0]["cadence_rpm"]
assert_in_delta 3.5, profile[0]["speed_mps"]
assert_nil profile[1]["heart_rate_bpm"]
assert_nil profile[1]["speed_mps"]
end
end