From 5f5357bab8350fed36e99d94b954816514c9b074 Mon Sep 17 00:00:00 2001 From: Jayant Goel Date: Mon, 27 Jun 2022 02:41:47 +0530 Subject: [PATCH] feat(plugins/habits): added limit option in habit languages (#1112) --- source/plugins/habits/index.mjs | 4 ++-- source/plugins/habits/metadata.yml | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/plugins/habits/index.mjs b/source/plugins/habits/index.mjs index d6349ec4873..2eca5defd13 100644 --- a/source/plugins/habits/index.mjs +++ b/source/plugins/habits/index.mjs @@ -10,7 +10,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled return null //Load inputs - let {from, days, facts, charts, "charts.type": _charts, trim} = imports.metadata.plugins.habits.inputs({data, account, q}, defaults) + let {from, days, facts, charts, "charts.type": _charts, trim, "languages.limit": limit} = imports.metadata.plugins.habits.inputs({data, account, q}, defaults) //Initialization const habits = {facts, charts, trim, lines: {average: {chars: 0}}, commits: {fetched: 0, hour: NaN, hours: {}, day: NaN, days: {}}, indents: {style: "", spaces: 0, tabs: 0}, linguist: {available: false, ordered: [], languages: {}}} @@ -105,7 +105,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled habits.linguist.available = true const {total, stats} = await recent_analyzer({login, data, imports, rest, account}, {days, load: from || 1000, tempdir: "habits"}) habits.linguist.languages = Object.fromEntries(Object.entries(stats).map(([language, value]) => [language, value / total])) - habits.linguist.ordered = Object.entries(habits.linguist.languages).sort(([_an, a], [_bn, b]) => b - a) + habits.linguist.ordered = Object.entries(habits.linguist.languages).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit || Infinity) } else { console.debug(`metrics/compute/${login}/plugins > habits > linguist not available`) diff --git a/source/plugins/habits/metadata.yml b/source/plugins/habits/metadata.yml index cf09459fa2f..3bfd6b54b38 100644 --- a/source/plugins/habits/metadata.yml +++ b/source/plugins/habits/metadata.yml @@ -67,3 +67,11 @@ inputs: description: Trim unused hours on charts type: boolean default: no + + plugin_habits_languages_limit: + description: Limits the number of languages to be displayed + type: number + default: 8 + min: 0 + max: 8 + zero: disable \ No newline at end of file