commit 85c040023dead7209b3aef6d9c5c585ae7f576c0
parent b8fee7b0e3e7871afa8bb405e63a2f1c8daa3131
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 12 Nov 2024 18:52:44 +0000
fe: extract Point into a module
Diffstat:
2 files changed, 35 insertions(+), 34 deletions(-)
diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm
@@ -9,6 +9,7 @@ import Html.Events.Extra.Pointer as Pointer
import Maybe exposing (Maybe)
import Json.Decode as D
import Http
+import Point exposing(Point, Pos ,decoder)
import Svg exposing (Svg, svg, rect, circle, g, polyline)
import Svg.Attributes as S exposing
( viewBox
@@ -153,42 +154,9 @@ fetchTrack start duration = Http.get
String.fromInt start ++
"&duration=" ++
String.fromInt duration)
- , expect = Http.expectJson Loaded trackDecoder
+ , expect = Http.expectJson Loaded (D.list Point.decoder)
}
-type alias Pos =
- { lat : Float
- , lon : Float
- , ele : Maybe Float
- }
-
-
-type alias Point =
- { time : Float
- , pos : Pos
- , cadence : Maybe Int
- , power : Maybe Int
- , heartRate : Maybe Int
- }
-
-posDecoder : D.Decoder Pos
-posDecoder = D.map3 Pos
- (D.field "lat" D.float)
- (D.field "lon" D.float)
- (D.field "ele" (D.maybe D.float))
-
-
-pointDecoder : D.Decoder Point
-pointDecoder = D.map5 Point
- (D.field "time" D.float)
- (D.field "pos" posDecoder)
- (D.field "cadence" (D.maybe D.int))
- (D.field "power" (D.maybe D.int))
- (D.field "heartRate" (D.maybe D.int))
-
-trackDecoder : D.Decoder (List Point)
-trackDecoder = D.list pointDecoder
-
-- UPDATE
diff --git a/frontend/src/Point.elm b/frontend/src/Point.elm
@@ -0,0 +1,33 @@
+module Point exposing(Pos, Point, decoder)
+
+import Json.Decode as D
+
+type alias Pos =
+ { lat : Float
+ , lon : Float
+ , ele : Maybe Float
+ }
+
+
+type alias Point =
+ { time : Float
+ , pos : Pos
+ , cadence : Maybe Int
+ , power : Maybe Int
+ , heartRate : Maybe Int
+ }
+
+posDecoder : D.Decoder Pos
+posDecoder = D.map3 Pos
+ (D.field "lat" D.float)
+ (D.field "lon" D.float)
+ (D.field "ele" (D.maybe D.float))
+
+
+decoder : D.Decoder Point
+decoder = D.map5 Point
+ (D.field "time" D.float)
+ (D.field "pos" posDecoder)
+ (D.field "cadence" (D.maybe D.int))
+ (D.field "power" (D.maybe D.int))
+ (D.field "heartRate" (D.maybe D.int))