fe: extract Point into a module
This commit is contained in:
parent
b8fee7b0e3
commit
85c040023d
@ -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
|
||||
|
33
frontend/src/Point.elm
Normal file
33
frontend/src/Point.elm
Normal file
@ -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))
|
Loading…
Reference in New Issue
Block a user