souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6447030949f4d286891ceb5b6b8885056718d92c
parent 1a1186fbffd517a9395f7a0392ab37806d91ed6c
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 29 Oct 2024 19:33:06 +0000

remove elevation from Pos

it allows us no way to represent "elevation unknown" which is a
possibility for GPX files

Diffstat:
Mlib/Track.hs | 16+++++++++++-----
Mtests/UnitTest.hs | 2+-
2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/Track.hs b/lib/Track.hs @@ -4,6 +4,7 @@ module Track ( Track, Pos(..), pos, + elevation, parse, Track.length ) where @@ -20,7 +21,7 @@ import Data.List as List import Data.Map as Map import Control.Exception -data Pos = Pos Float Float Float deriving (Show, Eq) +data Pos = Pos Float Float deriving (Show, Eq) type Power = Maybe Int @@ -29,6 +30,7 @@ type HeartRate = Maybe Int data Point = Point { pos :: Pos, + elevation :: Maybe Float, time :: UTCTime, power :: Power, cadence :: Cadence, @@ -40,15 +42,16 @@ type Track = [Point] mkPoint pos = Point pos + (Just 0) (UTCTime (toEnum 60631) 43200) (Just 0) (Just 0) (Just 0) -parse :: String -> Either SomeException [Point] parse' str = [ Point - (Pos 51.6 0 0) + (Pos 51.6 0) + (Just 0) (UTCTime (toEnum 60631) 43200) (Just 0) (Just 0) @@ -63,12 +66,12 @@ elToPoint n = let lat = traceShow (getAttr "lat") (getAttr "lat") lon = getAttr "lon" - in mkPoint (Pos lat lon 0) + in mkPoint (Pos lat lon) where getAttr name = case (Map.lookup name attrs) of Just v -> (read (Data.Text.unpack v) :: Float) _ -> 0 - _ -> mkPoint (Pos 1 2 3) + _ -> mkPoint (Pos 0 0) getPoints :: Cursor -> [Point] getPoints c = @@ -82,6 +85,9 @@ getPoints c = List.map elToPoint trkpts +-- TODO am sure we could use some amazing monad thing to reduce +-- the amount of pattern matching here +parse :: String -> Either SomeException [Point] parse str = case parseText def (T.pack str) of Right gpx -> diff --git a/tests/UnitTest.hs b/tests/UnitTest.hs @@ -24,7 +24,7 @@ test2 = TestCase $ Right (p:ps) -> assertEqual "matches lat/lon" (Track.pos p) - (Track.Pos 51.0 (-0.1) 0.0) + (Track.Pos 51.0 (-0.1)) tests :: Test tests = TestList [