feat(plugins/habits): add plugin_habits_languages_threshold (#1138) [skip ci]

This commit is contained in:
Simon Lecoq
2022-07-21 04:44:34 +02:00
committed by GitHub
parent 17bddd1224
commit 12372cbc84
2 changed files with 10 additions and 3 deletions

View File

@@ -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: {}}}
@@ -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`)

View File

@@ -86,3 +86,9 @@ inputs:
min: 0
max: 8
zero: disable
plugin_habits_languages_threshold:
description: |
Display threshold (percentage)
type: string
default: 0%