chore: code formatting
This commit is contained in:
@@ -7,11 +7,11 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {"charts.type":_charts} = imports.metadata.plugins.stargazers.inputs({data, account, q})
|
||||
let {"charts.type": _charts} = imports.metadata.plugins.stargazers.inputs({data, account, q})
|
||||
|
||||
//Retrieve stargazers from graphql api
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > querying api`)
|
||||
const repositories = data.user.repositories.nodes.map(({name:repository, owner:{login:owner}}) => ({repository, owner})) ?? []
|
||||
const repositories = data.user.repositories.nodes.map(({name: repository, owner: {login: owner}}) => ({repository, owner})) ?? []
|
||||
const dates = []
|
||||
for (const {repository, owner} of repositories) {
|
||||
//Iterate through stargazers
|
||||
@@ -20,7 +20,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository} after ${cursor}`)
|
||||
const {repository:{stargazers:{edges}}} = await graphql(queries.stargazers({login:owner, repository, after:cursor ? `after: "${cursor}"` : ""}))
|
||||
const {repository: {stargazers: {edges}}} = await graphql(queries.stargazers({login: owner, repository, after: cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
dates.push(...edges.map(({starredAt}) => new Date(starredAt)))
|
||||
pushed = edges.length
|
||||
@@ -32,7 +32,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
|
||||
//Compute stargazers increments
|
||||
const days = 14 * (1 + data.large / 2)
|
||||
const increments = {dates:Object.fromEntries([...new Array(days).fill(null).map((_, i) => [new Date(Date.now() - i * 24 * 60 * 60 * 1000).toISOString().slice(0, 10), 0]).reverse()]), max:NaN, min:NaN}
|
||||
const increments = {dates: Object.fromEntries([...new Array(days).fill(null).map((_, i) => [new Date(Date.now() - i * 24 * 60 * 60 * 1000).toISOString().slice(0, 10), 0]).reverse()]), max: NaN, min: NaN}
|
||||
dates
|
||||
.map(date => date.toISOString().slice(0, 10))
|
||||
.filter(date => date in increments.dates)
|
||||
@@ -42,12 +42,12 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
|
||||
//Compute total stargazers
|
||||
let {stargazers} = data.computed.repositories
|
||||
const total = {dates:{...increments.dates}, max:NaN, min:NaN}
|
||||
const total = {dates: {...increments.dates}, max: NaN, min: NaN}
|
||||
{
|
||||
const dates = Object.keys(total.dates)
|
||||
for (let i = dates.length - 1; i >= 0; i--) {
|
||||
const date = dates[i], tomorrow = dates[i + 1]
|
||||
stargazers -= (increments.dates[tomorrow] ?? 0)
|
||||
stargazers -= increments.dates[tomorrow] ?? 0
|
||||
total.dates[date] = stargazers
|
||||
}
|
||||
}
|
||||
@@ -61,22 +61,23 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
let charts = null
|
||||
if (_charts === "chartist") {
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > generating charts`)
|
||||
charts = await Promise.all([{data:total, low:total.min, high:total.max}, {data:increments, ref:0, low:increments.min, high:increments.max, sign:true}].map(({data:{dates:set}, high, low, ref, sign = false}) => imports.chartist("line", {
|
||||
width:480 * (1 + data.large),
|
||||
height:160,
|
||||
showPoint:true,
|
||||
axisX:{showGrid:false},
|
||||
axisY:{showLabel:false, offset:20, labelInterpolationFnc:value => imports.format(value, {sign}), high, low, referenceValue:ref},
|
||||
showArea:true,
|
||||
fullWidth:true,
|
||||
charts = await Promise.all([{data: total, low: total.min, high: total.max}, {data: increments, ref: 0, low: increments.min, high: increments.max, sign: true}].map(({data: {dates: set}, high, low, ref, sign = false}) =>
|
||||
imports.chartist("line", {
|
||||
width: 480 * (1 + data.large),
|
||||
height: 160,
|
||||
showPoint: true,
|
||||
axisX: {showGrid: false},
|
||||
axisY: {showLabel: false, offset: 20, labelInterpolationFnc: value => imports.format(value, {sign}), high, low, referenceValue: ref},
|
||||
showArea: true,
|
||||
fullWidth: true,
|
||||
}, {
|
||||
labels:Object.keys(set).map((date, i, a) => {
|
||||
labels: Object.keys(set).map((date, i, a) => {
|
||||
const day = date.substring(date.length - 2)
|
||||
if ((i === 0) || ((a[i - 1]) && (date.substring(0, 7) !== a[i - 1].substring(0, 7))))
|
||||
return `${day} ${months[Number(date.substring(5, 7))]}`
|
||||
return day
|
||||
}),
|
||||
series:[Object.values(set)],
|
||||
series: [Object.values(set)],
|
||||
})
|
||||
))
|
||||
data.postscripts.push(`(${function(format) {
|
||||
@@ -99,6 +100,6 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user