-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
67 lines (53 loc) · 1.94 KB
/
client.js
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
import io from 'socket.io-client';
const predictContainer = document.getElementById('predictContainer');
const predictButton = document.getElementById('predict-button');
const dataButton = document.getElementById('data-button');
const socket =
io('http://localhost:8001',
{reconnectionDelay: 300, reconnectionDelayMax: 300});
//const testSample = [38,31.0,1]; // survived (age, fare, is_female)
//const testSample = [28,7.0,0]; //did not survive
var testSample = [];
var age;
var fare;
var sex;
//const testSample = [40,0.0,0]; //died
dataButton.onclick = () => {
//dataButton.disabled = true;
//testSample = document.getElementById('data').value;
age = parseInt(document.getElementById('age').value);
testSample.push(age);
fare = parseInt(document.getElementById('fare').value);
testSample.push(fare);
sex = parseInt(document.getElementById('sex').value);
testSample.push(sex);
console.log(testSample);
}
predictButton.onclick = () => {
predictButton.disabled = true;
socket.emit('predictSample', testSample);
testSample = [];
};
// functions to handle socket events
socket.on('connect', () => {
document.getElementById('waiting-msg').style.display = 'none';
document.getElementById('trainingStatus').innerHTML = 'Training in Progress';
});
socket.on('trainingComplete', () => {
document.getElementById('trainingStatus').innerHTML = 'Training Complete';
document.getElementById('predictSample').innerHTML = '[' + testSample.join(', ') + ']';
predictContainer.style.display = 'block';
});
socket.on('predictResult', (result) => {
plotPredictResult(result);
});
socket.on('disconnect', () => {
document.getElementById('trainingStatus').innerHTML = '';
predictContainer.style.display = 'none';
document.getElementById('waiting-msg').style.display = 'block';
});
function plotPredictResult(result) {
predictButton.disabled = false;
document.getElementById('predictResult').innerHTML = result;
console.log(result);
}