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↵
↵
↵
```javascript↵
↵
function setPolygonTestGroupAutomatically() {↵
const mapping = {};↵
$("#testsTable tbody tr pre")↵
.each((idx_minus_one, v) => {↵
if (v.id) return; // Ignores raw input, only consider tests generated with command↵
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_minus_one + 1);↵
});↵
↵
for(const [groupName, iconst keyToIndices] of = Object.entries(mapping)) {;↵
function go (idx) {↵
if (idx == keyToIndices.length) {↵
console.log("Changed everything!")↵
}↵
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}`, data));↵
} ${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.↵
↵
<iframe width="560" height="315" src="https://www.youtube.com/embed/iaByPo0XuHk" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
↵
As a workaround, I wrote a simple script. ↵
↵
Test group of each test = the last token of the test generation command↵
↵
↵
```javascript↵
↵
function setPolygonTestGroupAutomatically() {↵
const mapping = {};↵
$("#testsTable tbody tr pre")↵
.each((idx_minus_one, v) => {↵
if (v.id) return; // Ignores raw input, only consider tests generated with command↵
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_minus_one + 1);↵
});↵
for(const [groupName, i
function go (idx) {↵
if (idx == keyToIndices.length) {↵
console.log("Changed everything!")↵
}↵
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}
}
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.↵
↵
<iframe width="560" height="315" src="https://www.youtube.com/embed/iaByPo0XuHk" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>