File size: 8,085 Bytes
c473c85
 
 
 
 
dfa545b
 
 
 
 
 
 
c473c85
 
 
 
 
 
 
 
 
 
dfa545b
61f6c42
 
 
 
 
dfa545b
 
61f6c42
 
 
 
 
 
 
 
 
 
 
 
dfa545b
 
c473c85
dfa545b
 
 
c473c85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
from dash import html, dcc
from typing import Dict

import plotly.express as px
import numpy as np
import dash_bootstrap_components as dbc

NAVBAR_MIN_HEIGHT = "4rem"

def get_navbar() -> dbc.Nav:
    return dbc.Nav(
        children = [
            html.A(
                dbc.Row(
                    [
                        dbc.Col(html.Img(src = "/assets/mosquito-white.png", height = "30px")),
                    ],
                    align = "center",
                    className = "g-0 px-2",
                ),
                style = {"textDecoration": "none"},
            ),
            dbc.NavItem(
                children = dbc.NavLink(
                    children = "Home",
                    href = "/",
                    class_name = "text-light"
                )
            ),
            dbc.NavItem(
                children = dbc.NavLink(
                    children = "Usage Guide",
                    href = "/guide",
                    class_name = "text-light"
                )
            ),
            dbc.NavItem(
                children = dbc.NavLink(
                    children = "About",
                    href = "/about",
                    class_name = "text-light"
                )
            )
        ],
        className = "bg-dark d-flex flex-row justify-content-start align-items-center",
        style = {
            "min-height": NAVBAR_MIN_HEIGHT
        }
    )

def display_slider_value(name: str, value: int | float) -> str:
    return f"{name}: {value}"

def get_cc_ui() -> dbc.Container:
    return dbc.Container(
        children = [
            html.H5(
                children = "Color Threshold (0 - 255)",
                className = "text-start my-3"
            ),
            dcc.Slider(
                min = 0,
                max = 255,
                value = 75,
                id = "select-cc-color-thresh",
                className = "my-1"
            ),
            html.P(
                children = display_slider_value("Color Threshold", 75),
                id = "display-cc-color-thresh"
            ),
            html.H5(
                children = "Average Area",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 800,
                type = "number",
                id = "select-cc-avg-area",
                className = "w-50"
            ),
            html.H5(
                children = "Max Eggs (optional)",
                className = "text-start my-3 mt-3"
            ),
            dcc.Input(
                type = "number",
                id = "select-cc-max-eggs",
                className = "w-50"
            ),
            dbc.Button(
                children = "Count",
                color = "primary",
                className = "w-25 mt-4",
                id = "count-cc"
            )
        ],
        className = "p-3 m-0 border border-dark d-flex flex-column justify-content-center align-items-left"
    )

def get_cc_filter_ui() -> dbc.Container:
    return dbc.Container(
        children = [
            html.H5(
                children = "Color Threshold (0 - 255)",
                className = "text-start my-3"
            ),
            dcc.Slider(
                min = 0,
                max = 255,
                value = 75,
                id = "select-cc-filter-color-thresh",
                className = "my-1"
            ),
            html.P(
                children = display_slider_value("Color Threshold", 75),
                id = "display-cc-filter-color-thresh"
            ),
            html.H5(
                children = "Average Area",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 800,
                type = "number",
                id = "select-cc-filter-avg-area",
                className = "w-50"
            ),
            html.H5(
                children = "Max Eggs (optional)",
                className = "text-start my-3 mt-3"
            ),
            dcc.Input(
                type = "number",
                id = "select-cc-filter-max-eggs",
                className = "w-50"
            ),
            html.H5(
                children = "Kernel Width",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 3,
                type = "number",
                id = "select-cc-kernel-width",
                className = "w-50"
            ),
            html.H5(
                children = "Kernel Height",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 3,
                type = "number",
                id = "select-cc-kernel-height",
                className = "w-50"
            ),
            dbc.Button(
                children = "Count",
                color = "primary",
                className = "w-25 mt-4",
                id = "count-cc-filter"
            )
        ],
        className = "p-3 m-0 border border-dark d-flex flex-column justify-content-center align-items-left"
    )

def get_contour_ui() -> dbc.Container:
    return dbc.Container(
        children = [
            html.H5(
                children = "Color Threshold (0 - 255)",
                className = "text-start my-3"
            ),
            dcc.Slider(
                min = 0,
                max = 255,
                value = 75,
                id = "select-contour-color-thresh",
                className = "my-1"
            ),
            html.P(
                children = display_slider_value("Color Threshold", 75),
                id = "display-contour-color-thresh"
            ),
            html.H5(
                children = "Average Area",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 800,
                type = "number",
                id = "select-contour-avg-area",
                className = "w-50"
            ),
            html.H5(
                children = "Max Eggs (optional)",
                className = "text-start my-3 mt-3"
            ),
            dcc.Input(
                type = "number",
                id = "select-contour-max-eggs",
                className = "w-50"
            ),
            html.H5(
                children = "Kernel Width",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 3,
                type = "number",
                id = "select-contour-width",
                className = "w-50"
            ),
            html.H5(
                children = "Kernel Height",
                className = "text-start my-3"
            ),
            dcc.Input(
                value = 3,
                type = "number",
                id = "select-contour-height",
                className = "w-50"
            ),
            dbc.Button(
                children = "Count",
                color = "primary",
                className = "w-25 mt-4",
                id = "count-contour"
            )
        ],
        className = "p-3 m-0 border border-dark d-flex flex-column justify-content-center align-items-left"
    )

def get_results_container(result: Dict) -> dbc.Container:
    children = list()

    for stat_name, stat in result["stats"].items():
        children.append(
            html.H5(
                children = f"{stat_name.replace('-', ' ')}: {stat}",
                className = "text-start w-100"
            ),
        )

    children.append(html.Hr(className = "border border-dark"))

    for vis_name, vis_pic in result["vis"].items():
        children.append(html.H4(vis_name.replace("-", " ")))
        image_fig = px.imshow(vis_pic)
        children.append(
            dcc.Graph(
                figure = image_fig,
                className = "w-100"
            )
        )

    return dbc.Container(
        children = children,
        className = "p-3 m-0 border border-dark d-flex flex-column justify-content-center align-items-center"
    )