forked from ghuser-io/db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintDataStats.js
executable file
·157 lines (139 loc) · 5.41 KB
/
printDataStats.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env node
'use strict';
(() => {
const fs = require('fs');
const path = require('path');
const data = require('./impl/data');
const DbFile = require('./impl/dbFile');
const scriptUtils = require('./impl/scriptUtils');
scriptUtils.printUnhandledRejections();
printDataStats();
return;
function printDataStats() {
let numUsers = 0;
let largestUserFileName;
let largestUserFileSize = 0;
let totalUserSize = 0;
for (const file of fs.readdirSync(data.users)) {
if (file.endsWith('.json')) {
const pathToFile = path.join(data.users, file);
const user = new DbFile(pathToFile);
if (!user.ghuser_deleted_because && !user.removed_from_github) {
++numUsers;
}
const userFileSize = fs.statSync(pathToFile).size;
if (userFileSize > largestUserFileSize) {
largestUserFileSize = userFileSize;
largestUserFileName = file;
}
totalUserSize += userFileSize;
}
}
console.log(data.users);
console.log(` ${numUsers} users`);
console.log(` largest: ${largestUserFileName} (${toKB(largestUserFileSize)})`);
console.log(` total: ${toKB(totalUserSize)}`);
let largestContribFileName;
let largestContribFileSize = 0;
let totalContribSize = 0;
for (const file of fs.readdirSync(data.contribs)) {
if (file.endsWith('.json')) {
const pathToFile = path.join(data.contribs, file);
const contribList = new DbFile(pathToFile);
const contribFileSize = fs.statSync(pathToFile).size;
if (contribFileSize > largestContribFileSize) {
largestContribFileSize = contribFileSize;
largestContribFileName = file;
}
totalContribSize += contribFileSize;
}
}
console.log(data.contribs);
console.log(` largest: ${largestContribFileName} (${toKB(largestContribFileSize)})`);
console.log(` total: ${toMB(totalContribSize)}`);
let numRepos = 0;
let numSignificantRepos = 0;
let largestRepoFileName;
let largestRepoFileSize = 0;
let totalRepoSize = 0;
for (const ownerDir of fs.readdirSync(data.repos)) {
const pathToOwner = path.join(data.repos, ownerDir);
for (const file of fs.readdirSync(pathToOwner)) {
if (file.endsWith('.json')) {
const pathToFile = path.join(pathToOwner, file);
const repo = new DbFile(pathToFile);
++numRepos;
numSignificantRepos += !repo.removed_from_github && !repo.ghuser_insignificant && 1 || 0;
const repoFileSize = fs.statSync(pathToFile).size;
if (repoFileSize > largestRepoFileSize) {
largestRepoFileSize = repoFileSize;
largestRepoFileName = `${ownerDir}/${file}`;
}
totalRepoSize += repoFileSize;
}
}
}
console.log(data.repos);
console.log(` ${numRepos} repos`);
console.log(` ${numSignificantRepos} significant repos`);
console.log(` largest: ${largestRepoFileName} (${toKB(largestRepoFileSize)})`);
console.log(` total: ${toMB(totalRepoSize)}`);
let largestRepoCommitsFileName;
let largestRepoCommitsFileSize = 0;
let totalRepoCommitsSize = 0;
for (const ownerDir of fs.readdirSync(data.repoCommits)) {
const pathToOwner = path.join(data.repoCommits, ownerDir);
for (const file of fs.readdirSync(pathToOwner)) {
if (file.endsWith('.json')) {
const pathToFile = path.join(pathToOwner, file);
const repoCommits = new DbFile(pathToFile);
const repoCommitsFileSize = fs.statSync(pathToFile).size;
if (repoCommitsFileSize > largestRepoCommitsFileSize) {
largestRepoCommitsFileSize = repoCommitsFileSize;
largestRepoCommitsFileName = `${ownerDir}/${file}`;
}
totalRepoCommitsSize += repoCommitsFileSize;
}
}
}
console.log(data.repoCommits);
console.log(` largest: ${largestRepoCommitsFileName} (${toKB(largestRepoCommitsFileSize)})`);
console.log(` total: ${toMB(totalRepoCommitsSize)}`);
let numOrgs = 0;
let largestOrgFileName;
let largestOrgFileSize = 0;
let totalOrgSize = 0;
for (const file of fs.readdirSync(data.orgs)) {
if (file.endsWith('.json')) {
const pathToFile = path.join(data.orgs, file);
const org = new DbFile(pathToFile);
++numOrgs;
const orgFileSize = fs.statSync(pathToFile).size;
if (orgFileSize > largestOrgFileSize) {
largestOrgFileSize = orgFileSize;
largestOrgFileName = file;
}
totalOrgSize += orgFileSize;
}
}
console.log(data.orgs);
console.log(` ${numOrgs} orgs`);
console.log(` largest: ${largestOrgFileName} (${largestOrgFileSize} B)`);
console.log(` total: ${toKB(totalOrgSize)}`);
const nonOrgsSize = fs.statSync(data.nonOrgs).size;
console.log(`${data.nonOrgs}: ${toKB(nonOrgsSize)}`);
const metaSize = fs.statSync(data.meta).size;
console.log(`${data.meta}: ${metaSize} B`);
const totalSize = totalUserSize + totalContribSize + totalRepoSize + totalRepoCommitsSize +
totalOrgSize + nonOrgsSize + metaSize;
console.log(`total: ${toMB(totalSize)}`);
console.log(`\n=> ${toKB(totalSize / numUsers)}/user`);
return;
function toKB(bytes) {
return `${Math.round(bytes / 1024)} KB`;
}
function toMB(bytes) {
return `${Math.round(bytes / 1024 / 1024)} MB`;
}
}
})();