aboutsummaryrefslogtreecommitdiff
path: root/src/Views.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Views.elm')
-rw-r--r--src/Views.elm71
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 @@
1module Views exposing (viewAccuracy, viewProgress, viewWpm)
2
3import Array exposing (..)
4import Base exposing (..)
5import Time exposing (Posix, toHour, toMinute, toSecond, utc)
6import Utils exposing (diffDuration, wordCountWith)
7
8
9viewTime : Posix -> String
10viewTime 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
24viewWpm : Model -> String
25viewWpm 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
45viewProgress : Int -> Int -> String
46viewProgress soFar total =
47 String.fromInt soFar ++ "/" ++ String.fromInt total
48
49
50viewAccuracy : Array Word -> String
51viewAccuracy 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