This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyze.js
76 lines (59 loc) · 1.6 KB
/
analyze.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
// * analyze.js: Analyze as it name suggests and save to csv
import * as fs from "fs/promises";
let langObj = {};
try {
const buffer = await fs.readFile("data/data.json");
langObj = JSON.parse(buffer.toString());
} catch (err) {
console.log("data.json not found");
process.exit(1);
}
let langCounter = {};
for (const repo in langObj) {
const langStats = langObj[repo];
for (const lang in langStats) {
if (langCounter[lang]) {
langCounter[lang] += parseInt(langStats[lang]);
} else {
langCounter[lang] = parseInt(langStats[lang]);
}
}
}
const sorted = Object.entries(langCounter).sort(([, a], [, b]) => b - a);
const languages = [];
sorted.map((lang) => {
languages.push(lang[0]);
});
console.log(langCounter);
let CSVWrite = "name,";
for (const lang of languages) {
CSVWrite += `${lang},`;
}
CSVWrite += "Total,\n";
for (const reponame in langObj) {
let totalThisRepo = 0;
const repolang = langObj[reponame];
CSVWrite += `${reponame},`;
for (const lang of languages) {
if (repolang[lang]) {
CSVWrite += `${repolang[lang].toString()},`;
totalThisRepo += repolang[lang];
} else {
CSVWrite += "0,";
}
}
CSVWrite += `${totalThisRepo},\n`;
}
CSVWrite += "Total,";
let totalポイッ = 0;
for (const lang of sorted) {
CSVWrite += `${lang[1]},`;
totalポイッ += lang[1];
}
CSVWrite += `${totalポイッ},\n`;
CSVWrite += "Percentage,";
for (const lang of sorted)
CSVWrite += `${((100 * lang[1]) / totalポイッ).toFixed(2)},`;
CSVWrite += "100.00,\n";
await fs.writeFile("data/lang.csv", CSVWrite);
console.log("Convert to CSV Success");