Skip to content

Commit

Permalink
feat(plugins/habits): added limit option in habit languages (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayantGoel001 authored Jun 26, 2022
1 parent 005a9d6 commit 5f5357b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/plugins/habits/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}}}
Expand Down Expand Up @@ -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`)
Expand Down
8 changes: 8 additions & 0 deletions source/plugins/habits/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5f5357b

Please sign in to comment.