From b476268e6d2890f6caad045f31d8123b598475a1 Mon Sep 17 00:00:00 2001 From: Cliff Brake Date: Thu, 5 Sep 2019 12:34:37 -0400 Subject: [PATCH] use factored out sample in main --- frontend/src/Main.elm | 16 +--------------- frontend/src/Sample.elm | 11 ++++++++++- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index 013144c9..d3f4d2a2 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -28,6 +28,7 @@ import Json.Encode as Encode import List.Extra as ListExtra import Material.Icons.Image exposing (edit) import Round +import Sample exposing (Sample, encodeSample, sampleDecoder) import Time import Url.Builder as Url @@ -51,13 +52,6 @@ type alias Response = } -type alias Sample = - { id : String - , value : Float - , time : String - } - - type alias Device = { id : String , config : DeviceConfig @@ -157,14 +151,6 @@ responseDecoder = |> optional "error" Decode.string "" -sampleDecoder : Decode.Decoder Sample -sampleDecoder = - Decode.map3 Sample - (Decode.field "id" Decode.string) - (Decode.field "value" Decode.float) - (Decode.field "time" Decode.string) - - samplesDecoder : Decode.Decoder (List Sample) samplesDecoder = Decode.list sampleDecoder diff --git a/frontend/src/Sample.elm b/frontend/src/Sample.elm index 2ce8d888..c1eec67d 100644 --- a/frontend/src/Sample.elm +++ b/frontend/src/Sample.elm @@ -1,5 +1,6 @@ -module Sample exposing (Sample, encodeSample) +module Sample exposing (Sample, encodeSample, sampleDecoder) +import Json.Decode as Decode import Json.Encode @@ -17,3 +18,11 @@ encodeSample s = , ( "id", Json.Encode.string <| s.id ) , ( "value", Json.Encode.float <| s.value ) ] + + +sampleDecoder : Decode.Decoder Sample +sampleDecoder = + Decode.map3 Sample + (Decode.field "type" Decode.string) + (Decode.field "id" Decode.string) + (Decode.field "value" Decode.float)