Load all language colours (#467)

This commit is contained in:
Nixinova
2021-08-20 06:13:48 +12:00
committed by GitHub
parent 1a520745cc
commit 359ff46780
5 changed files with 32 additions and 21 deletions

View File

@@ -60,7 +60,7 @@ For better results, it's advised to add either your surnames and eventually no-r
plugin_languages_sections: most-used, recently-used # Display most used and recently used languages stats
plugin_languages_indepth: no # Get indepth stats (see documentation before enabling)
plugin_languages_categories: programming # Display only languages that match these categories in most-used section
plugin_languages_categories: markup, programming, data # Display only languages that match these categories in recently-used section
plugin_languages_recent_categories: markup, programming, data # Display only languages that match these categories in recently-used section
plugin_languages_recent_load: 500 # Load up to 500 events to compute recently used stats
plugin_languages_recent_days: 7 # Limit recently used stats to last week
commits_authoring: lowlighter@users.noreply.github.com # Surnames or email addresses used to identify your commits

View File

@@ -4,7 +4,7 @@ import linguist from "linguist-js"
export async function indepth({login, data, imports, repositories}, {skipped, categories}) {
//Compute repositories stats from fetched repositories
const results = {total:0, lines:{}, stats:{}, commits:0, files:0, missed:0}
const results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:0}
for (const repository of repositories) {
//Skip repository if asked
if ((skipped.includes(repository.name.toLocaleLowerCase())) || (skipped.includes(`${repository.owner.login}/${repository.name}`.toLocaleLowerCase()))) {
@@ -48,7 +48,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
//Get user recent activity
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
const commits = [], pages = Math.ceil(load/100), results = {total:0, lines:{}, stats:{}, commits:0, files:0, missed:0, days}
const commits = [], pages = Math.ceil(load/100), results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:0, days}
try {
for (let page = 1; page <= pages; page++) {
console.debug(`metrics/compute/${login}/plugins > languages > loading page ${page}`)
@@ -140,6 +140,7 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
//Gather language data
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
const {results:files, languages:languageResults} = await linguist(path)
Object.assign(results.colors, Object.fromEntries(Object.entries(languageResults.all).map(([lang, {color}]) => [lang, color])))
//Processing diff
const per_page = 1
@@ -212,7 +213,7 @@ if (/languages.analyzers.mjs$/.test(process.argv[1])) {
//Prepare call
const imports = await import("../../app/metrics/utils.mjs")
const results = {total:0, lines:{}, stats:{}, missed:0}
const results = {total:0, lines:{}, colors:{}, stats:{}, missed:0}
console.debug = log => /exited with code null/.test(log) ? console.error(log.replace(/^.*--max-count=(?<step>\d+) --skip=(?<start>\d+).*$/, (_, step, start) => `error: skipped commits ${start} from ${Number(start)+Number(step)}`)) : null
//Analyze repository

View File

@@ -38,6 +38,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
//Iterate through user's repositories and retrieve languages data
console.debug(`metrics/compute/${login}/plugins > languages > processing ${data.user.repositories.nodes.length} repositories`)
const languages = {unique, sections, details, indepth, colors:{}, total:0, stats:{}, "stats.recent":{}}
const customColors = {}
for (const repository of data.user.repositories.nodes) {
//Skip repository if asked
if ((skipped.includes(repository.name.toLocaleLowerCase())) || (skipped.includes(`${repository.owner.login}/${repository.name}`.toLocaleLowerCase()))) {
@@ -47,7 +48,10 @@ export default async function({login, data, imports, q, rest, account}, {enabled
//Process repository languages
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
languages.stats[name] = (languages.stats[name] ?? 0) + size
languages.colors[name] = colors[name.toLocaleLowerCase()] ?? color ?? "#ededed"
if (colors[name.toLocaleLowerCase()])
customColors[name] = colors[name.toLocaleLowerCase()]
if (!languages.colors[name])
languages.colors[name] = color
languages.total += size
}
}
@@ -58,12 +62,15 @@ export default async function({login, data, imports, q, rest, account}, {enabled
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, categories:_recent_categories ?? categories, days:_recent_days, load:_recent_load})
Object.assign(languages.colors, languages["stats.recent"].colors)
}
//Indepth mode
if (indepth) {
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
const existingColors = languages.colors
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped, categories}))
Object.assign(languages.colors, existingColors)
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
}
}
@@ -74,11 +81,14 @@ export default async function({login, data, imports, q, rest, account}, {enabled
languages[section] = Object.entries(stats).filter(([name]) => !ignored.includes(name.toLocaleLowerCase())).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size:value, color:languages.colors[name], x:0})).filter(({value}) => value / total > threshold)
const visible = {total:Object.values(languages[section]).map(({size}) => size).reduce((a, b) => a + b, 0)}
for (let i = 0; i < languages[section].length; i++) {
const {name} = languages[section][i]
languages[section][i].value /= visible.total
languages[section][i].x = (languages[section][i - 1]?.x ?? 0) + (languages[section][i - 1]?.value ?? 0)
languages[section][i].lines = lines[languages[section][i].name] ?? 0
if ((colors[i]) && (!colors[languages[section][i].name.toLocaleLowerCase()]))
languages[section][i].lines = lines[name] ?? 0
if ((colors[i]) && (!colors[name.toLocaleLowerCase()]))
languages[section][i].color = colors[i]
else
languages[section][i].color = customColors[name] ?? languages.colors[name] ?? "#ededed"
}
}