Skip to content

Commit

Permalink
feat(plugins/habits): add plugin_habits_languages_threshold (#1138)…
Browse files Browse the repository at this point in the history
… [skip ci]
  • Loading branch information
lowlighter committed Jul 21, 2022
1 parent 17bddd1 commit 12372cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions source/plugins/habits/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default async function({login, data, rest, imports, q, account}, {enabled
return null

//Load inputs
let {from, days, facts, charts, "charts.type": _charts, trim, "languages.limit": limit} = imports.metadata.plugins.habits.inputs({data, account, q}, defaults)
let {from, days, facts, charts, "charts.type": _charts, trim, "languages.limit": limit, "languages.threshold": threshold} = imports.metadata.plugins.habits.inputs({data, account, q}, defaults)
threshold = (Number(threshold.replace(/%$/, "")) || 0) / 100

//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 +106,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).slice(0, limit || Infinity)
habits.linguist.ordered = Object.entries(habits.linguist.languages).sort(([_an, a], [_bn, b]) => b - a).filter(([_, value]) => value > threshold).slice(0, limit || Infinity)
}
else {
console.debug(`metrics/compute/${login}/plugins > habits > linguist not available`)
Expand Down
8 changes: 7 additions & 1 deletion source/plugins/habits/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ inputs:
default: 8
min: 0
max: 8
zero: disable
zero: disable

plugin_habits_languages_threshold:
description: |
Display threshold (percentage)
type: string
default: 0%

0 comments on commit 12372cb

Please sign in to comment.