Repository navigation
Expand file tree
/
Copy pathranksort.js
More file actions
69 lines (56 loc) · 1.68 KB
/
Copy pathranksort.js
File metadata and controls
69 lines (56 loc) · 1.68 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
const _=require('underscore');
const fs = require('fs');
const math = require('mathjs');
//const json = require('./assets/ranks.json');
let json = JSON.parse(fs.readFileSync('../BinList/assets/bin-list.json', 'utf8'));
let resultArray = [];
let jsonResult = {};
_.map(json, function(content) {
let number = content.rarity.split(':')[1];
number = parseFloat(number);
number = number = number + 0; // you are number!!
number = math.format(number, {notation: 'fixed'});
jsonResult = {
"bin": content.bin,
"bits": content.bits,
"bytes": content.bytes,
"lines": content.lines,
"name": content.name,
"rarity": content.rarity,
"humanreadable": number.toString()
}
console.log(jsonResult);
resultArray.push(jsonResult);
});
/*
fs.writeFile(`./bin-ranks.json`, JSON.stringify(resultArray), function (err) {
if (err) return console.log(err);
console.log(`write ./bin-ranks.json`);
});
json = JSON.parse(fs.readFileSync('./bin-ranks.json', 'utf8'));
resultArray = [];
jsonResult = {};
*/
var arr = [];
let metadata = {};
resultArray.sort((a, b) => {
return b.humanreadable - a.humanreadable;
});
for(var i = 0; i < resultArray.length; i++) {
//console.log(json[i].humanreadable);
metadata = {
"bin": resultArray[i].bin,
"bits": resultArray[i].bits,
"bytes": resultArray[i].bytes,
"lines": resultArray[i].lines,
"name": resultArray[i].name,
"rarity": resultArray[i].rarity,
"humanreadable": resultArray[i].humanreadable,
"rank": i.toString()
}
arr.push(metadata);
}
fs.writeFile(`../BinList/bin-list.json`, JSON.stringify(arr), function (err) {
if (err) return console.log(err);
console.log(`write ./bins-ranked.json`);
});