remove elm gpx parser

This commit is contained in:
Daniel Barlow 2024-11-12 18:44:40 +00:00
parent 543873164e
commit b8fee7b0e3
3 changed files with 0 additions and 189 deletions

View File

@ -1,43 +0,0 @@
module Track exposing (Track, Point, parse)
import Result
import Xml.Decode as XD exposing (path, list, single, floatAttr, stringAttr)
import Time
import Iso8601
type alias Position = (Float, Float, Maybe Float) -- lat, lon, ele
type alias Point =
{ loc : Position
, time : Maybe Time.Posix
, power : Maybe Int
, cadence : Maybe Int
, hr : Maybe Int
}
type alias Track = List Point
timeDecoder : XD.Decoder Time.Posix
timeDecoder = XD.andThen (\ts ->
case Iso8601.toTime ts of
Result.Ok time -> XD.succeed time
Result.Err f -> XD.fail "err"
)
XD.string
triple x y z = (x,y,z)
pointDecoder = XD.map5 Point
(XD.map3 triple (floatAttr "lat") (floatAttr "lon")
(XD.maybe (path ["ele"] (single XD.float))))
(XD.maybe (path ["time"] (single timeDecoder)))
(XD.maybe (path ["extensions", "gpxtpx:TrackPointExtension", "pwr:PowerInWatts"] (single XD.int)))
(XD.maybe (path ["extensions", "gpxtpx:TrackPointExtension", "gpxtpx:cad"] (single XD.int)))
(XD.maybe (path ["extensions", "gpxtpx:TrackPointExtension", "gpxtpx:hr"] (single XD.int)))
gpxDecoder =
(path [ "trk", "trkseg", "trkpt" ] (list pointDecoder))
parse str = XD.run gpxDecoder str

View File

@ -1,89 +0,0 @@
module Fixtures exposing (threepoints, threepoints_expected)
import Track exposing (Track, Point)
import Time
import Maybe
threepoints = """
<?xml version="1.0" encoding="UTF-8"?>
<gpx
version="1.1"
creator="OpenTracks"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:topografix="http://www.topografix.com/GPX/Private/TopoGrafix/0/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:opentracks="http://opentracksapp.com/xmlschemas/v1"
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v2"
xmlns:gpxtrkx="http://www.garmin.com/xmlschemas/TrackStatsExtension/v1"
xmlns:cluetrust="http://www.cluetrust.com/Schemas/"
xmlns:pwr="http://www.garmin.com/xmlschemas/PowerExtension/v1"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/Private/TopoGrafix/0/1 http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v2 https://www8.garmin.com/xmlschemas/TrackPointExtensionv2.xsd http://www.garmin.com/xmlschemas/PowerExtension/v1 https://www8.garmin.com/xmlschemas/PowerExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackStatsExtension/v1 http://www.cluetrust.com/Schemas http://www.cluetrust.com/Schemas/gpxdata10.xsd http://opentracksapp.com/xmlschemas/v1 http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd">
<trk>
<name><![CDATA[2024-10-23T08:34+01]]></name>
<desc><![CDATA[]]></desc>
<type><![CDATA[unknown]]></type>
<extensions>
</extensions>
<trkseg>
<trkpt lat="51.600643" lon="-0.01856">
<ele>64.8</ele>
<time>2024-10-23T08:40:52.256+01:00</time>
<extensions><gpxtpx:TrackPointExtension>
<gpxtpx:speed>8.49</gpxtpx:speed>
<gpxtpx:cad>110</gpxtpx:cad>
<pwr:PowerInWatts>89</pwr:PowerInWatts>
<opentracks:accuracy_horizontal>3.216</opentracks:accuracy_horizontal><opentracks:distance>17.08</opentracks:distance>
<cluetrust:distance>1,468.88</cluetrust:distance>
</gpxtpx:TrackPointExtension></extensions>
</trkpt>
<trkpt lat="51.600679" lon="-0.018179">
<ele>65.5</ele>
<time>2024-10-23T08:40:55.259+01:00</time>
<extensions><gpxtpx:TrackPointExtension>
<gpxtpx:speed>8.57</gpxtpx:speed>
<gpxtpx:cad>111</gpxtpx:cad>
<pwr:PowerInWatts>86</pwr:PowerInWatts>
<opentracks:accuracy_horizontal>3.216</opentracks:accuracy_horizontal><opentracks:distance>17.08</opentracks:distance>
<cluetrust:distance>1,485.96</cluetrust:distance>
</gpxtpx:TrackPointExtension></extensions>
</trkpt>
<!-- insert-segment -->
<trkpt lat="51.600697" lon="-0.018064">
<ele>66.2</ele>
<time>2024-10-23T08:40:56.231+01:00</time>
<extensions><gpxtpx:TrackPointExtension>
<gpxtpx:speed>8.62</gpxtpx:speed>
<gpxtpx:cad>111</gpxtpx:cad>
<pwr:PowerInWatts>86</pwr:PowerInWatts>
<opentracks:accuracy_horizontal>3.216</opentracks:accuracy_horizontal><opentracks:distance>10.675</opentracks:distance>
<cluetrust:distance>1,496.635</cluetrust:distance>
</gpxtpx:TrackPointExtension></extensions>
</trkpt>
</trkseg>
</trk>
</gpx>
"""
threepoints_expected =
[ (Point
(51.600643, -0.01856, Just 64.8)
(Just (Time.millisToPosix 1729669252256))
(Just 89)
(Just 110)
Nothing
)
, (Point
(51.600679, -0.018179, Just 65.5)
(Just (Time.millisToPosix 1729669255259))
(Just 86)
(Just 111)
Nothing
)
, (Point
(51.600697, -0.018064, Just 66.2)
(Just (Time.millisToPosix 1729669256231))
(Just 86)
(Just 111)
Nothing
)
]

View File

@ -1,57 +0,0 @@
module TrackTest exposing (specs)
import Fixtures
import Track exposing (Track, Point)
import Test exposing (..)
import Expect exposing (Expectation)
import Time
specs: Test
specs =
describe "XML Parsing"
[ test "it parses points" <|
\_ ->
case Track.parse Fixtures.threepoints of
(Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk
_ -> Expect.fail "not ok"
, test "missing child ele node in track point" <|
\_ ->
let
xml = String.replace
"<ele>64.8</ele>"
""
Fixtures.threepoints
in
case Track.parse xml of
Ok (p::pts) ->
case p.loc of
(_, _, ele) -> Expect.equal ele Nothing
Ok _ -> Expect.fail "empty list"
(Err f) -> Expect.fail f
, test "heart rate" <|
\_ ->
let
xml = String.replace
"</gpxtpx:TrackPointExtension>"
"<gpxtpx:hr>97</gpxtpx:hr></gpxtpx:TrackPointExtension>"
Fixtures.threepoints
in
case Track.parse xml of
Ok (p::pts) ->
Expect.equal p.hr (Just 97)
Ok _ -> Expect.fail "no points"
(Err f) -> Expect.fail f
, test "multiple trksegs are coalesced" <|
\_ ->
let
xml = String.replace
"<!-- insert-segment -->"
"</trkseg><trkseg>"
Fixtures.threepoints
in
case Track.parse xml of
(Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk
_ -> Expect.fail "not ok"
]