refactor(metrics/insights): new features (#1098)
This commit is contained in:
@@ -55,6 +55,10 @@
|
||||
methods: {
|
||||
format(type, value, options) {
|
||||
switch (type) {
|
||||
case "plural":
|
||||
if (options?.y)
|
||||
return (value !== 1) ? "ies" : "y"
|
||||
return (value !== 1) ? "s" : ""
|
||||
case "number":
|
||||
return new Intl.NumberFormat(navigator.lang, options).format(value)
|
||||
case "date":
|
||||
@@ -74,6 +78,14 @@
|
||||
RegExp(baseUrl + String.raw`compare\/([\w-.]+...[\w-.]+)(?=<)`, "g"),
|
||||
(_, repo, tags) => (options?.repo === repo ? "" : repo + "@") + tags,
|
||||
) // -> 'lowlighter/metrics@1.0...1.1'
|
||||
.replace(
|
||||
/(?<!&)#(\d+)/g,
|
||||
(_, id) => `<a href="https://github.com/${options?.repo}/issues/${id}">#${id}</a>`,
|
||||
) // -> #123
|
||||
.replace(
|
||||
/@([-\w]+)/g,
|
||||
(_, user) => `<a href="https://github.com/${user}">@${user}</a>`,
|
||||
) // -> @user
|
||||
}
|
||||
return value
|
||||
},
|
||||
@@ -86,7 +98,40 @@
|
||||
this.metrics = JSON.parse(localStorage.getItem("local.metrics") ?? "null")
|
||||
return
|
||||
}
|
||||
this.metrics = (await axios.get(`/about/query/${this.user}`)).data
|
||||
const {processing, ...data} = (await axios.get(`/about/query/${this.user}`)).data
|
||||
if (processing) {
|
||||
let completed = 0
|
||||
this.progress = 1/(data.plugins.length+1)
|
||||
this.loaded = []
|
||||
const retry = async (plugin, attempts = 60, interval = 10) => {
|
||||
if (this.loaded.includes(plugin))
|
||||
return
|
||||
do {
|
||||
try {
|
||||
const {data} = await axios.get(`/about/query/${this.user}/${plugin}`)
|
||||
if (!data)
|
||||
throw new Error(`${plugin}: no data`)
|
||||
if (plugin === "base")
|
||||
this.metrics = {rendered:data, mime:"application/json", errors:[]}
|
||||
else
|
||||
Object.assign(this.metrics.rendered.plugins, {[plugin]:data})
|
||||
break
|
||||
}
|
||||
catch {
|
||||
console.warn(`${plugin}: no data yet, retrying in ${interval} seconds`)
|
||||
await new Promise(solve => setTimeout(solve, interval*1000))
|
||||
}
|
||||
} while (--attempts)
|
||||
completed++
|
||||
this.progress = completed/(data.plugins.length+1)
|
||||
this.loaded.push(plugin)
|
||||
}
|
||||
await retry("base", 30, 5)
|
||||
await Promise.allSettled(data.plugins.map(plugin => retry(plugin)))
|
||||
}
|
||||
else {
|
||||
this.metrics = data
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this.error = {code: error.response.status, message: error.response.data}
|
||||
@@ -103,23 +148,39 @@
|
||||
},
|
||||
//Computed properties
|
||||
computed: {
|
||||
stats() {
|
||||
return this.metrics?.rendered.user ?? null
|
||||
},
|
||||
sponsors() {
|
||||
return this.metrics?.rendered.plugins?.sponsors ?? null
|
||||
},
|
||||
ranked() {
|
||||
return this.metrics?.rendered.plugins.achievements.list?.filter(({leaderboard}) => leaderboard).sort((a, b) => a.leaderboard.type.localeCompare(b.leaderboard.type)) ?? []
|
||||
return this.metrics?.rendered.plugins?.achievements?.list?.filter(({leaderboard}) => leaderboard).sort((a, b) => a.leaderboard.type.localeCompare(b.leaderboard.type)) ?? []
|
||||
},
|
||||
achievements() {
|
||||
return this.metrics?.rendered.plugins.achievements.list?.filter(({leaderboard}) => !leaderboard).filter(({title}) => !/(?:automator|octonaut|infographile)/i.test(title)) ?? []
|
||||
return this.metrics?.rendered.plugins?.achievements?.list?.filter(({leaderboard}) => !leaderboard).filter(({title}) => !/(?:automator|octonaut|infographile)/i.test(title)) ?? []
|
||||
},
|
||||
introduction() {
|
||||
return this.metrics?.rendered.plugins.introduction?.text ?? ""
|
||||
return this.metrics?.rendered.plugins?.introduction?.text ?? ""
|
||||
},
|
||||
followup() {
|
||||
return this.metrics?.rendered.plugins.followup ?? null
|
||||
return this.metrics?.rendered.plugins?.followup ?? null
|
||||
},
|
||||
habits() {
|
||||
return this.metrics?.rendered.plugins.habits.commits.hours ?? null
|
||||
calendar() {
|
||||
if (this.metrics?.rendered.plugins?.calendar)
|
||||
return Object.assign(this.metrics?.rendered.plugins?.calendar, {color(c) {
|
||||
return {
|
||||
"#ebedf0":"var(--color-calendar-graph-day-bg)",
|
||||
"#9be9a8":"var(--color-calendar-graph-day-L1-bg)",
|
||||
"#40c463":"var(--color-calendar-graph-day-L2-bg)",
|
||||
"#30a14e":"var(--color-calendar-graph-day-L3-bg)",
|
||||
"#216e39":"var(--color-calendar-graph-day-L4-bg)",
|
||||
}[c] ?? c
|
||||
}})
|
||||
return null
|
||||
},
|
||||
isocalendar() {
|
||||
return (this.metrics?.rendered.plugins.isocalendar.svg ?? "")
|
||||
return (this.metrics?.rendered.plugins?.isocalendar?.svg ?? "")
|
||||
.replace(/#ebedf0/gi, "var(--color-calendar-graph-day-bg)")
|
||||
.replace(/#9be9a8/gi, "var(--color-calendar-graph-day-L1-bg)")
|
||||
.replace(/#40c463/gi, "var(--color-calendar-graph-day-L2-bg)")
|
||||
@@ -127,19 +188,31 @@
|
||||
.replace(/#216e39/gi, "var(--color-calendar-graph-day-L4-bg)")
|
||||
},
|
||||
languages() {
|
||||
return this.metrics?.rendered.plugins.languages.favorites ?? []
|
||||
return Object.assign(this.metrics?.rendered.plugins?.languages?.favorites ?? [], {total:this.metrics?.rendered.plugins?.languages.total})
|
||||
},
|
||||
reactions() {
|
||||
return this.metrics?.rendered.plugins?.reactions ?? null
|
||||
},
|
||||
repositories() {
|
||||
return this.metrics?.rendered.plugins?.repositories?.list ?? []
|
||||
},
|
||||
stars() {
|
||||
return {repositories:this.metrics?.rendered.plugins?.stars?.repositories.map(({node, starredAt}) => ({...node, starredAt})) ?? []}
|
||||
},
|
||||
topics() {
|
||||
return this.metrics?.rendered.plugins?.topics?.list ?? []
|
||||
},
|
||||
activity() {
|
||||
return this.metrics?.rendered.plugins.activity.events ?? []
|
||||
return this.metrics?.rendered.plugins?.activity?.events ?? []
|
||||
},
|
||||
contributions() {
|
||||
return this.metrics?.rendered.plugins.notable.contributions ?? []
|
||||
return this.metrics?.rendered.plugins?.notable?.contributions ?? []
|
||||
},
|
||||
account() {
|
||||
if (!this.metrics)
|
||||
return null
|
||||
const {login, name} = this.metrics.rendered.user
|
||||
return {login, name, avatar: this.metrics.rendered.computed.avatar, type: this.metrics?.rendered.account}
|
||||
const {login, name} = this.metrics?.rendered.user
|
||||
return {login, name, avatar: this.metrics?.rendered.computed.avatar, type: this.metrics?.rendered.account}
|
||||
},
|
||||
url() {
|
||||
return `${window.location.protocol}//${window.location.host}/about/${this.user}`
|
||||
@@ -166,6 +239,8 @@
|
||||
pending: false,
|
||||
error: null,
|
||||
config: {},
|
||||
progress: 0,
|
||||
loaded: []
|
||||
},
|
||||
})
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user