diff options
Diffstat (limited to 'src/Views.elm')
-rw-r--r-- | src/Views.elm | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/src/Views.elm b/src/Views.elm index b56a945..b54fc93 100644 --- a/src/Views.elm +++ b/src/Views.elm | |||
@@ -5,10 +5,11 @@ import Base exposing (..) | |||
5 | import Css exposing (..) | 5 | import Css exposing (..) |
6 | import Html | 6 | import Html |
7 | import Html.Styled exposing (..) | 7 | import Html.Styled exposing (..) |
8 | import Html.Styled.Attributes exposing (css) | ||
8 | import Html.Styled.Events exposing (onClick) | 9 | import Html.Styled.Events exposing (onClick) |
9 | import Styles exposing (styledListItem, styledUnorderedList) | 10 | import Styles exposing (styledButton, styledListItem, styledUnorderedList) |
10 | import Time exposing (Posix, toHour, toMinute, toSecond, utc) | 11 | import Time exposing (Posix, toHour, toMinute, toSecond, utc) |
11 | import Utils exposing (diffDuration, wordCountWith) | 12 | import Utils exposing (diffDuration, isNothing, wordCountWith) |
12 | 13 | ||
13 | 14 | ||
14 | viewTime : Posix -> String | 15 | viewTime : Posix -> String |
@@ -26,7 +27,7 @@ viewTime t = | |||
26 | String.join ":" (List.map String.fromInt [ hh, mm, ss ]) | 27 | String.join ":" (List.map String.fromInt [ hh, mm, ss ]) |
27 | 28 | ||
28 | 29 | ||
29 | viewWpm : Model -> String | 30 | viewWpm : Model -> Maybe String |
30 | viewWpm model = | 31 | viewWpm model = |
31 | let | 32 | let |
32 | t1 = | 33 | t1 = |
@@ -40,11 +41,8 @@ viewWpm model = | |||
40 | 41 | ||
41 | correctWords = | 42 | correctWords = |
42 | wordCountWith model.words ((==) Correct) | 43 | wordCountWith model.words ((==) Correct) |
43 | |||
44 | wpm = | ||
45 | Maybe.map (String.fromInt << truncate << (*) 60 << (/) (toFloat correctWords)) duration | ||
46 | in | 44 | in |
47 | Maybe.withDefault "XX" wpm | 45 | Maybe.map (String.fromInt << truncate << (*) 60 << (/) (toFloat correctWords)) duration |
48 | 46 | ||
49 | 47 | ||
50 | viewProgress : Model -> String | 48 | viewProgress : Model -> String |
@@ -59,28 +57,30 @@ viewProgress model = | |||
59 | String.fromInt soFar ++ ":" ++ String.fromInt total | 57 | String.fromInt soFar ++ ":" ++ String.fromInt total |
60 | 58 | ||
61 | 59 | ||
62 | viewAccuracy : Array Word -> String | 60 | viewAccuracy : Model -> Maybe String |
63 | viewAccuracy words = | 61 | viewAccuracy model = |
64 | let | 62 | if isNothing model.end then |
65 | wordsAttempted = | 63 | Nothing |
66 | toFloat <| wordCountWith words ((/=) Todo) | ||
67 | 64 | ||
68 | correctCount = | 65 | else |
69 | toFloat <| wordCountWith words ((==) Correct) | 66 | let |
67 | words = | ||
68 | model.words | ||
70 | 69 | ||
71 | accuracy = | 70 | wordsAttempted = |
72 | if wordsAttempted == 0.0 then | 71 | toFloat <| wordCountWith words ((/=) Todo) |
73 | Nothing | ||
74 | 72 | ||
75 | else | 73 | correctCount = |
76 | Just <| correctCount / wordsAttempted * 100 | 74 | toFloat <| wordCountWith words ((==) Correct) |
77 | in | 75 | |
78 | case accuracy of | 76 | accuracy = |
79 | Nothing -> | 77 | if wordsAttempted == 0.0 then |
80 | "XX" | 78 | Nothing |
81 | 79 | ||
82 | Just a -> | 80 | else |
83 | String.fromInt <| truncate a | 81 | Just <| String.fromInt <| truncate <| correctCount / wordsAttempted * 100 |
82 | in | ||
83 | accuracy | ||
84 | 84 | ||
85 | 85 | ||
86 | viewWordLengthOptions : Html Msg | 86 | viewWordLengthOptions : Html Msg |
@@ -89,12 +89,20 @@ viewWordLengthOptions = | |||
89 | wl = | 89 | wl = |
90 | [ 10, 25, 50, 100 ] | 90 | [ 10, 25, 50, 100 ] |
91 | in | 91 | in |
92 | styledUnorderedList [] | 92 | ul |
93 | [ css | ||
94 | [ margin zero | ||
95 | , listStyle Css.none | ||
96 | , display inlineBlock | ||
97 | , paddingLeft (px 0) | ||
98 | ] | ||
99 | ] | ||
93 | (List.map | 100 | (List.map |
94 | (\len -> | 101 | (\len -> |
95 | styledListItem | 102 | li [ css [ display inline ] ] |
96 | [ onClick (Base.WordLengthChanged len) ] | 103 | [ styledButton [ onClick (Base.WordLengthChanged len) ] |
97 | [ text <| String.fromInt len ] | 104 | [ text <| String.fromInt len ] |
105 | ] | ||
98 | ) | 106 | ) |
99 | wl | 107 | wl |
100 | ) | 108 | ) |
@@ -102,8 +110,15 @@ viewWordLengthOptions = | |||
102 | 110 | ||
103 | viewStats : Model -> Html Msg | 111 | viewStats : Model -> Html Msg |
104 | viewStats model = | 112 | viewStats model = |
105 | styledUnorderedList [] | 113 | let |
106 | [ styledListItem [] [ text ("WPM " ++ viewWpm model) ] | 114 | wpm = |
107 | , styledListItem [] [ text ("ACC " ++ viewAccuracy model.words) ] | 115 | viewWpm model |
108 | , styledListItem [] [ text ("POS " ++ viewProgress model) ] | 116 | |
109 | ] | 117 | acc = |
118 | viewAccuracy model | ||
119 | |||
120 | stats = | ||
121 | Maybe.map2 (\w a -> w ++ " words per minute ยท " ++ a ++ "% accuracy") wpm acc | ||
122 | in | ||
123 | p [] | ||
124 | [ text (Maybe.withDefault "" stats) ] | ||