Repository navigation
Redesign user rating to reward skill instead of AC rate #1048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
afea98e
Redesign user rating to reward skill instead of AC rate
boomzero ad2cc20
3.8.6
github-actions[bot] 6f1453a
Update version info to 3.8.6
github-actions[bot] f3e93bf
Base rating accuracy on verdict totals, not per-problem counts
boomzero 225d5ab
Update time and description of 3.8.6
github-actions[bot] 26b29a5
Update time and description of 3.8.6
github-actions[bot] 3c7ceba
Show rating colors on the web contest rank page
boomzero d6c5756
Update time and description of 3.8.6
github-actions[bot] d69a4f2
Update time and description of 3.8.6
github-actions[bot] 00e839b
Match the web rank-correct page to the legacy OI rank styling
boomzero db57c1d
Update time and description of 3.8.6
github-actions[bot] 1d2e4a5
Let the web rank table overflow like the OI rank page
boomzero 6a0f4b1
Update time and description of 3.8.6
github-actions[bot] 958e1fb
Update time and description of 3.8.6
github-actions[bot] a6231fd
Show rank 1 instead of "Winner" on the web rank page
boomzero b10f64d
Update time and description of 3.8.6
github-actions[bot] 4c7b614
Remove ratings cached under the old key from localStorage
boomzero 3da222b
Update time and description of 3.8.6
github-actions[bot] e2de9fe
Update time and description of 3.8.6
github-actions[bot] 60b84a3
Use one readable rating palette on every page and theme
boomzero e5bdbb5
Update time and description of 3.8.6
github-actions[bot] 0a5778e
Update time and description of 3.8.6
github-actions[bot] 038d6b0
Restore a hover effect on rating-colored usernames
boomzero 7757836
Update time and description of 3.8.6
github-actions[bot] 1bbf8e1
Separate the red and orange rating colors
boomzero ffd6b47
Update time and description of 3.8.6
github-actions[bot] a42778b
Use the vivid orange for the second rating tier
boomzero 503012b
Update time and description of 3.8.6
github-actions[bot] 15c3902
Update time and description of 3.8.6
github-actions[bot] 672d408
Update time and description of 3.8.6
github-actions[bot] 6d9fd90
Count solved problems from links too when computing the rating
boomzero 23c9c02
Update time and description of 3.8.6
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -945,9 +945,9 @@ let RenderMathJax = async () => { | |||||
| }; | ||||||
| let GetUserInfo = async (Username) => { | ||||||
| try { | ||||||
| if (localStorage.getItem("UserScript-User-" + Username + "-UserRating") != null && new Date().getTime() - parseInt(localStorage.getItem("UserScript-User-" + Username + "-LastUpdateTime")) < 1000 * 60 * 60 * 24) { | ||||||
| if (localStorage.getItem("UserScript-User-" + Username + "-UserRatingV2") != null && new Date().getTime() - parseInt(localStorage.getItem("UserScript-User-" + Username + "-LastUpdateTime")) < 1000 * 60 * 60 * 24) { | ||||||
| return { | ||||||
| "Rating": localStorage.getItem("UserScript-User-" + Username + "-UserRating"), | ||||||
| "Rating": localStorage.getItem("UserScript-User-" + Username + "-UserRatingV2"), | ||||||
| "EmailHash": localStorage.getItem("UserScript-User-" + Username + "-EmailHash") | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -958,7 +958,7 @@ let GetUserInfo = async (Username) => { | |||||
| return null; | ||||||
| } | ||||||
| const ParsedDocument = new DOMParser().parseFromString(Response, "text/html"); | ||||||
| let Rating = (ParsedDocument.querySelector("#statics > tbody > tr:nth-child(4) > td:nth-child(2)") != null && ParsedDocument.querySelector("#statics > tbody > tr:nth-child(3) > td:nth-child(2)") != null) ? (parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(4) > td:nth-child(2)").innerText.trim()) / parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(3) > td:nth-child(2)").innerText.trim())).toFixed(3) * 1000 : 0; | ||||||
| let Rating = CalculateUserRating(ParsedDocument); | ||||||
| let Temp = (ParsedDocument.querySelector("#statics > tbody") != null) ? ParsedDocument.querySelector("#statics > tbody").children : []; | ||||||
| //页面结构异常(如403/404页面)时返回默认值,不写入缓存 | ||||||
| if (Temp.length == 0) { | ||||||
|
|
@@ -968,7 +968,7 @@ let GetUserInfo = async (Username) => { | |||||
| } | ||||||
| let Email = Temp[Temp.length - 1].children[1].innerText.trim(); | ||||||
| let EmailHash = CryptoJS.MD5(Email).toString(); | ||||||
| localStorage.setItem("UserScript-User-" + Username + "-UserRating", Rating); | ||||||
| localStorage.setItem("UserScript-User-" + Username + "-UserRatingV2", Rating); | ||||||
| if (Email == "") { | ||||||
| EmailHash = undefined; | ||||||
| } else { | ||||||
|
|
@@ -1611,14 +1611,18 @@ let GetUsernameHTML = async (Element, Username, Simple = false, Href = "https:// | |||||
| // HTMLData += "link-fuchsia" | ||||||
| // } | ||||||
| // else | ||||||
| if (Rating > 500) { | ||||||
| if (Rating >= 2400) { | ||||||
| HTMLData += "link-danger"; | ||||||
| } else if (Rating >= 400) { | ||||||
| } else if (Rating >= 2000) { | ||||||
| HTMLData += "link-warning"; | ||||||
| } else if (Rating >= 300) { | ||||||
| } else if (Rating >= 1600) { | ||||||
| HTMLData += "link-primary"; | ||||||
| } else if (Rating >= 1200) { | ||||||
| HTMLData += "link-success"; | ||||||
| } else { | ||||||
| } else if (Rating >= 800) { | ||||||
| HTMLData += "link-info"; | ||||||
| } else { | ||||||
| HTMLData += "link-secondary"; | ||||||
| } | ||||||
| } else { | ||||||
| HTMLData += "link-info"; | ||||||
|
|
@@ -2393,6 +2397,43 @@ function GetProfileActivityData(root = document) { | |||||
| return series.map(points => [...points].sort((a, b) => a[0] - b[0])); | ||||||
| } | ||||||
|
|
||||||
| // Deterministic 0-3000 rating computed from a single userinfo.php page. It only | ||||||
| // reads the p(id, attempts) list and the daily history, and never uses the | ||||||
| // current time, so every viewer gets the same number for the same profile. | ||||||
| function CalculateUserRating(root = document) { | ||||||
| let attempts = []; | ||||||
| for (let script of root.querySelector("#statics")?.querySelectorAll("script") || []) { | ||||||
| for (let match of script.textContent.matchAll(/\bp\(\s*\d+\s*,\s*(\d+)\s*\)/g)) attempts.push(Math.max(1, Number(match[1]))); | ||||||
| } | ||||||
| let solved = attempts.length; | ||||||
| if (solved == 0) return 0; | ||||||
| let activity = GetProfileActivityData(root) || [[], []]; | ||||||
| // Soft-cap ACs per day: normal training days count fully, while a day with | ||||||
| // dozens of ACs (pasted solutions, bulk resubmits) adds only logarithmically. | ||||||
| const DailyCap = 8; | ||||||
| let totalAC = 0, cappedAC = 0; | ||||||
| for (let [, count] of activity[1]) { | ||||||
| totalAC += count; | ||||||
| cappedAC += count <= DailyCap ? count : DailyCap + DailyCap * Math.log(1 + (count - DailyCap) / DailyCap); | ||||||
| } | ||||||
| let burst = totalAC > 0 ? cappedAC / totalAC : 1; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Missing or unparseable activity history sets Prompt for AI agents
Suggested change
|
||||||
| // Volume: each solve is worth 1 on the first try and decays slowly with retries. | ||||||
| let weighted = attempts.reduce((sum, count) => sum + 1 / (1 + 0.4 * Math.log(count)), 0); | ||||||
| let volume = 1 - Math.exp(-weighted * burst / 350); | ||||||
| // Accuracy: first-try rate and per-attempt rate, both shrunk toward typical | ||||||
| // values so small samples cannot score high. | ||||||
| let firstTry = (attempts.filter(count => count == 1).length + 20 * 0.25) / (solved + 20); | ||||||
| let perAttempt = (solved + 60 * 0.2) / (attempts.reduce((sum, count) => sum + count, 0) + 60); | ||||||
| let accuracyRaw = 0.5 * firstTry + 0.5 * perAttempt; | ||||||
| // Strong users still fail on hard problems, so credit peaks around 45%-60%; | ||||||
| // near-perfect accuracy over hundreds of solves looks copied and earns less. | ||||||
| let accuracy = accuracyRaw < 0.15 ? 0 : accuracyRaw < 0.45 ? (accuracyRaw - 0.15) / 0.3 : accuracyRaw < 0.6 ? 1 : Math.max(0.3, 1 - (accuracyRaw - 0.6) * 2); | ||||||
| let confidence = solved / (solved + 80); | ||||||
| let consistency = 1 - Math.exp(-activity[0].length / 250); | ||||||
| let score = 0.57 * volume + 0.33 * accuracy * confidence + 0.1 * consistency; | ||||||
| return Math.round(3000 * Math.pow(score, 0.9)); | ||||||
| } | ||||||
|
|
||||||
| function InitializeProfileActivityChart(chart) { | ||||||
| const data = GetProfileActivityData(); | ||||||
| chart.style.cssText = "width:100%;max-width:600px;text-align:left;border:1px solid var(--bs-border-color, #adb5bd);box-sizing:border-box;padding:12px;margin-top:12px"; | ||||||
|
|
@@ -2523,9 +2564,7 @@ function InitializeUserProfile(isAdmin = false) { | |||||
| let rows = [...table.rows]; | ||||||
| const Value = pattern => rows.find(row => pattern.test(row.cells[0]?.textContent.trim() || ""))?.cells[1]?.textContent.trim(); | ||||||
| let email = Value(/^(电子邮箱|Email:?)$/i) || ""; | ||||||
| let submitted = Number(Value(/^(提交|Submit(?:ted)?|Submissions?:?)$/i)); | ||||||
| let accepted = Number(Value(/^(正确|Accepted:?)$/i)); | ||||||
| let rating = submitted > 0 && Number.isFinite(accepted) ? Math.round(accepted / submitted * 1000) : 0; | ||||||
| let rating = CalculateUserRating(); | ||||||
| let profile = document.createElement("div"); | ||||||
| profile.id = "UserScriptProfile"; | ||||||
| profile.className = "row text-start text-left"; | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a profile contains solved-problem
<a href="problem.php?id=...">elements but no rawp(id, attempts)script, this loop leavesattemptsempty and the function returns a rating of 0. That representation is explicitly supported byGetProfileSolvedProblems, so affected established users will display a zero rating and receive the lowest username color both on their profile and whereverGetUserInfois used. The rating parser should handle the link-based representation as well, using a safe fallback when an attempt count is unavailable.Useful? React with 👍 / 👎.