feat(plugins/leetcode): add plugin (#1213) [skip ci]
This commit is contained in:
12
source/plugins/leetcode/README.md
Normal file
12
source/plugins/leetcode/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
<!--header-->
|
||||
<!--/header-->
|
||||
|
||||
## ➡️ Available options
|
||||
|
||||
<!--options-->
|
||||
<!--/options-->
|
||||
|
||||
## ℹ️ Examples workflows
|
||||
|
||||
<!--examples-->
|
||||
<!--/examples-->
|
||||
8
source/plugins/leetcode/examples.yml
Normal file
8
source/plugins/leetcode/examples.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
- name: LeetCode
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
filename: metrics.plugin.leetcode.svg
|
||||
token: NOT_NEEDED
|
||||
base: ""
|
||||
plugin_leetcode: yes
|
||||
plugin_leetcode_sections: solved, skills, recent
|
||||
54
source/plugins/leetcode/index.mjs
Normal file
54
source/plugins/leetcode/index.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!q.leetcode) || (!imports.metadata.plugins.leetcode.enabled(enabled, {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {user, sections, "limit.skills":_limit_skills, "limit.recent":_limit_recent} = imports.metadata.plugins.leetcode.inputs({data, account, q})
|
||||
const result = {user, sections, languages:[], skills:[], problems:{}, recent:[]}
|
||||
|
||||
//Languages stats
|
||||
{
|
||||
console.debug(`metrics/compute/${login}/plugins > leetcode > querying api (languages statistics)`)
|
||||
const {data:{data:{matchedUser:{languageProblemCount:languages}}}} = await imports.axios.post("https://leetcode.com/graphql", {variables: {username: user}, query: queries.leetcode.languages()})
|
||||
result.languages = languages.map(({languageName:language, problemsSolved:solved}) => ({language, solved}))
|
||||
}
|
||||
|
||||
//Skills stats
|
||||
{
|
||||
console.debug(`metrics/compute/${login}/plugins > leetcode > querying api (skills statistics)`)
|
||||
const {data:{data:{matchedUser:{tagProblemCounts:skills}}}} = await imports.axios.post("https://leetcode.com/graphql", {variables: {username: user}, query: queries.leetcode.skills()})
|
||||
for (const category in skills)
|
||||
result.skills.push(...skills[category].map(({tagName:name, problemsSolved:solved}) => ({name, solved, category})))
|
||||
result.skills.sort((a, b) => b.solved - a.solved)
|
||||
result.skills = result.skills.slice(0, _limit_skills || Infinity)
|
||||
}
|
||||
|
||||
//Problems
|
||||
{
|
||||
console.debug(`metrics/compute/${login}/plugins > leetcode > querying api (problems statistics)`)
|
||||
const {data:{data:{allQuestionsCount:all, matchedUser:{submitStatsGlobal:{acSubmissionNum:submissions}}}}} = await imports.axios.post("https://leetcode.com/graphql", {variables: {username: user}, query: queries.leetcode.problems()})
|
||||
for (const {difficulty, count} of all)
|
||||
result.problems[difficulty] = {count, solved:0}
|
||||
for (const {difficulty, count:solved} of submissions)
|
||||
result.problems[difficulty].solved = solved
|
||||
}
|
||||
|
||||
//Recent submissions
|
||||
{
|
||||
console.debug(`metrics/compute/${login}/plugins > leetcode > querying api (recent submissions statistics)`)
|
||||
const {data:{data:{recentAcSubmissionList:submissions}}} = await imports.axios.post("https://leetcode.com/graphql", {variables: {username: user, limit:_limit_recent}, query: queries.leetcode.recent()})
|
||||
result.recent = submissions.map(({title, timestamp}) => ({title, date:new Date(timestamp*1000)}))
|
||||
}
|
||||
|
||||
//Results
|
||||
return result
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
59
source/plugins/leetcode/metadata.yml
Normal file
59
source/plugins/leetcode/metadata.yml
Normal file
@@ -0,0 +1,59 @@
|
||||
name: 🗳️ Leetcode
|
||||
category: social
|
||||
description: |
|
||||
This plugin displays statistics from a [LeetCode](https://leetcode.com) account.
|
||||
disclaimer: |
|
||||
This plugin is not affiliated, associated, authorized, endorsed by, or in any way officially connected with [LeetCode](https://leetcode.com).
|
||||
All product and company names are trademarks™ or registered® trademarks of their respective holders.
|
||||
examples:
|
||||
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.leetcode.svg
|
||||
index: 9
|
||||
supports:
|
||||
- user
|
||||
scopes: []
|
||||
inputs:
|
||||
|
||||
plugin_leetcode:
|
||||
description: |
|
||||
Enable leetcode plugin
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
plugin_leetcode_user:
|
||||
type: string
|
||||
description: |
|
||||
LeetCode login
|
||||
default: .user.login
|
||||
preset: no
|
||||
|
||||
plugin_leetcode_sections:
|
||||
description: |
|
||||
Displayed sections
|
||||
|
||||
- `solved` will display solved problems scores
|
||||
- `skills` will display solved problems tagged skills
|
||||
- `recent` will display recent submissions
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: solved
|
||||
example: solved, skills, recent
|
||||
values:
|
||||
- solved
|
||||
- skills
|
||||
- recent
|
||||
|
||||
plugin_leetcode_limit_skills:
|
||||
description: |
|
||||
Display limit (skills)
|
||||
type: number
|
||||
default: 10
|
||||
min: 0
|
||||
zero: disable
|
||||
|
||||
plugin_leetcode_limit_recent:
|
||||
description: |
|
||||
Display limit (recent)
|
||||
type: number
|
||||
default: 2
|
||||
min: 1
|
||||
max: 15
|
||||
8
source/plugins/leetcode/queries/languages.graphql
Normal file
8
source/plugins/leetcode/queries/languages.graphql
Normal file
@@ -0,0 +1,8 @@
|
||||
query Languages ($username: String!) {
|
||||
matchedUser(username: $username) {
|
||||
languageProblemCount {
|
||||
languageName
|
||||
problemsSolved
|
||||
}
|
||||
}
|
||||
}
|
||||
18
source/plugins/leetcode/queries/problems.graphql
Normal file
18
source/plugins/leetcode/queries/problems.graphql
Normal file
@@ -0,0 +1,18 @@
|
||||
query Problems ($username: String!) {
|
||||
allQuestionsCount {
|
||||
difficulty
|
||||
count
|
||||
}
|
||||
matchedUser(username: $username) {
|
||||
problemsSolvedBeatsStats {
|
||||
difficulty
|
||||
percentage
|
||||
}
|
||||
submitStatsGlobal {
|
||||
acSubmissionNum {
|
||||
difficulty
|
||||
count
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
source/plugins/leetcode/queries/recent.graphql
Normal file
8
source/plugins/leetcode/queries/recent.graphql
Normal file
@@ -0,0 +1,8 @@
|
||||
query Recent ($username: String!, $limit: Int!) {
|
||||
recentAcSubmissionList(username: $username, limit: $limit) {
|
||||
id
|
||||
title
|
||||
titleSlug
|
||||
timestamp
|
||||
}
|
||||
}
|
||||
18
source/plugins/leetcode/queries/skills.graphql
Normal file
18
source/plugins/leetcode/queries/skills.graphql
Normal file
@@ -0,0 +1,18 @@
|
||||
query Skills ($username: String!) {
|
||||
matchedUser(username: $username) {
|
||||
tagProblemCounts {
|
||||
advanced {
|
||||
tagName
|
||||
problemsSolved
|
||||
}
|
||||
intermediate {
|
||||
tagName
|
||||
problemsSolved
|
||||
}
|
||||
fundamental {
|
||||
tagName
|
||||
problemsSolved
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user