Skip to content

Commit

Permalink
use factored out sample in main
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrake committed Sep 5, 2019
1 parent 6f1c1c0 commit b476268
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 1 addition & 15 deletions frontend/src/Main.elm
Expand Up @@ -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

Expand All @@ -51,13 +52,6 @@ type alias Response =
}


type alias Sample =
{ id : String
, value : Float
, time : String
}


type alias Device =
{ id : String
, config : DeviceConfig
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion 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


Expand All @@ -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)

0 comments on commit b476268

Please sign in to comment.