diff --git a/lib/Track.hs b/lib/Track.hs index fa3eff4..adde8f8 100644 --- 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 index b459b80..8ecff8d 100644 --- 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 [