-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbinary-classification.js
More file actions
82 lines (74 loc) · 3.01 KB
/
binary-classification.js
File metadata and controls
82 lines (74 loc) · 3.01 KB
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
/**
* This is a custom page object used for [binary-classification-hbs.htm]
* and [binary-classification-vue.htm] examples.
*
* The page object is created by extending/copying the core [js/pages/entryForm.js] file.
* This demo shows how you can use the built-in features of [entryForm] for a page
* allowing for a relatively small amount of JS code needed for a custom form.
*/
/* Validates with both [jshint] and [eslint] */
/* global app */
/* jshint strict: true */
/* eslint-env browser */
/* eslint quotes: ["error", "single", { "avoidEscape": true }] */
/* eslint strict: ["error", "function"] */
/* eslint spaced-comment: ["error", "always"] */
/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */
(function () {
'use strict';
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* Create the Page Object by copying the entryForm Page
*/
var page = app.deepClone({}, app.pages.entryForm);
/**
* The [entryForm.model] defines callback functions that can be handled
* when it is extended.
*/
Object.assign(page.model, {
// New Values Button Reference
btnNewValues: null,
// Entry Form Events
// Simpley enable/disable the custom [New Random Values] button while
// data is being submitted.
onFormLoaded: function() {
this.btnNewValues = document.querySelector('.btn-new-values');
this.btnNewValues.onclick = this.newValues.bind(this);
},
onFormBeforeSave: function() {
this.btnNewValues.disabled = true;
return true; // Valid to submit/save
},
onFormAfterSave: function() { this.btnNewValues.disabled = false; },
onFormSaveError: function() { this.btnNewValues.disabled = false; },
// Set new random values and run a new prediction after
newValues: function() {
var elements = document.querySelectorAll('input[id^="field-"]');
Array.prototype.forEach.call(elements, function(el) {
var isFloat = el.step.includes('.');
if (isFloat) {
var value = getRandomArbitrary(parseFloat(el.min), parseFloat(el.max));
value = Number(value).toFixed(el.step.length - 2);
el.value = value;
} else {
el.value = getRandomIntInclusive(parseInt(el.min, 10), parseInt(el.max, 10));
}
});
// Call prediction web service, [saveRecord()] is
// defined in the core [pages/entryForm.js] file.
this.saveRecord();
},
});
/**
* Add page to app
*/
app.addPage('binaryPredictionPage', page);
})();