Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins/habits): add plugin_habits_languages_threshold #1138

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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%