/
examples.js
159 lines (155 loc) 路 4.48 KB
/
examples.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// //////////////////////////////////////////////////////////////////////////////
// / DISCLAIMER
// /
// / Copyright 2014-2024 ArangoDB GmbH, Cologne, Germany
// / Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
// /
// / Licensed under the Business Source License 1.1 (the "License");
// / you may not use this file except in compliance with the License.
// / You may obtain a copy of the License at
// /
// / https://github.com/arangodb/arangodb/blob/devel/LICENSE
// /
// / Unless required by applicable law or agreed to in writing, software
// / distributed under the License is distributed on an "AS IS" BASIS,
// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// / See the License for the specific language governing permissions and
// / limitations under the License.
// /
// / Copyright holder is ArangoDB GmbH, Cologne, Germany
// /
// / @author Wilfried Goesgens
// / @author Copyright 2018, ArangoDB Inc
// //////////////////////////////////////////////////////////////////////////////
let db = require("internal").db;
let examples = require("@arangodb/graph-examples/example-graph.js");
let user_examples = require("@arangodb/examples/example-users.js");
exports.Examples = {
'traversalGraph': {
createDS: function() {
examples.loadGraph("traversalGraph");
},
removeDS: function() {
examples.dropGraph("traversalGraph");
}
},
'kShortestPathsGraph': {
createDS: function() {
examples.loadGraph("kShortestPathsGraph");
},
removeDS: function() {
examples.dropGraph("kShortestPathsGraph");
}
},
'mps_graph': {
createDS: function() {
examples.loadGraph("mps_graph");
},
removeDS: function() {
examples.dropGraph("mps_graph");
}
},
'knows_graph': {
createDS: function() {
examples.loadGraph("knows_graph");
},
removeDS: function() {
examples.dropGraph("knows_graph");
}
},
'routeplanner': {
createDS: function() {
examples.loadGraph("routeplanner");
},
removeDS: function() {
examples.dropGraph("routeplanner");
}
},
'connectedComponentsGraph': {
createDS: function() {
examples.loadGraph("connectedComponentsGraph");
},
removeDS: function() {
examples.dropGraph("connectedComponentsGraph");
}
},
'joinSampleDataset': {
createDS: function() {
db._create("users");
db._create("relations");
[ [1, "Abigail", true ],
[2, "Fred", true ],
[3, "Mary", true ],
[4, "Mariah", true ],
[5, "John", false]
].forEach(function (v) {
db.users.save( {
_key: v[1],
name: v[1],
active: v[2],
userId: v[0]
});
});
[
[1,2,"friend"],
[1,3,"friend"],
[1,4,"friend"],
[2,5,"friend"],
[2,2,"friend"],
[3,4,"friend"],
[3,1,"friend"],
[4,1,"friend"],
[4,2,"friend"]
].forEach(function (v) {
db.relations.save( {
type: v[2],
friendOf: v[0],
thisUser: v[1]
});
});
},
removeDS: function() {
try {
db._drop("users");
} catch (e) {}
try {
db._drop("relations");
} catch (e) {}
}
},
'observationsSampleDataset': {
createDS: function() {
db._create("observations");
db.observations.save([
{ "time": "2021-05-25 07:00:00", "subject": "st113", "val": 10 },
{ "time": "2021-05-25 07:15:00", "subject": "st113", "val": 9 },
{ "time": "2021-05-25 07:30:00", "subject": "st113", "val": 25 },
{ "time": "2021-05-25 07:45:00", "subject": "st113", "val": 20 },
{ "time": "2021-05-25 07:00:00", "subject": "xh458", "val": 0 },
{ "time": "2021-05-25 07:15:00", "subject": "xh458", "val": 10 },
{ "time": "2021-05-25 07:30:00", "subject": "xh458", "val": 5 },
{ "time": "2021-05-25 07:45:00", "subject": "xh458", "val": 30 },
{ "time": "2021-05-25 08:00:00", "subject": "xh458", "val": 25 },
]);
},
removeDS: function() {
try {
db._drop("observations");
} catch (e) {}
}
},
'usersDataset': {
createDS: function() {
let u = user_examples.createUsers('users');
let r = user_examples.createRegions('regions');
user_examples.createLocations('locations', u);
},
removeDS: function() {
try {
db._drop("users");
db._drop("regions");
db._drop("locations");
} catch (e) {}
}
}
};