commit 2204a53a4f7b3c9504cbd30286be05977addee86
parent 086664f8fb80301da4439af877fb7f5a31dca741
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 25 Oct 2024 00:00:37 +0100
parse power
Diffstat:
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git 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
@@ -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
@@ -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