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:
parent
1a1186fbff
commit
6447030949
16
lib/Track.hs
16
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 ->
|
||||
|
@ -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 [
|
||||
|
Loading…
Reference in New Issue
Block a user