Add bar charts

This commit is contained in:
Matan Kushner
2019-03-17 16:22:53 -04:00
parent 175ccf3141
commit e93bd4fb04

View File

@@ -26,20 +26,25 @@ async function updateGist(stats) {
} catch (error) { } catch (error) {
console.error(`Unable to get gist\n${error}`); console.error(`Unable to get gist\n${error}`);
} }
// Get original filename to update that same file
const filename = Object.keys(gist.data.files)[0];
const lines = []; const lines = [];
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
const data = stats.data.languages[i]; const data = stats.data.languages[i];
const name = data.name.padEnd(10); const { name, percent, text: time } = data;
const percent = data.percent;
const time = data.text;
lines.push(`${name} - ${time}`); const line = [
name.padEnd(11),
time.padEnd(14),
generateBarChart(percent, 12),
String(percent.toFixed(1)).padStart(5) + "%"
];
lines.push(line.join(" "));
} }
try { try {
// Get original filename to update that same file
const filename = Object.keys(gist.data.files)[0];
await octokit.gists.update({ await octokit.gists.update({
gist_id: gistId, gist_id: gistId,
files: { files: {
@@ -54,6 +59,13 @@ async function updateGist(stats) {
} }
} }
function generateBarChart(percent, size) {
const empty = "░";
const full = "█";
const barsFull = Math.round(size * (percent / 100));
return full.repeat(barsFull).padEnd(size, empty);
}
(async () => { (async () => {
await main(); await main();
})(); })();