|
@@ -3,10 +3,13 @@ package com.miniframe.bisiness.mdo;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.github.dockerjava.api.async.ResultCallback;
|
|
import com.github.dockerjava.api.async.ResultCallback;
|
|
import com.github.dockerjava.api.model.Frame;
|
|
import com.github.dockerjava.api.model.Frame;
|
|
import com.miniframe.core.ExecProcessFlow;
|
|
import com.miniframe.core.ExecProcessFlow;
|
|
@@ -14,13 +17,16 @@ import com.miniframe.core.exception.BusinessException;
|
|
import com.miniframe.core.ext.UtilTools;
|
|
import com.miniframe.core.ext.UtilTools;
|
|
import com.miniframe.generate.business.mdo.model.MDO0039BaseModel;
|
|
import com.miniframe.generate.business.mdo.model.MDO0039BaseModel;
|
|
import com.miniframe.mdo.service.LogService;
|
|
import com.miniframe.mdo.service.LogService;
|
|
|
|
+import com.miniframe.model.mdo.MdoProComval;
|
|
import com.miniframe.model.mdo.MdoProPython;
|
|
import com.miniframe.model.mdo.MdoProPython;
|
|
import com.miniframe.model.mdo.MdoProPythonSQLBuilder;
|
|
import com.miniframe.model.mdo.MdoProPythonSQLBuilder;
|
|
import com.miniframe.model.mdo.MdoProject;
|
|
import com.miniframe.model.mdo.MdoProject;
|
|
|
|
+import com.miniframe.model.mdo.dao.MdoProComvalMapper;
|
|
import com.miniframe.model.mdo.dao.MdoProPythonMapper;
|
|
import com.miniframe.model.mdo.dao.MdoProPythonMapper;
|
|
import com.miniframe.model.mdo.dao.MdoProjectMapper;
|
|
import com.miniframe.model.mdo.dao.MdoProjectMapper;
|
|
import com.miniframe.modo.temp.TemplateGenerator;
|
|
import com.miniframe.modo.temp.TemplateGenerator;
|
|
import com.miniframe.tools.XIFileUtils;
|
|
import com.miniframe.tools.XIFileUtils;
|
|
|
|
+import com.miniframe.tools.XiJsonUtil;
|
|
import com.miniframe.tools.docker.DockerExe;
|
|
import com.miniframe.tools.docker.DockerExe;
|
|
import freemarker.template.Configuration;
|
|
import freemarker.template.Configuration;
|
|
import freemarker.template.Template;
|
|
import freemarker.template.Template;
|
|
@@ -58,21 +64,69 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
|
|
TemplateGenerator.createProblemXml(pid);
|
|
TemplateGenerator.createProblemXml(pid);
|
|
//创建run.py
|
|
//创建run.py
|
|
TemplateGenerator.createRunpy(pid);
|
|
TemplateGenerator.createRunpy(pid);
|
|
- run(pid);
|
|
|
|
|
|
+ run(pid,pro.getStype());
|
|
}
|
|
}
|
|
|
|
|
|
//异步执行
|
|
//异步执行
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
- public void run(String pid )throws Exception{
|
|
|
|
|
|
+ public void run(String pid ,String stype)throws Exception{
|
|
LogService.addLog(pid,"求解——————————————————开始");
|
|
LogService.addLog(pid,"求解——————————————————开始");
|
|
DockerExe.stopDocker(pid);
|
|
DockerExe.stopDocker(pid);
|
|
DockerExe.runMdo(pid);
|
|
DockerExe.runMdo(pid);
|
|
|
|
+ List<MdoProComval> comvals =new ArrayList<>();
|
|
|
|
+ final List<String>[] vals = new List[]{new ArrayList<>()};
|
|
|
|
+ final boolean[] flag = {true};//步数是否结束
|
|
|
|
+ final int[] valNSiz = {0};
|
|
|
|
+ MdoProComvalMapper comvalDao =UtilTools.getBean(MdoProComvalMapper.class);
|
|
CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
|
|
CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
|
|
DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
|
|
DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
|
|
@Override
|
|
@Override
|
|
public void onNext(Frame frame) {
|
|
public void onNext(Frame frame) {
|
|
- LogService.addLog(pid,new String(frame.getPayload()));
|
|
|
|
|
|
+// LogService.addLog(pid,new String(frame.getPayload()));
|
|
|
|
+ String line =new String(frame.getPayload());
|
|
System.out.print(new String(frame.getPayload()));
|
|
System.out.print(new String(frame.getPayload()));
|
|
|
|
+ //存储每步数据
|
|
|
|
+ if("Forrester".equals(stype)||"Branin".equals(stype)){
|
|
|
|
+ if(line.startsWith("[")){
|
|
|
|
+ MdoProComval v=null;
|
|
|
|
+ if(comvals.isEmpty()){
|
|
|
|
+ v= new MdoProComval();
|
|
|
|
+ comvals.add(v);
|
|
|
|
+ }
|
|
|
|
+ if(flag[0]){//没有结束
|
|
|
|
+ v=comvals.get(comvals.size()-1);
|
|
|
|
+ }else{
|
|
|
|
+ v= new MdoProComval();
|
|
|
|
+ comvals.add(v);
|
|
|
|
+ }
|
|
|
|
+ String[] valts = line.replace("[","").replace("]","").split(" ");
|
|
|
|
+ valNSiz[0] = valts.length;
|
|
|
|
+ List<String> valtsl = Arrays.asList(valts);
|
|
|
|
+ vals[0].addAll(valtsl);
|
|
|
|
+ }
|
|
|
|
+ if(line.startsWith(" gen =")){
|
|
|
|
+ String step = line.split("=")[1].trim();
|
|
|
|
+ MdoProComval comval=comvals.get(comvals.size()-1);;
|
|
|
|
+ comval.setId(UtilTools.getUUid());
|
|
|
|
+ comval.setPid(pid);
|
|
|
|
+ comval.setStep(step);
|
|
|
|
+ List<String> x_nL = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < valNSiz[0]; i++) {
|
|
|
|
+ x_nL.add("x"+i);
|
|
|
|
+ }
|
|
|
|
+ comval.setVars(x_nL.toString().replace("[","").replace("]",""));
|
|
|
|
+ comval.setVals(vals[0].toString().replace("[","").replace("]",""));
|
|
|
|
+ comvalDao.insert(comval);
|
|
|
|
+ vals[0] = new ArrayList<>();
|
|
|
|
+ flag[0] =false;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ LogService.addLog(pid, XiJsonUtil.objectToJson(comval));
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
super.onNext(frame);
|
|
super.onNext(frame);
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|