@@ -4,6 +4,23 @@ const margin = {top: 10, right: 10, bottom: 10, left: 10};
4
4
var app = null ;
5
5
var currentClass = 0 ;
6
6
7
+ // Displays a danger alert message in the top of the screen.
8
+ function alertMessage ( message ) {
9
+ var alert = $ ( '<div class="alert alert-danger alert-dismissible fade show mb-0 mt-0" role="alert">' ) ;
10
+ var btnClose = $ ( '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' ) ;
11
+ var x = $ . parseHTML ( '<span aria-hidden="true">×</span>' ) ;
12
+
13
+ alert . text ( message ) ;
14
+ btnClose . append ( x ) ;
15
+ alert . append ( btnClose ) ;
16
+
17
+ $ ( "#alerts" ) . append ( alert ) ;
18
+
19
+ setTimeout ( function ( ) {
20
+ alert . alert ( 'close' ) ;
21
+ alert . alert ( 'dispose' ) ;
22
+ } , 2000 ) ;
23
+ }
7
24
8
25
class Dataspace {
9
26
constructor ( selector ) {
@@ -65,11 +82,15 @@ class Dataspace {
65
82
} ) . then ( json => {
66
83
this . dataset = json ;
67
84
this . draw ( ) ;
85
+ } ) . catch ( error => {
86
+ console . log ( error ) ;
87
+ alertMessage ( "Server could not generate dataset!" ) ;
68
88
} ) ;
69
89
}
70
90
71
91
// Fit the model specified in the data fields to the data in the plot
72
92
fit ( model ) {
93
+ $ ( "#metrics" ) . removeClass ( "visible" ) . addClass ( "invisible" ) ;
73
94
if ( this . dataset . length == 0 ) {
74
95
console . log ( "cannot fit model to no data!" ) ;
75
96
return
@@ -89,6 +110,8 @@ class Dataspace {
89
110
} ) . then ( json => {
90
111
$ ( "#f1score" ) . text ( json . metrics . f1 ) ;
91
112
$ ( "#metrics" ) . removeClass ( "invisible" ) . addClass ( "visible" ) ;
113
+ } ) . catch ( error => {
114
+ alertMessage ( "Could not fit model, check JSON hyperparams and try again!" ) ;
92
115
} ) ;
93
116
}
94
117
@@ -137,17 +160,24 @@ $(document).ready(function() {
137
160
return false ;
138
161
} )
139
162
140
- // Change the model hyperparameter tabs on select
163
+ // Change the model hyperparameter tabs on select and set the current model family.
141
164
$ ( "select#modelSelect" ) . change ( function ( e ) {
142
165
e . preventDefault ( ) ;
166
+ // Deactivate current model control form tab
143
167
$ ( '#modelTabs [class*="active"]' ) . removeClass ( "show active" ) ;
144
168
169
+ // Activate the selected model control form tab
145
170
var model = $ ( e . target ) . val ( ) ;
146
171
$ ( "#" + model ) . addClass ( "show active" ) ;
172
+
173
+ // Ensure that the info button points to the currect model
174
+ $ ( "#infoBtn" ) . attr ( "data-target" , "#" + model + "InfoModal" ) ;
175
+
147
176
return false ;
148
177
} )
149
178
150
- // Display the model when the fit button is clicked
179
+ // POST the active model control form when the fit button is clicked then render
180
+ // the model contours and score (along with any other model-visualizations).
151
181
$ ( "button#fitBtn" ) . click ( function ( e ) {
152
182
e . preventDefault ( ) ;
153
183
@@ -157,8 +187,53 @@ $(document).ready(function() {
157
187
return obj ;
158
188
} , { } ) ;
159
189
190
+ // Add unchecked checkboxes and change checkboxes to true/false
191
+ form . find ( 'input[type="checkbox"]' ) . each ( function ( ) {
192
+ var cb = $ ( this ) ;
193
+ if ( ! cb . prop ( "disabled" ) ) {
194
+ data [ cb . attr ( "name" ) ] = cb . prop ( "checked" ) . toString ( ) ;
195
+ }
196
+ } ) ;
197
+
198
+ console . log ( data ) ;
160
199
app . fit ( data ) ;
161
200
return false ;
162
201
} ) ;
163
202
203
+ // Enable the correct hyperparameters based on the selected naive bayes model
204
+ $ ( '#bayes input[name="model"]' ) . change ( function ( e ) {
205
+
206
+ // Disable all of the form controls except for the radios
207
+ $ ( '#bayes input[type="text"' ) . prop ( "disabled" , true ) ;
208
+ $ ( '#bayes input[type="checkbox"' ) . prop ( "disabled" , true ) ;
209
+
210
+ // Enable based on the model ID
211
+ switch ( $ ( this ) . val ( ) ) {
212
+ case "gaussiannb" :
213
+ $ ( '#bayes input[name="priors"]' ) . prop ( "disabled" , false ) ;
214
+ $ ( '#bayes input[name="var_smoothing"]' ) . prop ( "disabled" , false ) ;
215
+ break
216
+ case "multinomialnb" :
217
+ $ ( '#bayes input[name="alpha"]' ) . prop ( "disabled" , false ) ;
218
+ $ ( '#bayes input[name="class_prior"]' ) . prop ( "disabled" , false ) ;
219
+ $ ( '#bayes input[name="fit_prior"]' ) . prop ( "disabled" , false ) ;
220
+ break ;
221
+ case "bernoullinb" :
222
+ $ ( '#bayes input[name="alpha"]' ) . prop ( "disabled" , false ) ;
223
+ $ ( '#bayes input[name="binarize"]' ) . prop ( "disabled" , false ) ;
224
+ $ ( '#bayes input[name="class_prior"]' ) . prop ( "disabled" , false ) ;
225
+ $ ( '#bayes input[name="fit_prior"]' ) . prop ( "disabled" , false ) ;
226
+ break ;
227
+ case "complementnb" :
228
+ $ ( '#bayes input[name="alpha"]' ) . prop ( "disabled" , false ) ;
229
+ $ ( '#bayes input[name="class_prior"]' ) . prop ( "disabled" , false ) ;
230
+ $ ( '#bayes input[name="fit_prior"]' ) . prop ( "disabled" , false ) ;
231
+ $ ( '#bayes input[name="norm"]' ) . prop ( "disabled" , false ) ;
232
+ break ;
233
+ default :
234
+ console . log ( "unknown bayesian model selected, cannot enable form!" ) ;
235
+ }
236
+
237
+ } ) ;
238
+
164
239
} ) ;
0 commit comments