-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
366 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module CurrentReads exposing (..) | ||
|
||
import Bootstrap.Grid as Grid | ||
import Bootstrap.Grid.Col as Col | ||
import Bootstrap.Grid.Row as Row | ||
import EpaCommon exposing (EpaLevel, getColorForLevel) | ||
import Html exposing (Attribute, Html, a, div, h1, h5, img, text) | ||
import Html.Attributes exposing (alt, class, href, src, style) | ||
import Maybe | ||
import Time exposing (..) | ||
|
||
|
||
{-| Model for device info widget | ||
-} | ||
type alias CurrentReads = | ||
{ epaLevel : Maybe EpaLevel | ||
, lastEpaRead : Maybe Float | ||
, lastPm10 : Maybe Float | ||
, lastPm25 : Maybe Float | ||
} | ||
|
||
|
||
{-| HTML widget for displaying the device status. | ||
Includes general status, time to next read, and exception info if applicable. | ||
-} | ||
getCurrentReads : CurrentReads -> Html msg | ||
getCurrentReads currentReads = | ||
Grid.container [ style "padding" "1em" ] | ||
[ Grid.row [ Row.attrs [ class "align-items-center" ] ] | ||
[ Grid.col [ Col.attrs [ style "text-align" "center", style "padding" "2em" ] ] | ||
[ h1 | ||
[ style "color" (Maybe.map getColorForLevel currentReads.epaLevel |> Maybe.withDefault "black") | ||
] | ||
[ text (Maybe.map String.fromFloat currentReads.lastEpaRead |> Maybe.withDefault "NA") ] | ||
] | ||
] | ||
, Grid.row [ Row.attrs [ class "align-items-center" ] ] | ||
[ Grid.col [ Col.attrs [ style "text-align" "center", style "padding-bottom" "2em" ] ] [ a [ href "https://www.airnow.gov/aqi/aqi-basics/" ] [ text "EPA AQI Score" ] ] ] | ||
, Grid.row [ Row.attrs [ class "align-items-center" ] ] | ||
[ Grid.col [ Col.attrs [ style "text-align" "right" ] ] [ text "Last PM10:" ] | ||
, Grid.col [ Col.attrs [ style "text-align" "center", style "font-weight" "bold" ] ] [ text (Maybe.map String.fromFloat currentReads.lastPm10 |> Maybe.withDefault "NA") ] | ||
] | ||
, Grid.row [ Row.attrs [ class "align-items-center" ] ] | ||
[ Grid.col [ Col.attrs [ style "text-align" "right" ] ] [ text "Last PM25:" ] | ||
, Grid.col [ Col.attrs [ style "text-align" "center", style "font-weight" "bold" ] ] [ text (Maybe.map String.fromFloat currentReads.lastPm25 |> Maybe.withDefault "NA") ] | ||
] | ||
] | ||
|
||
|
||
{-| Conditionally display some block of HTML | ||
-} | ||
htmlIf : Html msg -> Bool -> Html msg | ||
htmlIf el cond = | ||
if cond then | ||
el | ||
|
||
else | ||
text "" | ||
|
||
|
||
{-| Format a unix timestamp as a string like MM/DD HH:MM:SS | ||
-} | ||
formatDuration : Posix -> Posix -> String | ||
formatDuration currentTime scheduledTime = | ||
let | ||
durationMillis = | ||
posixToMillis scheduledTime - posixToMillis currentTime | ||
|
||
hour = | ||
durationMillis // 1000 // 60 // 60 | ||
|
||
minute = | ||
modBy 60 (durationMillis // 1000 // 60) | ||
|
||
second = | ||
modBy 60 (durationMillis // 1000) | ||
in | ||
if durationMillis > 0 then | ||
String.padLeft 2 '0' (String.fromInt hour) ++ ":" ++ String.padLeft 2 '0' (String.fromInt minute) ++ ":" ++ String.padLeft 2 '0' (String.fromInt second) | ||
|
||
else | ||
"00:00:00" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module EpaCommon exposing (..) | ||
|
||
|
||
type EpaLevel | ||
= Hazardous | ||
| VeryUnhealthy | ||
| Unhealthy | ||
| UnhealthyForSensitive | ||
| Moderate | ||
| Good | ||
|
||
|
||
getColorForLevel : EpaLevel -> String | ||
getColorForLevel level = | ||
case level of | ||
Hazardous -> | ||
"maroon" | ||
|
||
VeryUnhealthy -> | ||
"purple" | ||
|
||
Unhealthy -> | ||
"red" | ||
|
||
UnhealthyForSensitive -> | ||
"orange" | ||
|
||
Moderate -> | ||
"yellow" | ||
|
||
Good -> | ||
"green" | ||
|
||
|
||
getLabelForLevel : EpaLevel -> String | ||
getLabelForLevel level = | ||
case level of | ||
Hazardous -> | ||
"Hazardous" | ||
|
||
VeryUnhealthy -> | ||
"Very Unhealthy" | ||
|
||
Unhealthy -> | ||
"Unhealthy" | ||
|
||
UnhealthyForSensitive -> | ||
"Unhealthy For Sensitive" | ||
|
||
Moderate -> | ||
"Moderate" | ||
|
||
Good -> | ||
"Good" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module EpaLevel exposing (..) | ||
|
||
import Bootstrap.Grid as Grid | ||
import Bootstrap.Grid.Col as Col | ||
import Bootstrap.Grid.Row as Row | ||
import EpaCommon exposing (..) | ||
import Html exposing (Attribute, Html, a, div, h1, h5, img, text) | ||
import Html.Attributes exposing (alt, class, href, src, style) | ||
|
||
|
||
{-| HTML widget for displaying the device status. | ||
Includes general status, time to next read, and exception info if applicable. | ||
-} | ||
getEpaLevel : Maybe EpaLevel -> Html msg | ||
getEpaLevel currentLevel = | ||
Grid.container [ class "align-middle", style "padding" "1em" ] | ||
[ getRow Hazardous (currentLevel == Just Hazardous) | ||
, getRow VeryUnhealthy (currentLevel == Just VeryUnhealthy) | ||
, getRow Unhealthy (currentLevel == Just Unhealthy) | ||
, getRow UnhealthyForSensitive (currentLevel == Just UnhealthyForSensitive) | ||
, getRow Moderate (currentLevel == Just Moderate) | ||
, getRow Good (currentLevel == Just Good) | ||
] | ||
|
||
|
||
getRow : EpaLevel -> Bool -> Html msg | ||
getRow level isSelected = | ||
Grid.row [ Row.attrs (List.append [ style "background-color" (getColorForLevel level) ] (selectedStyles isSelected)) ] | ||
[ Grid.col [ Col.attrs [ style "text-align" "center", style "padding" ".25em", style "color" "white" ] ] [ text (getLabelForLevel level) ] ] | ||
|
||
|
||
selectedStyles : Bool -> List (Attribute msg) | ||
selectedStyles isSelected = | ||
if isSelected then | ||
[ style "border-radius" "1em" ] | ||
|
||
else | ||
[ style "margin" "0 0.25em 0 0.25em" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.