-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
142 lines (112 loc) · 3.21 KB
/
script.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
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
var r=0;
var c=0;
var R=[[-1, -1, -1, -1, 0, -1],
[-1, -1, -1, 0, -1, 100],
[-1, -1, -1, 0, -1, -1],
[-1, 0, 0, -1, 0, -1],
[-1, 0, 0, -1, -1, 100],
[-1, 0, -1, -1, 0, 100]];
var Q_mat=[[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]];
var nodes = new vis.DataSet([
{id: 0, label: 'Node 0'},
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
// create an array with edges
var edges = new vis.DataSet([
{from: 0, to: 4},
{from: 1, to: 3},
{from: 1, to: 5},
{from: 2, to: 3},
{from: 3, to: 4},
{from: 4, to: 5},
{from: 5, to: 5}
]);
var restart = document.querySelector("#b1");
var start=document.querySelector("#b2");
var show_path=document.querySelector("#b3");
var tab1=document.getElementById("tab1") ;
var tab2=document.getElementById("tab2") ;
function change_Q(data,i) {
setTimeout(function() {
for(j in data.Q_Learn[i]){
var val=data.Q_Learn[i][j];
var index_rc=j.split('');
tab2.rows[r].cells[c].style.backgroundColor= "#e6fff1";
r=Number(index_rc[0]);
c=Number(index_rc[1]);
tab2.rows[r].cells[c].textContent=Math.round(val);
tab2.rows[r].cells[c].style.backgroundColor= "#ff4d4d";
}
}, 500 * i);
}
function training_Q(){
fetch('./model_history.json').then(response => {
return response.json();
}).then(data => {
//JSON data here..
var states_IF = document.getElementById("train_summary");
states_IF.textContent=data.Training_Summary
for (k in data.Q_Learn){
change_Q(data,k);
}
}).catch(err => {
// when the request fails
console.log('The request failed!');
});
}
function color_path(n){
var pathNode = nodes.get(n);
pathNode.color = {
border: '#ff4d4d',
background: '#ff4d4d',
highlight: {
border: '#ff4d4d',
background: '#ff4d4d'
}
}
nodes.update(pathNode);
}
function path_nodes(){
fetch('./model_history.json').then(response => {
return response.json();
}).then(data => {
//JSON data here..
var states_IF = document.getElementById("path_summary");
states_IF.textContent=data.Path_Summary
for(var i=0; i<data.Path.length;i++){
color_path(data.Path[i]);
}
}).catch(err => {
// when the request fails
console.log('The request failed!');
});
}
start.addEventListener('click',training_Q);
show_path.addEventListener('click',path_nodes)
for (var i = 0 ; i < tab1.rows.length; i++) {
for (var j = 1; j < tab1.rows[i].cells.length; j++) {
tab1.rows[i].cells[j].textContent=R[i][j-1];
}
}
for (var i = 0 ; i < tab2.rows.length; i++) {
for (var j = 1; j < tab2.rows[i].cells.length; j++) {
tab2.rows[i].cells[j].textContent=Q_mat[i][j-1];
}
}
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {autoResize: true};
var network = new vis.Network(container, data, options);