commit 6e4c1b735145f7ce625e9439e6170d833acafdfb
parent a85a00762d57451463a41c774e2206715c705a9c
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 25 Oct 2024 21:25:20 +0100
add hr
Diffstat:
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/Track.elm b/src/Track.elm
@@ -12,6 +12,7 @@ type alias Point =
, time : Maybe Time.Posix
, power : Maybe Int
, cadence : Maybe Int
+ , hr : Maybe Int
}
type alias Track = List Point
@@ -26,12 +27,13 @@ timeDecoder = XD.andThen (\ts ->
triple x y z = (x,y,z)
-pointDecoder = XD.map4 Point
+pointDecoder = XD.map5 Point
(XD.map3 triple (floatAttr "lat") (floatAttr "lon")
(XD.maybe (path ["ele"] (single XD.float))))
(XD.maybe (path ["time"] (single timeDecoder)))
(XD.maybe (path ["extensions", "gpxtpx:TrackPointExtension", "pwr:PowerInWatts"] (single XD.int)))
(XD.maybe (path ["extensions", "gpxtpx:TrackPointExtension", "gpxtpx:cad"] (single XD.int)))
+ (XD.maybe (path ["extensions", "gpxtpx:TrackPointExtension", "gpxtpx:hr"] (single XD.int)))
gpxDecoder =
diff --git a/tests/Fixtures.elm b/tests/Fixtures.elm
@@ -70,17 +70,20 @@ threepoints_expected =
(Just (Time.millisToPosix 1729669252256))
(Just 89)
(Just 110)
+ Nothing
)
, (Point
(51.600679, -0.018179, Just 65.5)
(Just (Time.millisToPosix 1729669255259))
(Just 86)
(Just 111)
+ Nothing
)
, (Point
(51.600697, -0.018064, Just 66.2)
(Just (Time.millisToPosix 1729669256231))
(Just 86)
(Just 111)
+ Nothing
)
]
diff --git a/tests/TrackTest.elm b/tests/TrackTest.elm
@@ -28,6 +28,19 @@ specs =
(_, _, ele) -> Expect.equal ele Nothing
Ok _ -> Expect.fail "empty list"
(Err f) -> Expect.fail f
+ , test "heart rate" <|
+ \_ ->
+ let
+ xml = String.replace
+ "</gpxtpx:TrackPointExtension>"
+ "<gpxtpx:hr>97</gpxtpx:hr></gpxtpx:TrackPointExtension>"
+ Fixtures.threepoints
+ in
+ case Track.parse xml of
+ Ok (p::pts) ->
+ Expect.equal p.hr (Just 97)
+ Ok _ -> Expect.fail "no points"
+ (Err f) -> Expect.fail f
, test "multiple trksegs are coalesced" <|
\_ ->