-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathutils.js
More file actions
95 lines (88 loc) · 3.23 KB
/
utils.js
File metadata and controls
95 lines (88 loc) · 3.23 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
const {DataFrame, Series, Int32, Uint8, Uint32, Uint64} = require('@rapidsai/cudf');
const {Float32Buffer} = require('@rapidsai/cuda');
function readDataFrame(path) {
if (path.indexOf('.csv', path.length - 4) !== -1) {
// csv file
return DataFrame.readCSV({sources: [path], header: 0, sourceType: 'files'});
} else if (path.indexOf('.parquet', path.length - 8) !== -1) {
// csv file
return DataFrame.readParquet({sources: [path]});
}
// if (df.names.includes('Unnamed: 0')) { df = df.cast({'Unnamed: 0': new Uint32}); }
return new DataFrame({});
}
async function getNodesForGraph(asDeviceMemory, nodes, numNodes) {
let nodesRes = {};
const pos = new Float32Buffer(Array.from(
{length: numNodes * 2},
() => Math.random() * 1000 * (Math.random() < 0.5 ? -1 : 1),
));
if (nodes.x in nodes.dataframe.names) {
nodesRes.nodeXPositions = asDeviceMemory(nodes.dataframe.get(node.x).data);
} else {
nodesRes.nodeXPositions = pos.subarray(0, pos.length / 2);
}
if (nodes.y in nodes.dataframe.names) {
nodesRes.nodeYPositions = asDeviceMemory(nodes.dataframe.get(node.y).data);
} else {
nodesRes.nodeYPositions = pos.subarray(pos.length / 2);
}
if (nodes.dataframe.names.includes(nodes.size)) {
nodesRes.nodeRadius = asDeviceMemory(nodes.dataframe.get(nodes.size).cast(new Uint8).data);
}
if (nodes.dataframe.names.includes(nodes.color)) {
nodesRes.nodeFillColors =
asDeviceMemory(nodes.dataframe.get(nodes.color).cast(new Uint32).data);
}
if (nodes.dataframe.names.includes(nodes.id)) {
nodesRes.nodeElementIndices =
asDeviceMemory(nodes.dataframe.get(nodes.id).cast(new Uint32).data);
}
return nodesRes;
}
async function getEdgesForGraph(asDeviceMemory, edges) {
let edgesRes = {};
if (edges.dataframe.names.includes(edges.color)) {
edgesRes.edgeColors = asDeviceMemory(edges.dataframe.get(edges.color).data);
} else {
edgesRes.edgeColors = asDeviceMemory(
Series
.sequence(
{type: new Uint64, size: edges.dataframe.numRows, init: 18443486512814075489n, step: 0})
.data);
}
if (edges.dataframe.names.includes(edges.id)) {
edgesRes.edgeList = asDeviceMemory(edges.dataframe.get(edges.id).cast(new Uint64).data);
}
if (edges.dataframe.names.includes(edges.bundle)) {
edgesRes.edgeBundles = asDeviceMemory(edges.dataframe.get(edges.bundle).data);
}
return edgesRes;
}
async function getPaginatedRows(df, pageIndex = 0, pageSize = 400, selected = []) {
if (selected.length != 0) {
const selectedSeries = Series.new({type: new Int32, data: selected}).unique(true);
const updatedDF = df.gather(selectedSeries);
const idxs = Series.sequence({
type: new Int32,
init: (pageIndex - 1) * pageSize,
size: Math.min(pageSize, updatedDF.numRows),
step: 1
});
return [updatedDF.gather(idxs).toArrow(), updatedDF.numRows];
} else {
const idxs = Series.sequence({
type: new Int32,
init: (pageIndex - 1) * pageSize,
size: Math.min(pageSize, df.numRows),
step: 1
});
return [df.gather(idxs).toArrow(), df.numRows];
}
}
module.exports = {
readDataFrame,
getNodesForGraph,
getEdgesForGraph,
getPaginatedRows
}