-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
50 lines (40 loc) · 1.69 KB
/
example.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
// Creating socket
const io = require('socket.io-client');
const xorBaseUrl = 'https://change.me';
const xorSocket = io(`${xorBaseUrl}/analyst`, { forceNew: true });
// Define variables:
const netconfigId = 'demo';
let ucid;
// Create new computation id
xorSocket.emit('createAndJoinNewUcid', { netconfigId }, (ans) => {
console.log(ans);
({ ucid } = ans.ucid);
});
// Load compute params from json file/re/
const fs = require('fs');
const json = JSON.parse(fs.readFileSync('./params/radar.json'));
// Create completion listeners for the different phases:
xorSocket.on('compilePhaseCompleted', ans => console.log(`compile: ${ans.timings}ms`));
xorSocket.on('offlinePhaseCompleted', ans => console.log(`offline: ${ans.timings}ms`));
xorSocket.on('preprocessingPhaseCompleted', ans => console.log(`preprocessing: ${ans.timings}ms`));
xorSocket.on('onlinePhaseCompleted', ans => console.log(`online: ${ans.timings}ms`));
xorSocket.on('postprocessingPhaseCompleted', ans => console.log(`postprocessing: ${ans.timings}ms`));
// List all datasets
xorSocket.emit('listPrivateDatasets', {}, ans => console.log(ans));
// List headers for a particular dataset
xorSocket.emit('listHeaders', { ownerId: 0, name: 'radar_a' }, console.log);
// Once computation is validated start process
xorSocket.on('newComputationCreated', (ans) => {
console.log(ans)
if(!ans.error) xorSocket.emit('initiateCompilePhase', { ucid });
else xorSocket.close();
});
// Result completion handler
xorSocket.on('resultPhaseCompleted', (ans) => {
console.log(ans);
// Result file can be downloaded under:
// https://${xorBaseUrl}/result/${ucid}
xorSocket.close();
});
// Start actual computation
xorSocket.emit('createNewComputation', json);