forked from switch-900/BitmapOCI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder.js
More file actions
43 lines (34 loc) · 1.24 KB
/
encoder.js
File metadata and controls
43 lines (34 loc) · 1.24 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
const fs = require('fs');
const path = require('path');
const inputFilePath = path.join(__dirname, '0.csv');
const outputFilePath = path.join(__dirname, 'pages/0.json');
fs.readFile(inputFilePath, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const rows = data.trim().split('\n');
const sats = rows.map(row => parseInt(row.split(',')[2]));
const indexedArray = sats.map((element, index) => ({ index, satNumber: element }));
indexedArray.sort((a, b) => a.satNumber - b.satNumber);
const satArray = []
const indexArray = []
indexedArray.forEach((data, i) => {
if (i === 0) {
console.log(data.satNumber)
satArray.push(data.satNumber)
indexArray.push((data.index))
} else {
const delta = indexedArray[i].satNumber - indexedArray[i-1].satNumber
satArray.push(delta)
indexArray.push((data.index))
}
})
fs.writeFile(outputFilePath, JSON.stringify([satArray, indexArray], null, 2), 'utf8', (err) => {
if (err) {
console.error(err);
return;
}
console.log(`output written to ${outputFilePath}`);
});
});