A Neovim plugin enabling you to solve LeetCode problems.
feat(stats): progress bars
7 files changed, +189 -35
+3-0lua/leetcode-ui/component/group.lua
| @@ -21,6 +21,9 @@ function Group:append(cmp) | ||
| 21 | 21 | return self |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | +---@param opts lc-ui.Group.opts | |
| 25 | +function Group:set_opts(opts) self.opts = vim.tbl_deep_extend("force", self.opts, opts) end | |
| 26 | + | |
| 24 | 27 | ---@param layout lc-ui.Layout |
| 25 | 28 | function Group:draw(layout) |
| 26 | 29 | local components = vim.deepcopy(self.components) |
+12-9lua/leetcode/api/statistics.lua
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | local utils = require("leetcode.api.utils") |
| 2 | 2 | local config = require("leetcode.config") |
| 3 | +local log = require("leetcode.logger") | |
| 3 | 4 | |
| 4 | 5 | local statistics = {} |
| 5 | 6 | |
| @@ -38,13 +39,14 @@ function statistics.calendar(cb) | ||
| 38 | 39 | end) |
| 39 | 40 | end |
| 40 | 41 | |
| 42 | +---@param cb fun(res: lc.Stats.Res) | |
| 41 | 43 | function statistics.solved(cb) |
| 42 | 44 | local variables = { |
| 43 | 45 | username = config.auth.name, |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | local query = [[ |
| 47 | - query userProfileStatistics($username: String!, $year: Int) { | |
| 49 | + query userStatistics($username: String!, $year: Int) { | |
| 48 | 50 | allQuestionsCount { |
| 49 | 51 | difficulty |
| 50 | 52 | count |
| @@ -63,16 +65,14 @@ function statistics.solved(cb) | ||
| 63 | 65 | } |
| 64 | 66 | submission_calendar: submissionCalendar |
| 65 | 67 | } |
| 66 | - submit_stats: submitStats { | |
| 68 | + solved_beats: problemsSolvedBeatsStats { | |
| 69 | + difficulty | |
| 70 | + percentage | |
| 71 | + } | |
| 72 | + submit_stats: submitStatsGlobal { | |
| 67 | 73 | acSubmissionNum { |
| 68 | 74 | difficulty |
| 69 | 75 | count |
| 70 | - submissions | |
| 71 | - } | |
| 72 | - totalSubmissionNum { | |
| 73 | - difficulty | |
| 74 | - count | |
| 75 | - submissions | |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | } |
| @@ -81,9 +81,11 @@ function statistics.solved(cb) | ||
| 81 | 81 | |
| 82 | 82 | utils._query(query, variables, function(res) |
| 83 | 83 | local data = res.body.data |
| 84 | - local calendar = data["matchedUser"]["calendar"] | |
| 84 | + | |
| 85 | 85 | local questions_count = data["allQuestionsCount"] |
| 86 | + local calendar = data["matchedUser"]["calendar"] | |
| 86 | 87 | local submit_stats = data["matchedUser"]["submit_stats"] |
| 88 | + local solved_beats = data["matchedUser"]["solved_beats"] | |
| 87 | 89 | |
| 88 | 90 | calendar.submission_calendar = select(2, pcall(utils.decode, calendar.submission_calendar)) |
| 89 | 91 | |
| @@ -91,6 +93,7 @@ function statistics.solved(cb) | ||
| 91 | 93 | calendar = calendar, |
| 92 | 94 | questions_count = questions_count, |
| 93 | 95 | submit_stats = submit_stats, |
| 96 | + solved_beats = solved_beats, | |
| 94 | 97 | }) |
| 95 | 98 | end) |
| 96 | 99 | end |
+27-0lua/leetcode/api/types.lua
| @@ -329,3 +329,30 @@ | ||
| 329 | 329 | ---@field is_premium boolean |
| 330 | 330 | ---@field is_verified boolean |
| 331 | 331 | ---@field id integer |
| 332 | + | |
| 333 | +-------------------------------------------- | |
| 334 | +--- Statistics | |
| 335 | +-------------------------------------------- | |
| 336 | +---@class lc.Stats.CalendarData | |
| 337 | +---@field active_years table | |
| 338 | +---@field dcc_badges table | |
| 339 | +---@field streak number | |
| 340 | +---@field submission_calendar table | |
| 341 | +---@field total_active_days number | |
| 342 | + | |
| 343 | +---@class lc.Stats.QuestionCount | |
| 344 | +---@field count number | |
| 345 | +---@field difficulty string | |
| 346 | + | |
| 347 | +---@class lc.Stats.SolvedBeat | |
| 348 | +---@field difficulty string | |
| 349 | +---@field percentage number | |
| 350 | + | |
| 351 | +---@class lc.Stats.SubmissionStat | |
| 352 | +---@field acSubmissionNum table | |
| 353 | + | |
| 354 | +---@class lc.Stats.Res | |
| 355 | +---@field calendar lc.Stats.CalendarData | |
| 356 | +---@field questions_count table<lc.Stats.QuestionCount> | |
| 357 | +---@field solved_beats table<lc.Stats.SolvedBeat> | |
| 358 | +---@field submit_stats lc.Stats.SubmissionStat |
+20-0lua/leetcode/theme/default.lua
| @@ -28,6 +28,10 @@ M.get = function() | ||
| 28 | 28 | medium = { fg = "#fac31d" }, |
| 29 | 29 | hard = { fg = "#f8615c" }, |
| 30 | 30 | |
| 31 | + easy_alt = { fg = "#294d35" }, | |
| 32 | + medium_alt = { fg = "#5e4e25" }, | |
| 33 | + hard_alt = { fg = "#5a302f" }, | |
| 34 | + | |
| 31 | 35 | ok = { fg = hl("DiagnosticOk").fg }, |
| 32 | 36 | info = { fg = hl("DiagnosticInfo").fg }, |
| 33 | 37 | hint = { fg = hl("DiagnosticHint").fg }, |
| @@ -50,6 +54,22 @@ M.get = function() | ||
| 50 | 54 | link = { fg = hl("Function").fg, underline = true }, |
| 51 | 55 | list = { fg = hl("SpecialChar").fg }, |
| 52 | 56 | ref = { fg = hl("Tag").fg }, |
| 57 | + | |
| 58 | + -- calendar | |
| 59 | + calendar_0 = { fg = "#45475b" }, | |
| 60 | + calendar_10 = { fg = "#004d1b" }, | |
| 61 | + calendar_20 = { fg = "#016620" }, | |
| 62 | + calendar_30 = { fg = "#078029" }, | |
| 63 | + calendar_40 = { fg = "#109932" }, | |
| 64 | + calendar_50 = { fg = "#1cb33d" }, | |
| 65 | + calendar_60 = { fg = "#28c244" }, | |
| 66 | + calendar_70 = { fg = "#51d164" }, | |
| 67 | + calendar_80 = { fg = "#7fe18b" }, | |
| 68 | + calendar_90 = { fg = "#b3f0b8" }, | |
| 69 | + calendar_100 = { fg = "#d8ffda" }, | |
| 70 | + | |
| 71 | + all = { fg = hl("Normal").fg }, | |
| 72 | + all_alt = { fg = "#45475b" }, | |
| 53 | 73 | } |
| 54 | 74 | end |
| 55 | 75 |