From 0d2203b4027ae3bf524d63da67202e778648e4cf Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期五, 02 八月 2024 09:59:20 +0800
Subject: [PATCH] 修改
---
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/async/PythonLib.java | 298 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 281 insertions(+), 17 deletions(-)
diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/async/PythonLib.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/async/PythonLib.java
index 3da299e..8562456 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/async/PythonLib.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/async/PythonLib.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.zt.common.servlet.Result;
import com.zt.life.modules.mainPart.taskReliability.model.PythonResult;
+import com.zt.life.modules.mainPart.taskReliability.model.SimulatAssess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,22 +24,31 @@
private String redisHost;
@Value("${spring.redis.port}")
private String redisPort;
+ @Value("${data.reliaSimLib.mainPy}")
+ private String reliaSimMain;
+ @Value("${data.reliaSimLib.resultHome}")
+ private String resultHome;
- private Long taskId = 123L;
- private String taskFlag = "relia";
+// private Long taskId = 123L;
+// private Long taskId = 124L;
+// private Long taskId = 100L; // =銆� model1.xml1
+ private String taskType = "calcreq";
@Autowired
private RedisTemplate redisTemplate;
- public Result callPython() {
+ public Result callPython(SimulatAssess simulatAssess) {
Result result = null;
InputStream is = null;
BufferedReader br = null;
try {
+ setParamToRedis(simulatAssess);
+
Process process = null;
- String command = "python D:\\work\\python\\relia_calc.py";
- command += " " + redisHost + " " + redisPort;
- command += " " + taskFlag + " " + taskId.toString();
+// String command = "python D:\\work\\python\\relia_calc.py";
+ String command = "python " + reliaSimMain;
+ command += " -ip " + redisHost + " -port " + redisPort;
+ command += " -taskType " + taskType + " -taskId " + simulatAssess.getId().toString();
logger.info("cmd鍛戒护涓猴細" + command);
if(System.getProperty("os.name").toLowerCase().indexOf("windows") > -1){
process = Runtime.getRuntime().exec(new String[]{"cmd", "/c", command});
@@ -48,12 +58,12 @@
throw new Exception("鏆備笉鏀寔璇ユ搷浣滅郴缁燂紝杩涜鍚姩python璁$畻锛�");
}
is = process.getInputStream();
- // 浠ュ懡浠よ鏂瑰紡璋冪敤python鏃讹紝杩斿洖鐨勭粨鏋滄槸GBK缂栫爜鐨勶紝鑰岄潪utf-8
- br = new BufferedReader(new InputStreamReader(is,"gb2312"));
+ // 浠ュ懡浠よ鏂瑰紡璋冪敤python鏃讹紝杩斿洖鐨勭粨鏋滄槸utf-8缂栫爜
+ br = new BufferedReader(new InputStreamReader(is,"utf-8"));
String line = br.readLine();
logger.info("python杩斿洖缁撴灉锛�" + line);
- int exitCode = process.waitFor();
- if (exitCode == 0) {
+// int exitCode = process.waitFor();
+// if (exitCode == 0) {
logger.info("鍚姩python璁$畻鎴愬姛");
if (line != null) {
PythonResult rtn = JSONObject.parseObject(line, PythonResult.class);
@@ -64,23 +74,23 @@
throw new RuntimeException("鍚姩python璁$畻澶辫触: errorMsg=" + errorMsg);
}
}
- } else {
- logger.error("鍚姩python璁$畻澶辫触: exitCode=" + exitCode);
- throw new RuntimeException("鍚姩python璁$畻澶辫触: exitCode=" + exitCode);
- }
+// } else {
+// logger.error("鍚姩python璁$畻澶辫触: exitCode=" + exitCode);
+// throw new RuntimeException("鍚姩python璁$畻澶辫触: exitCode=" + exitCode);
+// }
} catch (Exception e) {
logger.error("鍚姩python璁$畻鏃跺彂鐢烢xception锛�", e);
e.printStackTrace();
result = Result.error(e.getMessage());
} finally {
- if (is == null) {
+ if (is != null) {
try {
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
- if (br == null) {
+ if (br != null) {
try {
br.close();
} catch (Exception e) {
@@ -92,11 +102,265 @@
return result;
}
+/*
public String getPythonCalcResult() {
- String key = taskFlag + taskId.toString();
+ String key = taskId.toString() + "calcprog";
logger.info("redis key锛�" + key);
String progress = (String)redisTemplate.opsForValue().get(key);
if (progress==null) progress = "0";
return progress;
}
+*/
+
+ private void setParamToRedis(SimulatAssess simulatAssess) {
+ String key = simulatAssess.getId().toString() + taskType;
+ logger.info("redis key锛�" + key);
+/*
+ String xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+ "<des name=\"General system\">\n" +
+ " <tasks>\n" +
+ " <task duration=\"200\" model=\"model1\"/>\n" +
+ " <task duration=\"100\" model=\"model2\"/>\n" +
+ " </tasks>\n" +
+ " <models>\n" +
+ " <model name =\"model1\">\n" +
+ " <logic name=\"鎬讳綋\" type=\"series\"> \n" +
+ "\t\t\t\t<logic name=\"绯荤粺1\" type=\"series\"> \n" +
+ "\t\t\t\t\t<logic name=\"p1\" type=\"parallel\"> \n" +
+ "\t\t\t\t\t\t<node name=\"X1\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ " <repair_model name=\"rm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X2\" type=\"node\" cycon=\"15\" cycdown=\"5\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t</logic>\n" +
+ " <logic name=\"v1\" type=\"vote\" k=\"2\">\n" +
+ "\t\t\t\t\t\t<node name=\"X3\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ " <repair_model name=\"rm2\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X4\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t\t<node name=\"X5\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t</logic>\n" +
+ " <logic name=\"s1\" type=\"parallel\">\n" +
+ "\t\t\t\t\t\t<node name=\"X6\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X7\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t\t<node name=\"X8\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t</logic>\n" +
+ "\t\t\t\t</logic>\n" +
+ "\t\t\t\t<logic name=\"绯荤粺2\" type=\"series\"> \n" +
+ "\t\t\t\t\t<node name =\"X14\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t<node name=\"X15\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t<node name=\"X16\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm3\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t</logic>\n" +
+ " </logic>\n" +
+ " </model>\n" +
+ " <model name =\"model2\">\n" +
+ " <logic name=\"鎬讳綋\" type=\"series\"> \n" +
+ "\t\t\t\t<logic name=\"绯荤粺1\" type=\"series\">\n" +
+ "\t\t\t\t\t<logic name=\"p1\" type=\"parallel\"> \n" +
+ "\t\t\t\t\t\t<node name=\"X1\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X2\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t</logic>\n" +
+ " <logic name=\"v1\" type=\"vote\" k=\"2\">\n" +
+ "\t\t\t\t\t\t<node name=\"X3\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X4\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t\t<node name=\"X5\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t</logic>\n" +
+ " <logic name=\"s1\" type=\"parallel\">\n" +
+ "\t\t\t\t\t\t<node name=\"X6\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X7\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t\t<node name=\"X8\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t</logic>\n" +
+ "\t\t\t\t</logic>\n" +
+ "\t\t\t\t<logic name=\"绯荤粺2\" type=\"series\"> \n" +
+ "\t\t\t\t\t<logic name=\"p2\" type=\"parallel\"> \n" +
+ "\t\t\t\t\t\t<node name=\"X14\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"X15\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t</logic>\n" +
+ "\t\t\t\t\t<node name=\"X17\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t</logic>\n" +
+ " </logic>\n" +
+ " </model>\n" +
+ " </models>\n" +
+ " <failure_models>\n" +
+ " <failure_model name=\"fm1\" type=\"exponential\">\n" +
+ " <failure-rate value=\"0.004\"/>\n" +
+ " </failure_model>\n" +
+ " <failure_model name=\"fm2\" type=\"fixed\">\n" +
+ " <unreliability value=\"0.04\"/>\n" +
+ " </failure_model>\n" +
+ " <failure_model name=\"fm3\" type=\"weibull\">\n" +
+ " <scale value=\"100\"/>\n" +
+ " <shape value=\"2\"/>\n" +
+ " </failure_model>\n" +
+ " </failure_models>\n" +
+ " <repair_models>\n" +
+ " <repair_model name=\"rm1\" type=\"exponential\">\n" +
+ " <repair-rate value=\"0.1\"/>\n" +
+ " </repair_model>\n" +
+ " <repair_model name=\"rm2\" type=\"weibull\">\n" +
+ " <scale value=\"13\"/>\n" +
+ " <shape value=\"2\"/>\n" +
+ " </repair_model>\n" +
+ " </repair_models>\n" +
+ "</des>";
+*/
+ String xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+ "<des name=\"General system\">\n" +
+ " <tasks>\n" +
+ " <task duration=\"200\" model=\"model1\"/>\n" +
+ " <task duration=\"100\" model=\"model2\"/>\n" +
+ " </tasks>\n" +
+ " <models>\n" +
+ " <model name =\"model1\">\n" +
+ " <logic name=\"1813102074724945921\" type=\"series\"> \n" +
+ "\t\t\t\t<logic name=\"1721113377977629981\" type=\"series\"> \n" +
+ "\t\t\t\t\t<logic name=\"p1\" type=\"parallel\"> \n" +
+ "\t\t\t\t\t\t<node name=\"1721113796232438988\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ " <repair_model name=\"rm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"1721113971135848726\" type=\"node\" cycon=\"15\" cycdown=\"5\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t</logic>\n" +
+ " <logic name=\"v1\" type=\"vote\" k=\"2\">\n" +
+ "\t\t\t\t\t\t<node name=\"1721113929312687055\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ " <repair_model name=\"rm2\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"1721113465658619786\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t\t<node name=\"1721113182603098012\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t</logic>\n" +
+ "\t\t\t\t</logic>\n" +
+ "\t\t\t\t<logic name=\"1721113127170514122\" type=\"series\"> \n" +
+ "\t\t\t\t\t<node name =\"1721113197988754255\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t<node name=\"1721113169705470682\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t</logic>\n" +
+ " </logic>\n" +
+ " </model>\n" +
+ " <model name =\"model2\">\n" +
+ " <logic name=\"1813102074724945921\" type=\"series\"> \n" +
+ "\t\t\t\t<logic name=\"1721113377977629981\" type=\"series\"> \n" +
+ "\t\t\t\t\t<logic name=\"p1\" type=\"parallel\"> \n" +
+ "\t\t\t\t\t\t<node name=\"1721113796232438988\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ " <repair_model name=\"rm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"1721113971135848726\" type=\"node\" cycon=\"15\" cycdown=\"5\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t</logic>\n" +
+ " <logic name=\"v1\" type=\"vote\" k=\"2\">\n" +
+ "\t\t\t\t\t\t<node name=\"1721113929312687055\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ " <repair_model name=\"rm2\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t\t<node name=\"1721113465658619786\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t\t<node name=\"1721113182603098012\" type=\"node\">\n" +
+ "\t\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t\t</node> \n" +
+ "\t\t\t\t\t</logic>\n" +
+ "\t\t\t\t</logic>\n" +
+ "\t\t\t\t<logic name=\"1721113127170514122\" type=\"parallel\"> \n" +
+ "\t\t\t\t\t<node name =\"1721113197988754255\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm1\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t\t<node name=\"1721113169705470682\" type=\"node\">\n" +
+ "\t\t\t\t\t\t<failure_model name=\"fm2\"/>\n" +
+ "\t\t\t\t\t</node>\n" +
+ "\t\t\t\t</logic>\n" +
+ " </logic>\n" +
+ " </model>\n" +
+ " </models>\n" +
+ " <failure_models>\n" +
+ " <failure_model name=\"fm1\" type=\"exponential\">\n" +
+ " <failure-rate value=\"0.004\"/>\n" +
+ " </failure_model>\n" +
+ " <failure_model name=\"fm2\" type=\"fixed\">\n" +
+ " <unreliability value=\"0.04\"/>\n" +
+ " </failure_model>\n" +
+ " <failure_model name=\"fm3\" type=\"weibull\">\n" +
+ " <scale value=\"100\"/>\n" +
+ " <shape value=\"2\"/>\n" +
+ " </failure_model>\n" +
+ " </failure_models>\n" +
+ " <repair_models>\n" +
+ " <repair_model name=\"rm1\" type=\"exponential\">\n" +
+ " <repair-rate value=\"0.1\"/>\n" +
+ " </repair_model>\n" +
+ " <repair_model name=\"rm2\" type=\"weibull\">\n" +
+ " <scale value=\"13\"/>\n" +
+ " <shape value=\"2\"/>\n" +
+ " </repair_model>\n" +
+ " </repair_models>\n" +
+ "</des>";
+ JSONObject jsonObject = new JSONObject();
+/*
+ Long simulate_times = 10000L;
+ Long timeslice = 10L;
+ jsonObject.put("xmlfile", xmlfile);
+ jsonObject.put("simulate_times", simulate_times);
+ jsonObject.put("seed", 1000);
+ jsonObject.put("timeslice", 1);
+// jsonObject.put("timeslice", timeslice/60.0);
+// jsonObject.put("timeslice", timeslice);
+*/
+ jsonObject.put("xmlfile", xmlfile);
+ jsonObject.put("simulate_times", simulatAssess.getSimulatFrequency());
+ jsonObject.put("seed", 1000);
+ jsonObject.put("timeslice", simulatAssess.getSamplPeriod()/60.0);
+ jsonObject.put("result_home", resultHome);
+ redisTemplate.opsForValue().set(key, jsonObject.toJSONString());
+ }
}
--
Gitblit v1.9.1