diff options
Diffstat (limited to 'src/Views.elm')
-rw-r--r-- | src/Views.elm | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/Views.elm b/src/Views.elm new file mode 100644 index 0000000..c5cc159 --- /dev/null +++ b/src/Views.elm | |||
@@ -0,0 +1,71 @@ | |||
1 | module Views exposing (viewAccuracy, viewProgress, viewWpm) | ||
2 | |||
3 | import Array exposing (..) | ||
4 | import Base exposing (..) | ||
5 | import Time exposing (Posix, toHour, toMinute, toSecond, utc) | ||
6 | import Utils exposing (diffDuration, wordCountWith) | ||
7 | |||
8 | |||
9 | viewTime : Posix -> String | ||
10 | viewTime t = | ||
11 | let | ||
12 | hh = | ||
13 | toHour utc t | ||
14 | |||
15 | mm = | ||
16 | toMinute utc t | ||
17 | |||
18 | ss = | ||
19 | toSecond utc t | ||
20 | in | ||
21 | String.join ":" (List.map String.fromInt [ hh, mm, ss ]) | ||
22 | |||
23 | |||
24 | viewWpm : Model -> String | ||
25 | viewWpm model = | ||
26 | let | ||
27 | t1 = | ||
28 | model.begin | ||
29 | |||
30 | t2 = | ||
31 | model.end | ||
32 | |||
33 | duration = | ||
34 | Maybe.map2 diffDuration t1 t2 | ||
35 | |||
36 | correctWords = | ||
37 | wordCountWith model.words ((==) Correct) | ||
38 | |||
39 | wpm = | ||
40 | Maybe.map (String.fromInt << truncate << (*) 60 << (/) (toFloat correctWords)) duration | ||
41 | in | ||
42 | Maybe.withDefault "XX" wpm | ||
43 | |||
44 | |||
45 | viewProgress : Int -> Int -> String | ||
46 | viewProgress soFar total = | ||
47 | String.fromInt soFar ++ "/" ++ String.fromInt total | ||
48 | |||
49 | |||
50 | viewAccuracy : Array Word -> String | ||
51 | viewAccuracy words = | ||
52 | let | ||
53 | wordsAttempted = | ||
54 | toFloat <| wordCountWith words ((/=) Todo) | ||
55 | |||
56 | correctCount = | ||
57 | toFloat <| wordCountWith words ((==) Correct) | ||
58 | |||
59 | accuracy = | ||
60 | if wordsAttempted == 0.0 then | ||
61 | Nothing | ||
62 | |||
63 | else | ||
64 | Just <| correctCount / wordsAttempted * 100 | ||
65 | in | ||
66 | case accuracy of | ||
67 | Nothing -> | ||
68 | "XX" | ||
69 | |||
70 | Just a -> | ||
71 | String.fromInt <| truncate a | ||