<commit_before>port module Main exposing (main)

import Html exposing (Html, h1, div, dl, dt, dd, text)
import Html.Attributes exposing (class)


main : Program Never Model Msg
main =
    Html.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }



-- MODEL


type alias Model =
    Payload


type alias Payload =
    { humidity : Int
    , temperature : Int
    , heatIndex : Float
    }


init : ( Model, Cmd Msg )
init =
    ( Payload 0 0 0.0, Cmd.none )



-- UPDATE


type Msg
    = OnMessage Payload


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        OnMessage payload ->
            ( payload, Cmd.none )



-- SUBSCRIPTIONS


port onMessage : (Payload -> msg) -> Sub msg


subscriptions : Model -> Sub Msg
subscriptions model =
    onMessage OnMessage



-- VIEW


view : Model -> Html Msg
view model =
    let
        humidityClass =
            if (40 <= model.humidity) && (model.humidity <= 55) then
                "ok"
            else
                "bad"
    in
        div []
            [ h1 [] [ text "Elm and MQTT" ]
            , dl []
                [ dt [ class humidityClass ] [ text "humidity" ]
                , dd [ class humidityClass ]
                    [ text (toString model.humidity)
                    , text "%"
                    ]
                , dt [] [ text "temperature" ]
                , dd []
                    [ text (toString model.temperature)
                    , text "°C"
                    ]
                , dt [] [ text "heatIndex" ]
                , dd []
                    [ text (toString model.heatIndex)
                    , text "°C"
                    ]
                ]
            ]<commit_msg>payload has Maybe values<commit_after>port module Main exposing (main)

import Html exposing (Html, h1, div, dl, dt, dd, text)
import Html.Attributes exposing (class)


main : Program Never Model Msg
main =
    Html.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }



-- MODEL


loading =
    "loading"


type alias Model =
    Payload


type alias Payload =
    { humidity : Maybe Int
    , temperature : Maybe Int
    , heatIndex : Maybe Float
    }


init : ( Model, Cmd Msg )
init =
    ( Payload Nothing Nothing Nothing, Cmd.none )



-- UPDATE


type Msg
    = OnMessage Payload


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        OnMessage payload ->
            ( payload, Cmd.none )



-- SUBSCRIPTIONS


port onMessage : (Payload -> msg) -> Sub msg


subscriptions : Model -> Sub Msg
subscriptions model =
    onMessage OnMessage



-- VIEW


view : Model -> Html Msg
view model =
    let
        ( humidityClass, humidity ) =
            case model.humidity of
                Just humidity ->
                    ( if (40 <= humidity) && (humidity <= 55) then
                        "ok"
                      else
                        "bad"
                    , (toString humidity) ++ "%"
                    )

                Nothing ->
                    ( "loading", loading )

        temperature =
            case model.temperature of
                Just temperature ->
                    (toString temperature) ++ "°C"

                Nothing ->
                    loading

        heatIndex =
            case model.heatIndex of
                Just heatIndex ->
                    (toString heatIndex) ++ "°C"

                Nothing ->
                    loading
    in
        div []
            [ h1 [] [ text "Elm and MQTT" ]
            , dl []
                [ dt [ class humidityClass ] [ text "humidity" ]
                , dd [ class humidityClass ]
                    [ text humidity ]
                , dt [] [ text "temperature" ]
                , dd []
                    [ text temperature ]
                , dt [] [ text "heatIndex" ]
                , dd []
                    [ text heatIndex ]
                ]
            ]
{'fraction_non_alphanumeric': 0.09195402298850575, 'fraction_numerical': 0.003912937148447053, 'mean_word_length': 1.1801705756929637, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1010382', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1049, 'n_words': 333}