-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvis-pricing.js
More file actions
204 lines (192 loc) · 6.04 KB
/
Copy pathvis-pricing.js
File metadata and controls
204 lines (192 loc) · 6.04 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
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
// fetch('http://localhost:8100')
// .then(response => response.json())
// .then(state => {
//////////////NODES//////////////
var node_off = (x_pos,y_pos,id_num, title_hover) => { return { id: id_num, shape: 'icon', icon: { face: "'FontAwesome'", code: "\uf1b2", size: 40, color: "black", }, borderWidth: 2, x: x_pos, y: y_pos, title: title_hover}}
var node_on = (x_pos,y_pos,id_num, title_hover, color) => { return { id: id_num, shape: 'icon', icon: { face: "'FontAwesome'", code: "\uf1b2", size: 40, color: color, }, borderWidth: 2, x: x_pos, y: y_pos, title: title_hover}}
var nodes = new vis.DataSet([]);
///////////////EDGES/////////////
var between_nodes = (from_node,to_node) => {return { from: from_node, to: to_node, color: "rgb(20,24,200)", arrows: "from, to" }}
// create an array with edges
var edges = new vis.DataSet([]);
var updateNodesAndEdges = (edges, nodes,state, numNodesInserted) => {
//State machine
numNodes = state["Nodes"].length + 1
titles = []
titles.push(buildTitle(state["ThisName"], state["ThisId"], state["ThisAddress"],state["PendingJobs"], state["DoneJobs"]))
for(let i = numNodesInserted; i < numNodes-1; i++){
titles.push(buildTitle(state["Nodes"][i]["Name"], state["Nodes"][i]["ID"], state["Nodes"][i]["Address"], state["Nodes"][i]["PendingJobs"], state["Nodes"][i]["DoneJobs"]))
}
for(let i = numNodesInserted; i < numNodes; i++){
var randomColor = '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');
nodes.add(node_on(0, 0,i, titles[i], randomColor));
if (i > 0) {
for(let j = 0; j < i; j++){
edges.add(between_nodes(j,i));
}
}
}
return numNodes
}
var buildTitle = (name, ID, address, pending, done) => {
var NodeInfo = "Name: " + name + "\n" + "ID: " + ID + "\n" + "Address: " + address + "\n"
var PendingJobs = "\nPending Jobs \n"
if (pending.length > 0){
for (let i = 0; i < pending.length; i++){
PendingJobs += pending[i]["ID"] + "->" + pending[i]["Type"] + "\n"
}
}
var DoneJobs = "\nDone Jobs \n"
if (done.length > 0){
for (let i = 0; i < done.length; i++){
DoneJobs += done[i]["ID"] + "->" + done[i]["Type"] + "\n"
}
}
return NodeInfo + PendingJobs + DoneJobs
}
//updateNodes(state);
// create a network
var container = document.getElementById("mynetwork");
var data = {
nodes: nodes,
edges: edges,
};
var options = {
nodes: {
shape: 'dot'
},
edges: {
smooth: false
},
physics: true,
interaction: {
dragNodes: false,// do not allow dragging nodes
zoomView: false, // do not allow zooming
dragView: false // do not allow dragging
}
};
var network = new vis.Network(container, data, options);
var numNodesInserted = 0;
function timeout() {
setTimeout(function () {
// fetch('http://localhost:8100')
// .then(response => response.json())
// .then(state => {
state = {
"ThisName": "Alice",
"ThisId": "3089053916941511196",
"ThisAddress": "172.17.0.2",
"ThisPassword": "",
"ThisEvaluationPoint": {
"V": 1,
"M": 65000549695646603732796438742359905742570406053903786389881062969044166799969,
"BO": false
},
"ThisSecretValue": null,
"ThisPublicKey": null,
"DisableBroadcast": false,
"PendingJobs": [
{
"ID": "ID0f6017556475602505628",
"AgentID": "6017556475602505628",
"Type": "TestJob",
"Finished": false,
"Error": "",
"Payload": "Are you there?"
},
{
"ID": "ID1f3089053916941511196",
"AgentID": "3089053916941511196",
"Type": "MPSignature",
"Finished": false,
"Error": "",
"Payload": "02000000000000000000000000000000000000000000000000000000000000000212dc2ddad8ed72726c8e7d4daaeaba8480984f3efbfae14dd71f26182498ca154d93a90afdebeb0a815a3f258a9c866f36668767525ba7348f18db1c5f1157142439646639643439342d376333632d313165622d623865362d62383662323334383934623848656c6c6f20426f62"
}
],
"DoneJobs": [
{
"ID": "ID0f3089053916941511196",
"AgentID": "3089053916941511196",
"Type": "TestJob",
"Finished": true,
"Error": "",
"Payload": "Are you there?"
}
],
"JobBroadcast": {},
"KnownScalarShares": {
"9df9d494-7c3c-11eb-b8e6-b86b234894b8": [
{
"E": {
"V": 2,
"M": 65000549695646603732796438742359905742570406053903786389881062969044166799969,
"BO": false
},
"V": {
"V": 18267298965087384827294908530404108237589431360719280554881346428202447285138,
"M": 65000549695646603732796438742359905742570406053903786389881062969044166799969,
"BO": false
},
"T": 2,
"SuiteID": "9df9d494-7c3c-11eb-b8e6-b86b234894b8"
}
]
},
"Nodes": [
{
"Name": "Bob",
"ID": "6017556475602505628",
"Address": "172.17.0.3",
"LastSeen": "2021-03-30T09:46:14.9856168Z",
"PendingJobs": [
{
"ID": "ID1f3089053916941511196",
"Type": "TestJob"
}
],
"DoneJobs": [
{
"ID": "ID0f3089053916941511196",
"Type": "TestJob"
},
{
"ID": "ID1f3089053916941511196",
"Type": "MPSignature"
}
]
},
{
"Name": "Carol",
"ID": "3895312406672063063",
"Address": "172.17.0.4",
"LastSeen": "2021-03-30T09:46:15.2296065Z",
"PendingJobs": [
{
"ID": "ID0f3089053916941511196",
"Type": "TestJob"
},
{
"ID": "ID0f6017556475602505628",
"Type": "MPSignature"
},
{
"ID": "ID1f3089053916941511196",
"Type": "TestJob"
}
],
"DoneJobs": []
}
]
}
numNodesInserted = updateNodesAndEdges(edges, nodes, state, numNodesInserted);
var data = {
nodes: nodes,
edges: edges,
};
network = new vis.Network(container, data, options);
// })
timeout();
}, 7000);
};
timeout()
// });