From 63f54a93556776f066ae8007974f7abeacbeb06f Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 31 Oct 2024 13:00:01 +0000 Subject: [PATCH] read heart rate --- lib/Track.hs | 8 +++++++- tests/UnitTest.hs | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Track.hs b/lib/Track.hs index 4f56c48..0bff627 100644 --- a/lib/Track.hs +++ b/lib/Track.hs @@ -7,6 +7,7 @@ module Track elevation, cadence, power, + heartRate, time, parse, Track.length, @@ -78,6 +79,11 @@ elToPoint c = >>= element (tpxNS "cad") >>= child >>= content + hr = + gpxtpx + >>= element (tpxNS "hr") + >>= child + >>= content power = gpxtpx >>= element (Name "PowerInWatts" (Just "http://www.garmin.com/xmlschemas/PowerExtension/v1") Nothing) @@ -96,7 +102,7 @@ elToPoint c = utime (listToMaybe cadence <&> asInt) (listToMaybe power <&> asInt) - Nothing + (listToMaybe hr <&> asInt) where asFloat v = (read (Data.Text.unpack v) :: Float) asInt v = (read (Data.Text.unpack v) :: Int) diff --git a/tests/UnitTest.hs b/tests/UnitTest.hs index 2644859..b614689 100644 --- a/tests/UnitTest.hs +++ b/tests/UnitTest.hs @@ -51,6 +51,7 @@ onepointWithAttrs = 2.4 128 + 160 55 3.21610.675 32.025 @@ -108,8 +109,8 @@ test4 = ( \(p : _) -> assertEqual "handles attributes" - (Just 25.2, Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779) - (Track.elevation p, Track.cadence p, Track.power p, Track.time p) + (Just 25.2, Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779, Just 160) + (Track.elevation p, Track.cadence p, Track.power p, Track.time p, Track.heartRate p) ) (Track.parse onepointWithAttrs)