Skip to content
Merged
Show file tree
Hide file tree
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 Oct 5, 2026
ad2cc20
3.8.6
github-actions[bot] Oct 5, 2026
6f1453a
Update version info to 3.8.6
github-actions[bot] Oct 5, 2026
f3e93bf
Base rating accuracy on verdict totals, not per-problem counts
boomzero Oct 5, 2026
225d5ab
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
26b29a5
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
3c7ceba
Show rating colors on the web contest rank page
boomzero Oct 5, 2026
d6c5756
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
d69a4f2
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
00e839b
Match the web rank-correct page to the legacy OI rank styling
boomzero Oct 5, 2026
db57c1d
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
1d2e4a5
Let the web rank table overflow like the OI rank page
boomzero Oct 5, 2026
6a0f4b1
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
958e1fb
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
a6231fd
Show rank 1 instead of "Winner" on the web rank page
boomzero Oct 5, 2026
b10f64d
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
4c7b614
Remove ratings cached under the old key from localStorage
boomzero Oct 5, 2026
3da222b
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
e2de9fe
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
60b84a3
Use one readable rating palette on every page and theme
boomzero Oct 5, 2026
e5bdbb5
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
0a5778e
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
038d6b0
Restore a hover effect on rating-colored usernames
boomzero Oct 5, 2026
7757836
Update time and description of 3.8.6
github-actions[bot] Oct 5, 2026
1bbf8e1
Separate the red and orange rating colors
boomzero Oct 6, 2026
ffd6b47
Update time and description of 3.8.6
github-actions[bot] Oct 6, 2026
a42778b
Use the vivid orange for the second rating tier
boomzero Oct 6, 2026
503012b
Update time and description of 3.8.6
github-actions[bot] Oct 6, 2026
15c3902
Update time and description of 3.8.6
github-actions[bot] Oct 6, 2026
672d408
Update time and description of 3.8.6
github-actions[bot] Oct 6, 2026
6d9fd90
Count solved problems from links too when computing the rating
boomzero Oct 6, 2026
23c9c02
Update time and description of 3.8.6
github-actions[bot] Oct 6, 2026
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
61 changes: 50 additions & 11 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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])));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle profiles that expose solved problems as links

When a profile contains solved-problem <a href="problem.php?id=..."> elements but no raw p(id, attempts) script, this loop leaves attempts empty and the function returns a rating of 0. That representation is explicitly supported by GetProfileSolvedProblems, so affected established users will display a zero rating and receive the lowest username color both on their profile and wherever GetUserInfo is 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 👍 / 👎.

}
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Missing or unparseable activity history sets burst to 1, so parsed solves receive full uncapped volume and bypass the bulk-solving penalty. Use a conservative fallback when daily counts are unavailable.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At XMOJ.user.js, line 2419:

<comment>Missing or unparseable activity history sets `burst` to 1, so parsed solves receive full uncapped volume and bypass the bulk-solving penalty. Use a conservative fallback when daily counts are unavailable.</comment>

<file context>
@@ -2393,6 +2397,43 @@ function GetProfileActivityData(root = document) {
+        totalAC += count;
+        cappedAC += count <= DailyCap ? count : DailyCap + DailyCap * Math.log(1 + (count - DailyCap) / DailyCap);
+    }
+    let burst = totalAC > 0 ? cappedAC / totalAC : 1;
+    // 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);
</file context>
Suggested change
let burst = totalAC > 0 ? cappedAC / totalAC : 1;
let burst = totalAC > 0 ? cappedAC / totalAC : 0;

// 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";
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tests/profile-page.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test('profile page browser regressions', {timeout: 60000}, async t => {
assert.equal(await page.title(), '用户 ProfileTarget 的个人中心');
assert.equal(await page.getByText('用户名:ProfileTarget', {exact: true}).isVisible(), true);
assert.equal(await page.getByText('昵称:昵称--后缀', {exact: true}).isVisible(), true);
assert.equal(await page.getByText('评分:400', {exact: true}).isVisible(), true);
assert.equal(await page.getByText('评分:31', {exact: true}).isVisible(), true);
assert.equal(await page.locator('#UserScriptProfile img').isVisible(), true);
assert.match(await page.locator('#UserScriptProfile img').getAttribute('src'), /123456789012345678901234567890abcf/);
assert.equal(await page.evaluate(() => avatarEmail), 'profile@example.test');
Expand Down
Loading