refactor(metrics/insights): new features (#1098)

This commit is contained in:
Simon Lecoq
2022-06-24 22:35:09 +02:00
committed by GitHub
parent 79b80b1900
commit 3c4402e4ba
10 changed files with 732 additions and 142 deletions

View File

@@ -4,7 +4,7 @@
*/
//Setup
export default async function({login, graphql, rest, data, q, queries, imports}, conf) {
export default async function({login, graphql, rest, data, q, queries, imports, callbacks}, conf) {
//Load inputs
console.debug(`metrics/compute/${login}/base > started`)
let {indepth, hireable, "repositories.forks": _forks, "repositories.affiliations": _affiliations, "repositories.batch": _batch} = imports.metadata.plugins.base.inputs({data, q, account: "bypass"})
@@ -15,8 +15,10 @@ export default async function({login, graphql, rest, data, q, queries, imports},
console.debug(`metrics/compute/${login}/base > affiliations constraints ${affiliations}`)
//Skip initial data gathering if not needed
if (conf.settings.notoken)
if (conf.settings.notoken) {
await callbacks?.plugin?.(login, "base", true, data).catch(error => console.debug(`metrics/compute/${login}/plugins/callbacks > base > ${error}`))
return (postprocess.skip({login, data, imports}), {})
}
//Base parts (legacy handling for web instance)
const defaulted = ("base" in q) ? legacy.converter(q.base) ?? true : true
@@ -194,6 +196,7 @@ export default async function({login, graphql, rest, data, q, queries, imports},
console.debug(`metrics/compute/${login}/base > shared options > ${JSON.stringify(data.shared)}`)
//Success
console.debug(`metrics/compute/${login}/base > graphql query > account ${account} > success`)
await callbacks?.plugin?.(login, "base", true, data).catch(error => console.debug(`metrics/compute/${login}/plugins/callbacks > base > ${error}`))
return {}
}
catch (error) {
@@ -208,6 +211,7 @@ export default async function({login, graphql, rest, data, q, queries, imports},
}
//Not found
console.debug(`metrics/compute/${login}/base > no more account type`)
await callbacks?.plugin?.(login, "base", false, data).catch(error => console.debug(`metrics/compute/${login}/plugins/callbacks > base > ${error}`))
throw new Error("user not found")
}

View File

@@ -29,6 +29,14 @@
token: ${{ secrets.METRICS_TOKEN }}
config_output: png
- name: Metrics insights
if: ${{ success() || failure() }}
uses: lowlighter/metrics@latest
with:
filename: metrics.insights.html
token: ${{ secrets.METRICS_TOKEN }}
config_output: insights
- name: Presets
uses: lowlighter/metrics@latest
with:

View File

@@ -4,7 +4,7 @@
*/
//Setup
export default async function({login, q}, {conf, data, rest, graphql, plugins, queries, account, convert, template}, {pending, imports}) {
export default async function({login, q}, {conf, data, rest, graphql, plugins, queries, account, convert, template, callbacks}, {pending, imports}) {
//Load inputs
const {"config.animations": animations, "config.display": display, "config.timezone": _timezone, "config.base64": _base64, "debug.flags": dflags} = imports.metadata.plugins.core.inputs({data, account, q})
imports.metadata.templates[template].check({q, account, format: convert})
@@ -70,6 +70,7 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q
finally {
const result = {name, result: data.plugins[name]}
console.debug(imports.util.inspect(result, {depth: Infinity, maxStringLength: 256, getters: true}))
await callbacks?.plugin?.(login, name, !data.plugins[name].error, data.plugins[name]).catch(error => console.debug(`metrics/compute/${login}/plugins/callbacks > ${name} > ${error}`))
return result
}
})())

View File

@@ -52,8 +52,11 @@ export default async function({login, q, imports, data, graphql, queries, accoun
for (const [key, value] of Object.entries(list))
list[key] = {value, percentage: value / reactions.length, score: value / (display === "relative" ? max : reactions.length)}
//Compute total reactions
const total = Object.values(list).map(({value}) => value).reduce((a, b) => a + b, 0)
//Results
return {list, comments: comments.length, details, days, twemoji: q["config.twemoji"]}
return {list, total, comments: comments.length, details, days, twemoji: q["config.twemoji"]}
}
//Handle errors
catch (error) {

View File

@@ -32,6 +32,7 @@ export default async function({login, data, imports, q, account}, {enabled = fal
name: li.querySelector(".f3").innerText,
description: li.querySelector(".f5").innerText,
icon: li.querySelector("img")?.src ?? null,
url: li.querySelector("a")?.href ?? null,
}))
)
console.debug(`metrics/compute/${login}/plugins > topics > extracted ${starred.length} starred topics`)