This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
108 lines (94 loc) · 2.76 KB
/
main.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
'use strict';
// includes
const db = require('@arangodb').db;
const pregel = require("@arangodb/pregel");
let sgm = require("@arangodb/smart-graph");
const joi = require('joi');
// router
const createRouter = require('@arangodb/foxx/router');
const router = createRouter();
module.context.use(router);
// example algo
const exampleAlgo = require('./algos/exampleAlgorithm').exampleAlgo;
router.post('/start', function (req, res) {
const name = req.body.name || "name";
const graphName = req.body.graphName;
const algorithm = req.body.algorithm;
let pid = pregel.start(
"air",
graphName,
algorithm
);
res.send({
pid: pid
});
})
.body(
joi.object().required(),
'This implies JSON.'
)
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
router.post('/resultDetails', function (req, res) {
const graphName = req.body.graphName || "";
const resultField = req.body.resultField || "";
let finalResult = {};
// get all vertex collections
let vertexColls = sgm._graph(graphName)._vertexCollections();
for (let [key, col] of Object.entries(vertexColls)) {
let collectionName = col.name();
finalResult[collectionName] = [];
let res = db._query(
'FOR doc IN @@vertexCollection LIMIT 5 RETURN doc[@resultField]',
{
'@vertexCollection': collectionName,
'resultField': resultField
}
).toArray();
finalResult[collectionName].push(res);
}
;
res.send(finalResult);
})
.body(
joi.object().required(),
'This implies JSON.'
)
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
router.post('/status', function (req, res) {
const pid = req.body.pid || "";
let result = pregel.status(pid);
res.send(result);
})
.body(
joi.object().required(),
'This implies JSON.'
)
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
router.get('/graphs', function (req, res) {
res.send(sgm._list());
})
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
router.get('/userDefinedAlgorithms', function (req, res) {
const qualifiedName = module.context.collectionName("userDefinedAlgorithms");
let arr = db[qualifiedName].all().toArray();
let result = {};
arr.forEach(document => {
result[document._key] = document;
});
// also push demo example
result["dev_DemoPageRank"] = {
algorithm: exampleAlgo
};
res.send(result);
})
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');