-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdelete-data-points.js
39 lines (34 loc) · 1.21 KB
/
delete-data-points.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
// Delete a group of data points read from a csv file of the form:
// id,xid,other,rows
const Files = Java.type('java.nio.file.Files');
function readCsv(fileStore, filePath) {
const path = services.fileStoreService.getPathForRead(fileStore, filePath);
const lines = Array.from(Files.readAllLines(path));
const header = lines.shift().split(',');
for (let i = 0; i < lines.length; i++) {
const row = lines[i].split(',');
const data = lines[i] = {};
for (let j = 0; j < row.length; j++) {
data[header[j]] = row[j];
}
}
return lines;
}
const dataPointService = services.dataPointService;
const pointsArray = readCsv('default', 'data-points-to-delete.csv');
console.log(`Deleting ${pointsArray.length} points`);
let count = 0;
let failed = 0;
for(const point of pointsArray) {
try {
dataPointService.delete(point.xid);
count++;
}catch(error) {
log.error('Failed deleting data point {}', point.xid, error);
failed++;
}
if(count % 10 == 0){
console.log(`Deleted ${count} points out of ${pointsArray.length}`);
}
}
console.log(`Finished deleting ${count} out of ${pointsArray.length} points with ${failed} errors`);