1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
module AdvSearch.Range exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Lib.Html exposing (..)
import Lib.Util exposing (..)
import Array
import Lib.Ffi as Ffi
import Gen.Types as GT
import AdvSearch.Query exposing (..)
type alias Model a =
{ op : Op
, val : Int
, lst : Array.Array a
}
type Msg
= MOp Op Bool
| Val String
update : Msg -> Model a -> Model a
update msg model =
case msg of
MOp o _ -> { model | op = o }
Val n -> { model | val = Maybe.withDefault 0 (String.toInt n) }
fromQuery : (Data, Model comparable) -> Op -> comparable -> Maybe (Data, Model comparable)
fromQuery (dat,m) op v = Array.foldl (\v2 (i,r) -> (i+1, if v2 == v then Just i else r)) (0,Nothing) m.lst |> Tuple.second |> Maybe.map (\i -> (dat,{ m | val = i, op = op }))
toQuery : (Op -> a -> Query) -> Model a -> Maybe Query
toQuery f m = Array.get m.val m.lst |> Maybe.map (\v -> f m.op v)
view : String -> (a -> String) -> Model a -> (Html Msg, () -> List (Html Msg))
view lbl fmt model =
let val n = Array.get n model.lst |> Maybe.map fmt |> Maybe.withDefault ""
in
( text <| lbl ++ " " ++ showOp model.op ++ " " ++ val model.val
, \() ->
[ div [ class "advheader", style "width" "290px" ]
[ h3 [] [ text lbl ]
, div [ class "opts" ]
[ div [ class "opselect" ] <|
List.map (\op ->
if model.op == op then b [] [ text (showOp op) ] else a [ href "#", onClickD (MOp op True) ] [ text (showOp op) ]
) [Eq, Ne, Ge, Gt, Le, Lt]
]
]
, div [ style "display" "flex", style "justify-content" "space-between", style "margin-top" "5px" ]
[ b [ class "grayedout" ] [ text (val 0) ]
, b [] [ text (val model.val) ]
, b [ class "grayedout" ] [ text (val (Array.length model.lst - 1)) ]
]
, input
[ type_ "range"
, Html.Attributes.min "0"
, Html.Attributes.max (String.fromInt (Array.length model.lst - 1))
, value (String.fromInt model.val)
, onInput Val
, style "width" "290px"
] []
]
)
heightInit dat = (dat, { op = Ge, val = 150, lst = Array.initialize 300 (\n -> n+1) })
heightFromQuery d q =
case q of
QInt 6 op v -> fromQuery (heightInit d) op v
_ -> Nothing
heightView = view "Height" (\v -> String.fromInt v ++ "cm")
weightInit dat = (dat, { op= Ge, val = 60, lst = Array.initialize 401 identity })
weightFromQuery d q =
case q of
QInt 7 op v -> fromQuery (weightInit d) op v
_ -> Nothing
weightView = view "Weight" (\v -> String.fromInt v ++ "kg")
bustInit dat = (dat, { op = Ge, val = 40, lst = Array.initialize 101 (\n -> n+20) })
bustFromQuery d q =
case q of
QInt 8 op v -> fromQuery (bustInit d) op v
_ -> Nothing
bustView = view "Bust" (\v -> String.fromInt v ++ "cm")
waistInit dat = (dat, { op = Ge, val = 40, lst = Array.initialize 101 (\n -> n+20) })
waistFromQuery d q =
case q of
QInt 9 op v -> fromQuery (waistInit d) op v
_ -> Nothing
waistView = view "Waist" (\v -> String.fromInt v ++ "cm")
hipsInit dat = (dat, { op = Ge, val = 40, lst = Array.initialize 101 (\n -> n+20) })
hipsFromQuery d q =
case q of
QInt 10 op v -> fromQuery (hipsInit d) op v
_ -> Nothing
hipsView = view "Hips" (\v -> String.fromInt v ++ "cm")
cupInit dat = (dat, { op = Ge, val = 3, lst = Array.fromList (List.map Tuple.first (List.drop 1 GT.cupSizes)) })
cupFromQuery d q =
case q of
QStr 11 op v -> fromQuery (cupInit d) op v
_ -> Nothing
cupView = view "Cup size" identity
ageInit dat = (dat, { op = Ge, val = 17, lst = Array.initialize 120 (\n -> n+1) })
ageFromQuery d q =
case q of
QInt 12 op v -> fromQuery (ageInit d) op v
_ -> Nothing
ageView = view "Age" (\v -> if v == 1 then "1 year" else String.fromInt v ++ " years")
popularityInit dat = (dat, { op = Ge, val = 10, lst = Array.initialize 101 identity })
popularityFromQuery d q =
case q of
QInt 9 op v -> fromQuery (popularityInit d) op v
_ -> Nothing
popularityView = view "Popularity" String.fromInt
ratingInit dat = (dat, { op = Ge, val = 40, lst = Array.initialize 91 (\v -> v+10) })
ratingFromQuery d q =
case q of
QInt 10 op v -> fromQuery (ratingInit d) op v
_ -> Nothing
ratingView = view "Rating" (\v -> Ffi.fmtFloat (toFloat v / 10) 1)
votecountInit dat = (dat, { op = Ge, val = 10, lst = Array.fromList [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000 ] })
votecountFromQuery d q =
case q of
QInt 11 op v -> fromQuery (votecountInit d) op v
_ -> Nothing
votecountView = view "# Votes" String.fromInt
|