-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
63 lines (49 loc) · 1.84 KB
/
utils.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
export function parseNodes(sortedNodes) {
const out = [[]];
let count = 0;
let bucketIndex = 0;
let bucketCapacity = Math.round(sortedNodes.length / 10);
//console.log('len: ', sortedNodes.length);
//console.log('Bucket Capacity:', bucketCapacity);
//console.log('Least Capacity: ', sortedNodes[0].capacity);
//console.log('Max Capacity: ', sortedNodes[sortedNodes.length - 1].capacity);
for (let n of sortedNodes) {
out[bucketIndex].push(n);
count++;
if (count % bucketCapacity === 0) {
bucketIndex++;
out.push([]);
}
}
return out.filter(b => b.length > 0).map((bucket, index) => {
//console.log(`Bucket #${index}: ${bucket[0].capacity} to ${bucket[bucket.length - 1].capacity}`);
return {
id : index,
alias : `${formatSats(bucket[0].capacity)} to ${formatSats(bucket[bucket.length - 1].capacity)} sats`,
peers : bucket.length,
startSats : bucket[0].capacity,
endSats : bucket[bucket.length - 1].capacity,
children : bucket
}
});
}
export function parseLinks({nodes, channels}) {
return channels.map(l => {
return {
source: nodes.findIndex(n => n.public_key === l.n0_public_key),
target: nodes.findIndex(n => n.public_key === l.n1_public_key),
...l
}
});
}
export function formatSats(sats) {
if (sats < 1000) {
return sats;
} else if (sats < 1000000) {
return (sats / 1000).toFixed(2) + 'K';
//return (sats / 1000).toFixed(0) + 'K';
} else {
return (sats / 1000000).toFixed(2) + 'M';
//return (sats / 1000000).toFixed(0) + 'M';
}
}