Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions plugins/leetcode-summary/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# LeetCode Summary

A community `topbarGlyph` plugin for Ryoku Linux. It puts a small `LC` glyph on
the bar; click it for a panel with your LeetCode solved counts, global rank,
difficulty split, streak, acceptance rate and a 12-week activity map. The
username is a setting that starts empty, so **each installer sees their own summary** — type a
username into the panel and press Enter to switch instantly.
A community plugin for Ryoku Linux with **one shared data source and two hosts**:
a small `LC` glyph on the bar with a click-through panel, and a matching
paper-and-ink tile on the desktop. Both show your LeetCode solved counts, global
rank, difficulty split, streak, acceptance, language mix and a 12-week activity
map. The username is a setting, so **each installer sees their own summary** —
type a username into the panel and press Enter to switch instantly.

This replaces the separate LeetCode Pulse desktop plugin: the bar glyph and the
desktop tile are two views of the same plugin, like Coffee and VPN do, so there
is only one helper and one settings block to maintain.

It uses the same public [alfa-leetcode-api](https://github.com/alfaarghya/alfa-leetcode-api)
as the author's portfolio (`alfa-leetcode-api.onrender.com`). No token, login or
Expand All @@ -13,18 +18,27 @@ API key is needed.
## Files

- `service/Main.qml`: polls the helper every `pollSeconds` (default 600s, range
120–3600), keeps the last good snapshot and exposes it to both views.
- `content/Widget.qml`: the bar glyph. Shows the solved count when `showCount`
is on and a tooltip with the handle, rank and streak.
- `content/Panel.qml`: the click-through summary with the editable username field.
- `bin/leetcode_summary.py`: fetches `/profile`, `/solved` and `/calendar` in
parallel, computes the compact figures and caches a good snapshot.
120–3600), keeps the last good snapshot and exposes it to both views. An empty
username is a no-op, so a fresh install never shows someone else's profile.
- `content/Widget.qml`: the view both hosts mount; dispatches on density to
`Glyph.qml` at `glyph` and `Card.qml` at `compact`.
- `content/Glyph.qml`: the bar glyph. Shows the solved count when `showCount`
is on and a tooltip with the handle, rank, streak and acceptance rate.
- `content/Card.qml`: the desktop tile with the same stats, a difficulty bar,
a 12-column activity grid (one column per week, today outlined), accepted /
submission totals, an optional solved-progress track and the top languages.
A click opens your profile; hovering highlights the card. The status pill
distinguishes `SET USERNAME`, `IDLE`, `SYNCING`, `SAVED` and `LIVE`.
- `content/Panel.qml`: the click-through summary with the editable username field
and accepted / submission totals.
- `bin/leetcode_summary.py`: fetches `/profile`, `/solved`, `/calendar` and
`/language` in parallel, computes the compact figures and caches a good snapshot.

## Settings

| key | type | default | description |
| ----------- | ------ | --------- | ------------------------------------ |
| username | text | (empty) | LeetCode handle shown in the panel |
| username | text | (empty) | LeetCode handle; set it in the panel |
| pollSeconds | int | 600 | Refresh interval, 120–3600 seconds |
| showCount | toggle | true | Show the solved count next to `LC` |

Expand All @@ -38,21 +52,30 @@ also be changed under **QS Bar Settings > Community > LeetCode Summary**.
- The username is URL-encoded as one path component and never passed to a shell.
- Writes only `summary.json` under `pluginApi.stateDir`. A partial API outage
never overwrites a good cache, and a cache is only read for the username it
belongs to. Offline, the panel shows the saved snapshot with `SAVED.`.
belongs to. Offline, both views show the saved snapshot with `SAVED.`.
- No credentials, no privileged commands, no binary blobs.

## Preview

Bar glyph / panel:

![LeetCode Summary panel](assets/preview-widget.png)

Desktop tile:

![LeetCode Summary desktop tile](assets/preview-desktop.png)

## Build, check, install

```
ryoku plugin validate .
ryoku plugin add . --bar --yes
```

Enable it under **QS Bar Settings > Community**.
Then enable the desktop tile too under **QS Bar Settings > Community >
LeetCode Summary**, and place it with `ryoku-plugins-place leetcode-summary
desktopWidget <x> <y> <scale> <locked>` if it does not appear. Both views share
the same username and polling settings.

## Author

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions plugins/leetcode-summary/bin/leetcode_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import urllib.request

BASE = "https://alfa-leetcode-api.onrender.com"
PATHS = ("/profile", "/solved", "/calendar")
PATHS = ("/profile", "/solved", "/calendar", "/language")


def fetch(username, path):
Expand Down Expand Up @@ -54,22 +54,19 @@ def build_dots(raw_calendar):
try:
# Calendar keys are Unix timestamps in seconds, not day counts.
day = dt.datetime.fromtimestamp(int(key), dt.timezone.utc).date()
counts[day.isoformat()] = min(int(value), 3)
counts[day.isoformat()] = min(int(value), 5)
except (TypeError, ValueError, OSError, OverflowError):
continue
today = dt.datetime.now(dt.timezone.utc).date()
return [counts.get((today - dt.timedelta(days=i)).isoformat(), 0) for i in range(83, -1, -1)]


def main():
username = sys.argv[1].strip() if len(sys.argv) > 1 else ""
if not username:
print("usage: leetcode_summary.py <username> <state-dir>", file=sys.stderr)
sys.exit(2)
username = sys.argv[1] if len(sys.argv) > 1 else ""
state_dir = sys.argv[2] if len(sys.argv) > 2 else ""
cache_path = os.path.join(state_dir, "summary.json") if state_dir else ""

with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:
futures = [(path, pool.submit(fetch, username, path)) for path in PATHS]
results = {}
for path, future in futures:
Expand Down Expand Up @@ -103,11 +100,18 @@ def load_cached():
profile = results.get("/profile") or {}
solved = results.get("/solved") or {}
calendar = results.get("/calendar") or {}
languages = results.get("/language") or {}

total_attempts = bucket(solved.get("totalSubmissionNum"), "All").get("submissions", 0) or 0
total_accepted = bucket(solved.get("acSubmissionNum"), "All").get("submissions", 0) or 0
acceptance = round(total_accepted / total_attempts * 100) if total_attempts else 0

langs = [
{"name": row.get("languageName", ""), "count": row.get("problemsSolved", 0)}
for row in (languages.get("languageProblemCount") or [])
]
langs.sort(key=lambda row: row["count"], reverse=True)

data = {
"username": username,
"solved": solved.get("solvedProblem", profile.get("totalSolved", 0)) or 0,
Expand All @@ -120,6 +124,9 @@ def load_cached():
"streak": calendar.get("streak", 0) or 0,
"activeDays": calendar.get("totalActiveDays", 0) or 0,
"acceptance": acceptance,
"accepted": total_accepted,
"submissions": total_attempts,
"languages": langs[:3],
"dots": build_dots(calendar.get("submissionCalendar", "{}")),
"fetchedAt": int(dt.datetime.now(dt.timezone.utc).timestamp()),
"live": live,
Expand Down
Loading