souplesse

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

commit b78dbda7b8c9b2e3c1cfe3fdf83ee690dccbb513
parent 4922e4d5d9f282cebb2e084298750e92f76bbcbd
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 23 Oct 2024 23:49:19 +0100

parse actual lat/lon from gpx trkpt nodes

Diffstat:
Msrc/Track.elm | 11+++++------
Mtests/TrackTest.elm | 10++++++++--
2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/Track.elm b/src/Track.elm @@ -1,8 +1,7 @@ -module Track exposing (Track, parse) +module Track exposing (Track, Point, parse) import Result -import Xml.Decode as XD exposing (path, single, list, float) - +import Xml.Decode as XD exposing (path, list, floatAttr) type alias Point = { lat : Float @@ -12,11 +11,11 @@ type alias Point = type alias Track = List Point pointDecoder = XD.map2 Point - (XD.path ["ele"] (single float)) - (XD.path ["ele"] (single float)) + (floatAttr "lat") + (floatAttr "lon") gpxDecoder = - (XD.path [ "trk", "trkseg", "trkpt" ] (XD.list pointDecoder)) + (path [ "trk", "trkseg", "trkpt" ] (list pointDecoder)) parse str = XD.run gpxDecoder str diff --git a/tests/TrackTest.elm b/tests/TrackTest.elm @@ -1,7 +1,7 @@ module TrackTest exposing (specs) import Fixtures -import Track exposing (Track) +import Track exposing (Track, Point) import Test exposing (..) import Expect exposing (Expectation) @@ -12,8 +12,14 @@ specs = \_ -> let r = Track.parse Fixtures.threepoints + expected = + [ (Point 51.600643 -0.01856) + , (Point 51.600679 -0.018179) + , (Point 51.600697 -0.018064) + ] + in case r of - (Ok trk) -> Expect.equal (List.length trk) 3 + (Ok trk) -> Expect.equalLists trk expected _ -> Expect.fail "not ok" ]