diff --git a/frontend/src/Track.elm b/frontend/src/Track.elm deleted file mode 100644 index ff2503a..0000000 --- a/frontend/src/Track.elm +++ /dev/null @@ -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 diff --git a/frontend/tests/Fixtures.elm b/frontend/tests/Fixtures.elm deleted file mode 100644 index 91e14f0..0000000 --- a/frontend/tests/Fixtures.elm +++ /dev/null @@ -1,89 +0,0 @@ -module Fixtures exposing (threepoints, threepoints_expected) -import Track exposing (Track, Point) -import Time -import Maybe - - -threepoints = """ - - - - - - - - - - -64.8 - - -8.49 -110 -89 -3.21617.08 -1,468.88 - - - -65.5 - - -8.57 -111 -86 -3.21617.08 -1,485.96 - - - - -66.2 - - -8.62 -111 -86 -3.21610.675 -1,496.635 - - - - - -""" - -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 - ) - ] diff --git a/frontend/tests/TrackTest.elm b/frontend/tests/TrackTest.elm deleted file mode 100644 index f235352..0000000 --- a/frontend/tests/TrackTest.elm +++ /dev/null @@ -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 - "64.8" - "" - 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 - "" - "97" - 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 - "" - "" - Fixtures.threepoints - in - case Track.parse xml of - (Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk - _ -> Expect.fail "not ok" - - ]