
5

An automatic script to update test groups in Polygon automatically
source link: https://codeforces.com/blog/entry/84267
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

While preparing problems with subtasks using Polygon, it's super annoying that we cannot set test groups using test scripts.
As a workaround, I wrote a simple script.
Test group of each test = the last token of the test generation command
function setPolygonTestGroupAutomatically() {
const mapping = {};
$("#testsTable tbody tr code")
.each((_, v) => {
const vid = v.parentNode.parentNode.id; if(!vid.startsWith('test_')) return;
const idx = parseInt(vid.substring('test_'.length));
const tokens = v.innerText.split(" "); // Test generation command
const testGroup = tokens[tokens.length - 1]; // Last token of the test generation command
if (!mapping[testGroup]) {
mapping[testGroup] = [];
}
mapping[testGroup].push(idx);
});
const keyToIndices = Object.entries(mapping);
function go (idx) {
if (idx == keyToIndices.length) {
console.log("Changed everything!");
return;
}
const [groupName, indices] = keyToIndices[idx];
$.post("/data/tests", {
action: "setMultipleTestGroup",
session: $('#session').text(),
testset: Object.fromEntries(new URLSearchParams($("#add-test").attr('href')))['testset'],
requestString: indices.map(idx => `testIndex=${idx}`).join('&'),
groupName,
ccid: $('meta[name="ccid"]').attr('content')
}).error((err) => console.error(err))
.then((data) => {
console.log(`Done`, groupName, indices, data);
setTimeout(go, 1000, idx+1);
});
}
go(0);
}
setPolygonTestGroupAutomatically();
Paste the script above to the developer console on the tests page.
UPD: Added 1-second delay between each API call. It seems if we call the API multiple times simultaneously, Polygon will automatically change the dollars of the test script into non-consecutive numbers, making the whole working copy inaccessible.
</div
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK