mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core&ui: flatten testcases directory
This commit is contained in:
4 files changed
+21
-17
No files matched your search
@@ -45,21 +45,6 @@ export async function processTestdata(folder: string) {
|
||||
files = await fs.readdir(folder);
|
||||
}
|
||||
}
|
||||
const ini = files.filter((i) => i.toLowerCase() === 'config.ini')[0];
|
||||
if (!ini) return;
|
||||
const t = await fs.readFile(path.resolve(folder, ini), 'utf8');
|
||||
await fs.writeFile(path.resolve(folder, 'config.ini'), t.toLowerCase());
|
||||
for (const i of files) {
|
||||
if (i.toLowerCase() === 'input') await fs.rename(`${folder}/${i}`, `${folder}/input`);
|
||||
if (i.toLowerCase() === 'output') await fs.rename(`${folder}/${i}`, `${folder}/output`);
|
||||
}
|
||||
await Promise.all(['input', 'output'].flatMap(async (f) => {
|
||||
const dir = path.resolve(folder, f);
|
||||
const sf = await fs.readdir(dir);
|
||||
return sf
|
||||
.filter((i) => i !== i.toLowerCase())
|
||||
.map((i) => fs.rename(`${dir}/${i}`, `${dir}/${i.toLowerCase()}`));
|
||||
}));
|
||||
}
|
||||
|
||||
interface Args {
|
||||
|
||||
@@ -76,7 +76,7 @@ class ProblemImportHydroHandler extends Handler {
|
||||
const sub = await fs.readdir(path.join(tmpdir, i, 'testdata', f.name));
|
||||
for (const s of sub) {
|
||||
const stream = fs.createReadStream(path.join(tmpdir, i, 'testdata', f.name, s));
|
||||
await problem.addTestdata(domainId, docId, `${f.name}/${s}`, stream);
|
||||
await problem.addTestdata(domainId, docId, s, stream);
|
||||
}
|
||||
} else if (f.isFile()) {
|
||||
const stream = fs.createReadStream(path.join(tmpdir, i, 'testdata', f.name));
|
||||
|
||||
@@ -17,6 +17,7 @@ import MessageModel from './model/message';
|
||||
import problem from './model/problem';
|
||||
import RecordModel from './model/record';
|
||||
import ScheduleModel from './model/schedule';
|
||||
import StorageModel from './model/storage';
|
||||
import * as system from './model/system';
|
||||
import TaskModel from './model/task';
|
||||
import user from './model/user';
|
||||
@@ -532,6 +533,24 @@ const scripts: UpgradeScript[] = [
|
||||
}
|
||||
return true;
|
||||
},
|
||||
async function _76_77() {
|
||||
return await iterateAllProblem(['domainId', 'title', 'docId', 'data'], async (pdoc, current, total) => {
|
||||
if (!pdoc.data?.find((i) => i.name.includes('/'))) return;
|
||||
logger.info(pdoc.domainId, pdoc.docId, pdoc.title, pdoc.data.map((i) => i._id));
|
||||
const prefix = `problem/${pdoc.domainId}/${pdoc.docId}/testdata/`;
|
||||
for (const file of pdoc.data) {
|
||||
if (!file._id.includes('/')) continue;
|
||||
let newName = file._id.split('/')[1].toLowerCase();
|
||||
if (pdoc.data.find((i) => i._id === newName)) {
|
||||
newName = file._id.replace(/\//g, '_').toLowerCase();
|
||||
}
|
||||
await StorageModel.rename(`${prefix}${file._id}`, `${prefix}${newName}`);
|
||||
file._id = newName;
|
||||
file.name = newName;
|
||||
}
|
||||
await problem.edit(pdoc.domainId, pdoc.docId, { data: pdoc.data });
|
||||
});
|
||||
},
|
||||
];
|
||||
|
||||
export default scripts;
|
||||
@@ -47,7 +47,7 @@ export function convertIniConfig(ini: string) {
|
||||
if (!f[i] || !f[i].trim()) throw new Error('Testcada count incorrect.');
|
||||
const [input, output, time, score, memory] = f[i].split('|');
|
||||
const cur = {
|
||||
cases: [{ input: `input/${input.toLowerCase()}`, output: `output/${output.toLowerCase()}` }],
|
||||
cases: [{ input, output }],
|
||||
score: parseInt(score, 10),
|
||||
time: `${time}s`,
|
||||
memory: '256m',
|
||||
|
||||
Reference in new issue
Block a user