first passing test
This commit is contained in:
commit
2286ae1a49
24
elm.json
Normal file
24
elm.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.3"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
13
shell.nix
Normal file
13
shell.nix
Normal file
@ -0,0 +1,13 @@
|
||||
with import <nixpkgs> {} ;
|
||||
pkgs.mkShell {
|
||||
packages = [
|
||||
pkgs.caddy
|
||||
pkgs.elmPackages.elm
|
||||
pkgs.elmPackages.elm-format
|
||||
pkgs.elmPackages.elm-optimize-level-2
|
||||
pkgs.elmPackages.elm-review
|
||||
pkgs.elmPackages.elm-test
|
||||
# pkgs.nodejs_18
|
||||
# pkgs.shellcheck
|
||||
];
|
||||
}
|
56
src/Main.elm
Normal file
56
src/Main.elm
Normal file
@ -0,0 +1,56 @@
|
||||
module Main exposing (..)
|
||||
|
||||
import Browser
|
||||
import Html exposing (Html, button, div, text)
|
||||
import Html.Events exposing (onClick)
|
||||
import Track exposing (Track)
|
||||
|
||||
-- MAIN
|
||||
|
||||
|
||||
main =
|
||||
Browser.sandbox { init = init, update = update, view = view }
|
||||
|
||||
|
||||
|
||||
-- MODEL
|
||||
|
||||
|
||||
type alias Model = Track
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
Track.read "hello"
|
||||
|
||||
|
||||
|
||||
-- UPDATE
|
||||
|
||||
|
||||
type Msg
|
||||
= Increment
|
||||
| Decrement
|
||||
|
||||
|
||||
update : Msg -> Model -> Model
|
||||
update msg model =
|
||||
case msg of
|
||||
Increment ->
|
||||
model
|
||||
|
||||
Decrement ->
|
||||
model
|
||||
|
||||
|
||||
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ button [ onClick Decrement ] [ text "-" ]
|
||||
, div [] [ text (String.fromInt (List.length model)) ]
|
||||
, button [ onClick Increment ] [ text "+" ]
|
||||
]
|
22
src/Track.elm
Normal file
22
src/Track.elm
Normal file
@ -0,0 +1,22 @@
|
||||
module Track exposing (Track, parse)
|
||||
|
||||
import Result
|
||||
import Xml.Decode as XD exposing (path, single, list, float)
|
||||
|
||||
|
||||
type alias Point =
|
||||
{ lat : Float
|
||||
, lon : Float
|
||||
}
|
||||
|
||||
type alias Track = List Point
|
||||
|
||||
pointDecoder = XD.map2 Point
|
||||
(XD.path ["ele"] (single float))
|
||||
(XD.path ["ele"] (single float))
|
||||
|
||||
gpxDecoder =
|
||||
(XD.path [ "trk", "trkseg", "trkpt" ] (XD.list pointDecoder))
|
||||
|
||||
|
||||
parse str = XD.run gpxDecoder str
|
60
tests/Fixtures.elm
Normal file
60
tests/Fixtures.elm
Normal file
@ -0,0 +1,60 @@
|
||||
module Fixtures exposing (threepoints)
|
||||
|
||||
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>
|
||||
<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>
|
||||
"""
|
19
tests/TrackTest.elm
Normal file
19
tests/TrackTest.elm
Normal file
@ -0,0 +1,19 @@
|
||||
module TrackTest exposing (specs)
|
||||
import Fixtures
|
||||
|
||||
import Track exposing (Track)
|
||||
import Test exposing (..)
|
||||
import Expect exposing (Expectation)
|
||||
|
||||
specs: Test
|
||||
specs =
|
||||
describe "XML Parsing"
|
||||
[ test "it runs" <|
|
||||
\_ ->
|
||||
let
|
||||
r = Track.parse Fixtures.threepoints
|
||||
in
|
||||
case r of
|
||||
(Ok trk) -> Expect.equal (List.length trk) 3
|
||||
_ -> Expect.fail "not ok"
|
||||
]
|
Loading…
Reference in New Issue
Block a user