mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-25 18:13:10 +03:00
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import configs from "~/knexfile";
|
|
import knex from "knex";
|
|
|
|
import * as Data from "~/node_common/data";
|
|
import * as Strings from "~/common/strings";
|
|
|
|
const envConfig = configs["development"];
|
|
const db = knex(envConfig);
|
|
|
|
console.log(`RUNNING: worker-analytics.js`);
|
|
|
|
function sortObject(obj) {
|
|
var arr = [];
|
|
for (var prop in obj) {
|
|
if (obj.hasOwnProperty(prop)) {
|
|
arr.push({
|
|
key: prop,
|
|
value: obj[prop],
|
|
});
|
|
}
|
|
}
|
|
arr.sort(function(a, b) {
|
|
return b.value - a.value;
|
|
});
|
|
//arr.sort(function(a, b) { a.value.toLowerCase().localeCompare(b.value.toLowerCase()); }); //use this to sort as strings
|
|
return arr; // returns array
|
|
}
|
|
|
|
const run = async () => {
|
|
const response = await Data.getEveryUser(false);
|
|
|
|
let count = 0;
|
|
let bytes = 0;
|
|
let userMap = {};
|
|
|
|
response.forEach((user) => {
|
|
count = count + 1;
|
|
|
|
let userBytes = 0;
|
|
user.data.library[0].children.forEach((each) => {
|
|
userBytes = each.size + userBytes;
|
|
bytes = each.size + bytes;
|
|
});
|
|
|
|
userMap[user.username] = userBytes;
|
|
});
|
|
|
|
userMap = sortObject(userMap);
|
|
userMap = userMap.map((each, index) => {
|
|
return { ...each, index, value: Strings.bytesToSize(each.value) };
|
|
});
|
|
console.log(userMap);
|
|
console.log("TOTAL USER COUNT", count);
|
|
console.log("TOTAL BYTES", bytes);
|
|
console.log("TOTAL BYTES (CONVERTED)", Strings.bytesToSize(bytes));
|
|
};
|
|
|
|
run();
|
|
|
|
console.log(`FINISHED: worker-analytics.js`);
|
|
console.log(` CTRL +C to return to terminal.`);
|