рефакторинг анализа результатов запуска двм пакетов. был удвоенный код

This commit is contained in:
2025-03-14 21:29:21 +03:00
parent 174bc344a4
commit 9a5b84c068
6 changed files with 126 additions and 171 deletions

View File

@@ -42,73 +42,7 @@ public class RefreshDVMPackageResults extends TestingServerPass<DVMPackage> {
}
@Override
protected void body() throws Exception {
boolean hasErrors = false;
target.readJson();
Vector<DVMRunTask> runTasks = new Vector<>();
for (DVMCompilationTask compilationTask : target.package_json.compilationTasks)
runTasks.addAll(compilationTask.runTasks);
//----
int ct_count = 0;
int rt_count = 0;
int good = 0;
//--
int i = 0;
for (DVMCompilationTask compilationTask : target.package_json.compilationTasks)
for (DVMRunTask runTask : compilationTask.runTasks) {
ShowProgress(runTasks.size(), i, true);
++i;
rt_count++;
if (compilationTask.state != TaskState.Done) {
runTask.state = TaskState.Canceled;
} else {
File rt_workspace = Paths.get(target.getLocalWorkspace().getAbsolutePath(), "results", String.valueOf(runTask.id)).toFile();
if (rt_workspace.exists()) {
//анализ задачи на запуск.
File outFile = new File(rt_workspace, Constants.out_file);
File errFile = new File(rt_workspace.getAbsolutePath(), Constants.err_file);
//--
String output = FileUtils.readFileToString(outFile);
String errors = FileUtils.readFileToString(errFile);
//--
List<String> output_lines = Arrays.asList(output.split("\n"));
List<String> errors_lines = Arrays.asList(errors.split("\n"));
//---
if (output.trim().isEmpty()) {
runTask.state = TaskState.Crushed;
} else {
if (Utils.isCrushed(output_lines, errors_lines)) {
runTask.state = TaskState.Crushed;
} else {
Pair<TaskState, Integer> results = new Pair<>(TaskState.Done, 100);
switch (runTask.test_type) {
case Correctness:
results = Utils.analyzeCorrectness(output_lines);
break;
case Performance:
results = Utils.analyzePerformance(output_lines);
break;
default:
break;
}
runTask.state = results.getKey();
runTask.progress = results.getValue();
runTask.CleanTime = Utils.parseCleanTime(output);
}
}
}
}
if (!runTask.state.equals(TaskState.Done))
hasErrors = true;
else good++;
}
//--
target.saveJson(); //запись обновленных результатов пакета в json!
target.doneTasksCount = good;
target.state = hasErrors ? TasksPackageState.DoneWithErrors : TasksPackageState.Done;
double percent = (((double) (good)) / target.tasksCount) * 100.0;
target.description = "Выполнено на " + ((int) percent) + "%\n" +
"Всего задач: " + target.tasksCount + ", из них с ошибками " + (target.tasksCount - good);
//--
target.checkFinishState();
}
@Override
protected void performDone() throws Exception {