From 2204a53a4f7b3c9504cbd30286be05977addee86 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Fri, 25 Oct 2024 00:00:37 +0100 Subject: [PATCH] parse power --- src/Track.elm | 4 +++- tests/Fixtures.elm | 16 +++++++++++++--- tests/TrackTest.elm | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Track.elm b/src/Track.elm index a25e824..5793f4f 100644 --- a/src/Track.elm +++ b/src/Track.elm @@ -10,6 +10,7 @@ type alias Position = (Float, Float, Maybe Float) -- lat, lon, ele type alias Point = { loc : Position , time : Maybe Time.Posix + , power : Maybe Int } type alias Track = List Point @@ -24,10 +25,11 @@ timeDecoder = XD.andThen (\ts -> triple x y z = (x,y,z) -pointDecoder = XD.map2 Point +pointDecoder = XD.map3 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))) gpxDecoder = diff --git a/tests/Fixtures.elm b/tests/Fixtures.elm index 53d33f7..5228a6b 100644 --- a/tests/Fixtures.elm +++ b/tests/Fixtures.elm @@ -65,7 +65,17 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/ """ threepoints_expected = - [ (Point (51.600643, -0.01856, Just 64.8) (Just (Time.millisToPosix 1729669252256))) - , (Point (51.600679, -0.018179, Just 65.5) (Just (Time.millisToPosix 1729669255259))) - , (Point (51.600697, -0.018064, Just 66.2) (Just (Time.millisToPosix 1729669256231))) + [ (Point + (51.600643, -0.01856, Just 64.8) + (Just (Time.millisToPosix 1729669252256)) + (Just 89) + ) + , (Point + (51.600679, -0.018179, Just 65.5) + (Just (Time.millisToPosix 1729669255259)) + (Just 86)) + , (Point + (51.600697, -0.018064, Just 66.2) + (Just (Time.millisToPosix 1729669256231)) + (Just 86)) ] diff --git a/tests/TrackTest.elm b/tests/TrackTest.elm index 2bc7dd9..ef13302 100644 --- a/tests/TrackTest.elm +++ b/tests/TrackTest.elm @@ -23,7 +23,8 @@ specs = Fixtures.threepoints in case Track.parse xml of - Ok (p::pts) -> Expect.equal p (Point (51.600643, -0.01856, Nothing) (Just (Time.millisToPosix 1729669252256))) + Ok (p::pts) -> + Expect.equal p (Point (51.600643, -0.01856, Nothing) (Just (Time.millisToPosix 1729669252256)) (Just 89)) Ok _ -> Expect.fail "empty list" (Err f) -> Expect.fail f