remove elevation from Pos

it allows us no way to represent "elevation unknown" which is a
possibility for GPX files
This commit is contained in:
Daniel Barlow 2024-10-29 19:33:06 +00:00
parent 1a1186fbff
commit 6447030949
2 changed files with 12 additions and 6 deletions

View File

@ -4,6 +4,7 @@ module Track (
Track, Track,
Pos(..), Pos(..),
pos, pos,
elevation,
parse, parse,
Track.length Track.length
) where ) where
@ -20,7 +21,7 @@ import Data.List as List
import Data.Map as Map import Data.Map as Map
import Control.Exception import Control.Exception
data Pos = Pos Float Float Float deriving (Show, Eq) data Pos = Pos Float Float deriving (Show, Eq)
type Power = Maybe Int type Power = Maybe Int
@ -29,6 +30,7 @@ type HeartRate = Maybe Int
data Point = Point { data Point = Point {
pos :: Pos, pos :: Pos,
elevation :: Maybe Float,
time :: UTCTime, time :: UTCTime,
power :: Power, power :: Power,
cadence :: Cadence, cadence :: Cadence,
@ -40,15 +42,16 @@ type Track = [Point]
mkPoint pos = mkPoint pos =
Point Point
pos pos
(Just 0)
(UTCTime (toEnum 60631) 43200) (UTCTime (toEnum 60631) 43200)
(Just 0) (Just 0)
(Just 0) (Just 0)
(Just 0) (Just 0)
parse :: String -> Either SomeException [Point]
parse' str = [ parse' str = [
Point Point
(Pos 51.6 0 0) (Pos 51.6 0)
(Just 0)
(UTCTime (toEnum 60631) 43200) (UTCTime (toEnum 60631) 43200)
(Just 0) (Just 0)
(Just 0) (Just 0)
@ -63,12 +66,12 @@ elToPoint n =
let let
lat = traceShow (getAttr "lat") (getAttr "lat") lat = traceShow (getAttr "lat") (getAttr "lat")
lon = getAttr "lon" lon = getAttr "lon"
in mkPoint (Pos lat lon 0) in mkPoint (Pos lat lon)
where getAttr name = where getAttr name =
case (Map.lookup name attrs) of case (Map.lookup name attrs) of
Just v -> (read (Data.Text.unpack v) :: Float) Just v -> (read (Data.Text.unpack v) :: Float)
_ -> 0 _ -> 0
_ -> mkPoint (Pos 1 2 3) _ -> mkPoint (Pos 0 0)
getPoints :: Cursor -> [Point] getPoints :: Cursor -> [Point]
getPoints c = getPoints c =
@ -82,6 +85,9 @@ getPoints c =
List.map elToPoint trkpts 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 = parse str =
case parseText def (T.pack str) of case parseText def (T.pack str) of
Right gpx -> Right gpx ->

View File

@ -24,7 +24,7 @@ test2 = TestCase $
Right (p:ps) -> Right (p:ps) ->
assertEqual "matches lat/lon" assertEqual "matches lat/lon"
(Track.pos p) (Track.pos p)
(Track.Pos 51.0 (-0.1) 0.0) (Track.Pos 51.0 (-0.1))
tests :: Test tests :: Test
tests = TestList [ tests = TestList [