Redesign user rating to reward skill instead of AC rate
What does this PR aim to accomplish?:
The old rating was accepted / submitted × 1000. Anyone could raise it by only submitting easy problems they were sure of. Strong users who attempt hard problems scored about the same as careful beginners, around 400.
This PR replaces it with a rating that meets four goals:
- Comprehensive: it uses several signals.
- Hard to game: easy-problem farming and bulk pasting earn little.
- Deterministic: the same profile gives the same number for every viewer.
- Rewards talent: top competitors on the site land in the top tier.
Docs PR: https://github.com/XMOJ-Script-dev/docs/pull/9
How does this PR accomplish the above?:
New function CalculateUserRating(root). It is a pure function of one userinfo.php page and never reads the current time. It only needs data the script already fetches: the solved list, the verdict totals and the d1/d2 daily history.
The number after each solved problem is the total submit count for that problem, including submissions after AC. It is not used.
- Volume (57%):
1 − e^(−S·B/350), whereSis the number of solved problems. - Burst cap
B: daily ACs above 8 grow only logarithmically. A day with 120 ACs counts as about 30. Normal training and contest days are almost unaffected. - Accuracy (33%):
P = (S + 10) / (S + X + 40).Xis the total of PE, WA, TLE, MLE, OLE and RE verdicts; CE and ignored submissions are excluded. Resubmitting AC code changes neitherSnorX, so it can't inflate the score. The 40 virtual submissions keep small samples from scoring high. Credit peaks atP= 40–55% and falls off above that, because near-perfect accuracy over hundreds of solves looks copied. It is weighted byS / (S + 80). - Consistency (10%): active days, as
1 − e^(−days/250). - Final scale:
round(3000 × score^0.9).
Other changes:
GetUserInfoandInitializeUserProfileboth call the new function.- The cache key is renamed to
-UserRatingV2, so cached AC-rate values are not read as new ratings. A one-time sweep, guarded by theUserScript-RatingV2-Migratedmarker, deletes the oldUserScript-User-*-UserRatingentries. Email hashes, timestamps and settings are kept. - Color tiers are now: ≥2400 red
#dc2f5a, ≥2000 orange#e8590c(replaces yellow), ≥1600 blue#337cf2, ≥1200 green#2b9f4f, ≥800 cyan#1798b0, otherwise gray#78828c. They usexmoj-rating-*classes from a sharedRatingColorCSS, injected on legacy pages and in/web, instead of Bootstrap'slink-*classes. Those change with theme and hover: the old green had only 3.4:1 contrast on dark, and the yellow 1.6:1 on white. The new palette is the same on every page and in both themes, with at least 3.3:1 contrast on white and on dark. - Web contest rank page:
/web/contest/<cid>/rank-correctnever calledGetUsernameHTML, so usernames there had no avatar, rating color or badge, unlikecontestrank-oi.php. The newEnhanceRank()runs in the existingEnhance()observer loop. Vue owns the table and reuses rows when it re-sorts, so the script hides Vue's link and adds an owned copy keyed by username. A row is redrawn only when its user changes, which means the asyncGetUsernameHTMLupdate can't re-trigger itself. I checked this on a mock Vue table, including a re-sort. - Web rank page matches the OI rank page:
- Problem cells decode the server's colors the same way
contestrank-oi.phpdoes: tries counts like100 (3)/50 (2), green or red shading by tries, and purple for first blood. - The rank appears in a blue badge instead of the server's orange cell.
- Nick and AC count are plain text.
- The general
.welltheme rule no longer boxes the problem cells, and cells are vertically centered. - MonochromeUI gets the black header.
- Vue resets inline colors when it patches a row, so the web app's observer now also watches
style. - The table overflows into the page like
contestrank-oi.php, instead of being clipped by the.xmoj-scroll-xscroll box. macOS hides that box's scrollbar, so the clipping looked like a bug. - Checked on the live site with the repo's userscript harness, in dark mode with MonochromeUI, at 560, 900 and 1280 px wide. The web page and the OI page now overflow the same way and show the same tries counts.
- Problem cells decode the server's colors the same way
- The
profile-pagetest expectation is updated for the fixture: 400 → 33, checked by hand against the formula.
How it was checked:
- Real profiles fetched while building it: two NOI-level competitors score 2626 and 2760, both in the top tier. Mid-level active users score about 1140–1325.
- Synthetic profiles:
| Profile | Rating |
|---|---|
| Farmer: 300 solves, never fails | 1431 |
| Same farmer, pasting 50 solves a day | 905 |
| Grinder: 600 solves, 7 failures each | 1672 |
| New user: 20 solves, 3 failures each | 246 |
- The in-script function gives the same output as the prototype on all sample pages.
- The full
npm testsuite passes locally: 99/99, run against a locally cached Chromium build. The rank-cell logic was also tested in real Chromium against the server's actual color values, including Vue re-patching the color, the text, or both.
Known limitations:
- The rating can't see problem difficulty, because that would need crawling every problem.
- Slow, careful copying spread over many days is not detectable from profile data.
By submitting this pull request, I confirm the following:
- I have read and understood the contributor's guide, as well as this entire template.
- I have commented on my proposed changes within the code.
- I have tested my changes.
- I am willing to help maintain this change if there are issues with it later.
- It is compatible with the GNU General Public License v3.0.
- I have squashed any insignificant commits.
- I have checked that another pull request for this purpose does not exist.
- I have considered and confirmed that this submission will be valuable to others.
- I accept that this submission may not be used, and the PR can be closed at the will of the maintainer.
- I give this submission freely and claim no ownership to its content.
- I have verified that my changes work correctly in both the new UI and the old/classic UI.
Item 11 was verified by @boomzero in both the new and the classic UI, including username colors on /web/contest/<cid>/rank-correct and the profile 评分 line.
- I have read the above and my PR is ready for review.
🤖 Generated with Claude Code