remove redundant pattern match
we get the attributes using the cursor, so no need to parse it for the node
This commit is contained in:
parent
ff4451cb6f
commit
6e4073ca7a
63
lib/Track.hs
63
lib/Track.hs
@ -61,40 +61,37 @@ instance Exception BadFile
|
|||||||
|
|
||||||
elToPoint :: Cursor -> Either SomeException Point
|
elToPoint :: Cursor -> Either SomeException Point
|
||||||
elToPoint c =
|
elToPoint c =
|
||||||
case node c of
|
let lat = listToMaybe (attribute "lat" c) >>= asFloat
|
||||||
NodeElement (Element _ attrs _) ->
|
lon = listToMaybe (attribute "lon" c) >>= asFloat
|
||||||
let lat = listToMaybe (attribute "lat" c) >>= asFloat
|
ts =
|
||||||
lon = listToMaybe (attribute "lon" c) >>= asFloat
|
listToMaybe (child c >>= element (gpxNS "time") >>= child >>= content)
|
||||||
ele = listToMaybe (child c >>= element (gpxNS "ele") >>= child >>= content) >>= asFloat
|
>>= (Data.Time.ISO8601.parseISO8601 . Data.Text.unpack)
|
||||||
ts =
|
ele = listToMaybe (child c >>= element (gpxNS "ele") >>= child >>= content) >>= asFloat
|
||||||
listToMaybe (child c >>= element (gpxNS "time") >>= child >>= content)
|
gpxtpx =
|
||||||
>>= (Data.Time.ISO8601.parseISO8601 . Data.Text.unpack)
|
child c
|
||||||
gpxtpx =
|
>>= element (gpxNS "extensions")
|
||||||
child c
|
>>= child
|
||||||
>>= element (gpxNS "extensions")
|
>>= element (tpxNS "TrackPointExtension")
|
||||||
>>= child
|
>>= child
|
||||||
>>= element (tpxNS "TrackPointExtension")
|
extn n =
|
||||||
>>= child
|
gpxtpx >>= element n >>= child >>= content
|
||||||
extn n =
|
|
||||||
gpxtpx >>= element n >>= child >>= content
|
|
||||||
|
|
||||||
cadence = extn (tpxNS "cad")
|
cadence = extn (tpxNS "cad")
|
||||||
hr = extn (tpxNS "hr")
|
hr = extn (tpxNS "hr")
|
||||||
power = extn "{http://www.garmin.com/xmlschemas/PowerExtension/v1}PowerInWatts"
|
power = extn "{http://www.garmin.com/xmlschemas/PowerExtension/v1}PowerInWatts"
|
||||||
in if isJust lat && isJust lon && isJust ts
|
in if isJust lat && isJust lon && isJust ts
|
||||||
then
|
then
|
||||||
Right $
|
Right $
|
||||||
Point
|
Point
|
||||||
(Pos (fromJust lat) (fromJust lon) ele)
|
(Pos (fromJust lat) (fromJust lon) ele)
|
||||||
(fromJust ts)
|
(fromJust ts)
|
||||||
(listToMaybe cadence >>= asInt)
|
(listToMaybe cadence >>= asInt)
|
||||||
(listToMaybe power >>= asInt)
|
(listToMaybe power >>= asInt)
|
||||||
(listToMaybe hr >>= asInt)
|
(listToMaybe hr >>= asInt)
|
||||||
else Left (toException (BadFile "missing a required attribute"))
|
else Left (toException (BadFile "missing a required attribute"))
|
||||||
where
|
where
|
||||||
asFloat v = (readMaybe :: String -> Maybe Float) (Data.Text.unpack v)
|
asFloat v = (readMaybe :: String -> Maybe Float) (Data.Text.unpack v)
|
||||||
asInt v = (readMaybe :: String -> Maybe Int) (Data.Text.unpack v)
|
asInt v = (readMaybe :: String -> Maybe Int) (Data.Text.unpack v)
|
||||||
_ -> Left (toException (BadFile "did not find trkpt"))
|
|
||||||
|
|
||||||
getPoints :: Cursor -> Either SomeException [Point]
|
getPoints :: Cursor -> Either SomeException [Point]
|
||||||
getPoints c =
|
getPoints c =
|
||||||
|
Loading…
Reference in New Issue
Block a user