Pārlūkot izejas kodu

nsga2_history2 数据存储

huangxingxing 7 mēneši atpakaļ
vecāks
revīzija
de9a842980

+ 36 - 4
src/main/java/com/miniframe/bisiness/mdo/MDO0039Service.java

@@ -1,8 +1,6 @@
 package com.miniframe.bisiness.mdo;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -89,10 +87,14 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 		LogService.addLog(pid,"求解——————————————————开始");
 		DockerExe.stopDocker(pid);
 		DockerExe.runMdo(pid);
+
+		// ------20250210 保存 日志  弃用
 		List<MdoProComval> comvals =new ArrayList<>();
 		final List<String>[] vals = new List[]{new ArrayList<>()};
 		final boolean[] flag = {true};//步数是否结束
 		final int[] valNSiz = {0};
+		//-------20250210 保存 日志  弃用
+
 		CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
 			DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
 				@Override
@@ -168,7 +170,7 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 					super.onComplete();
 				}
 			});
-
+			saveNsga2_history2(pid, stype, comvalDao);
 			LogService.addLog(pid,"求解——————————————————成功");
 		} catch (Exception e) {
 			LogService.addLog(pid,"求解——————————————————失败");
@@ -179,6 +181,36 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 		});
 	}
 
+	private void saveNsga2_history2(String pid, String stype, MdoProComvalMapper comvalDao) {
+		//保存数据
+		if("Forrester".equals(stype)||"Branin".equals(stype)||"Rastrigin".equals(stype)
+				||"Rosenbrock".equals(stype)||"G9".equals(stype)
+		){
+			String postFile = "/cephfs/mdo/"+ pid +"/out/nsga2_history2.txt";
+			try (BufferedReader br = new BufferedReader(new FileReader(postFile))) {
+				String x_name="";
+				String line;
+				int step = 0;
+				while ((line = br.readLine()) != null) {
+					if(line.trim().startsWith("variables")){
+						x_name = line.split("=")[1].replace(" ","");
+					}else if(line.trim().matches("\\d.*")){//数字开头
+						step++;
+						String tvals =line.trim().replaceAll("\\s+"," ");//替换多个空格为一个空格
+						MdoProComval comval =new MdoProComval();
+						comval.setId(UtilTools.getUUid());
+						comval.setPid(pid);
+						comval.setStep(String.valueOf(step));
+						comval.setVars(x_name);
+						comval.setVals(tvals);
+						comvalDao.insert(comval);
+					}
+				}
+			}catch (Exception e){
+
+			}
+		}
+	}
 
 
 	/**