-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbest.js
More file actions
74 lines (69 loc) · 2.98 KB
/
best.js
File metadata and controls
74 lines (69 loc) · 2.98 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
/** @param {NS} ns **/
export async function main(ns) {
function fill(str, space = 10) {
var temp = str.toString()
var needed_space = space - temp.length
while (needed_space > 0) {
temp += ' '
needed_space--
}
return temp
}
function unit(income) {
var temp = parseInt(income)
const list = ['', 'K', 'M', 'G', 'T', 'P']
var count = 0
while ((temp / 1000) > 1) {
temp = temp / 1000
count++
}
return fill(temp.toPrecision(5) + list[count])
}
await ns.write('best.txt', '', 'w')
var printF = ns.args[0] === 'reset' ? (str) => {} : ns.tprintf
var displaySize = ns.args[0] === 'long' ? 30 : ns.args[0] === 'all' ? 100000 : 10
var rooted = ns.read('rooted.txt').split(',')
var data = []
for (const server of rooted) {
if (ns.fileExists(server + '.txt')) {
var temp = ns.read(server + '.txt').split(',')
if (temp.length === 31) {
data.push([server, 'CorePerTS', temp[0], temp[1], temp[2], temp[3], temp[4], temp[30]])
data.push([server, 'CorePer1k', temp[5], temp[6], temp[7], temp[8], temp[9], temp[30]])
data.push([server, 'CorePer97', temp[10], temp[11], temp[12], temp[13], temp[14], temp[30]])
}
}
}
data.sort((a, b) => {
return parseFloat(b[6]) - parseFloat(a[6])
})
printF(' PTS Income Error Hostname Type')
for (let i = 0; i < Math.min(data.length, displaySize); i++) {
printF(`${fill((i + 1) + '.', 5)} ${unit(data[i][6])} ${unit(data[i][5])} ${fill(parseFloat(data[i][7]).toFixed(4))} ${fill(data[i][0], 18)} ${fill(data[i][1])}`)
}
for (let i = 0; i < data.length; i++) {
await ns.write('best.txt', `${data[i]},`, 'a')
}
/*-------------------------------------*/
data = []
for (const server of rooted) {
if (ns.fileExists(server + '.txt')) {
var temp = ns.read(server + '.txt').split(',')
if (temp.length === 31) {
data.push([server, 'PerTS', temp[15], temp[16], temp[17], temp[18], temp[19], temp[30]])
data.push([server, 'Per1k', temp[20], temp[21], temp[22], temp[23], temp[24], temp[30]])
data.push([server, 'Per97', temp[25], temp[26], temp[27], temp[28], temp[29], temp[30]])
}
}
}
data.sort((a, b) => {
return parseFloat(b[6]) - parseFloat(a[6])
})
printF(' PTS Income Error Hostname Type')
for (let i = 0; i < Math.min(data.length, displaySize); i++) {
printF(`${fill((i + 1) + '.', 5)} ${unit(data[i][6])} ${unit(data[i][5])} ${fill(parseFloat(data[i][7]).toFixed(4))} ${fill(data[i][0], 18)} ${fill(data[i][1])}`)
}
for (let i = 0; i < data.length; i++) {
await ns.write('best.txt', `${data[i]},`, 'a')
}
}