From fb1c4d0eb169abbb96ff28ec6d49c759988eb118 Mon Sep 17 00:00:00 2001 From: RJ-star <63181527+RJ-star@users.noreply.github.com> Date: Fri, 17 May 2024 10:20:15 +0800 Subject: [PATCH] =?UTF-8?q?0516=E5=90=8E=E7=AB=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 注意修改数据库设置,dq_process.py和output.txt的路径 --- null | 0 .../springboot/controller/DQController.java | 9 +- .../buaa/springboot/service/DQService.java | 5 +- .../service/impl/DQServiceImpl.java | 51 +++++--- src/main/resources/application.yaml | 4 +- src/main/resources/dq_process.py | 122 ++++++++++++++++++ src/main/resources/output.txt | 7 + 7 files changed, 176 insertions(+), 22 deletions(-) create mode 100644 null create mode 100644 src/main/resources/dq_process.py create mode 100644 src/main/resources/output.txt diff --git a/null b/null new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/buaa/springboot/controller/DQController.java b/src/main/java/com/buaa/springboot/controller/DQController.java index 8cc082f..2401266 100644 --- a/src/main/java/com/buaa/springboot/controller/DQController.java +++ b/src/main/java/com/buaa/springboot/controller/DQController.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.util.List; import java.util.Map; @RestController @@ -16,7 +17,13 @@ public class DQController { @Autowired private DQService dqService; @GetMapping("/readData") - public Map readData() { + public List> readData() { return dqService.readData(); } + + @PostMapping("/openDQ") + public String openDQ() { + dqService.openDQ(); + return "启动成功"; + } } diff --git a/src/main/java/com/buaa/springboot/service/DQService.java b/src/main/java/com/buaa/springboot/service/DQService.java index 6231307..5c22bad 100644 --- a/src/main/java/com/buaa/springboot/service/DQService.java +++ b/src/main/java/com/buaa/springboot/service/DQService.java @@ -1,7 +1,10 @@ package com.buaa.springboot.service; +import java.util.List; import java.util.Map; public interface DQService { - public Map readData(); + public List> readData(); + + public void openDQ(); } diff --git a/src/main/java/com/buaa/springboot/service/impl/DQServiceImpl.java b/src/main/java/com/buaa/springboot/service/impl/DQServiceImpl.java index 376325d..2c6522e 100644 --- a/src/main/java/com/buaa/springboot/service/impl/DQServiceImpl.java +++ b/src/main/java/com/buaa/springboot/service/impl/DQServiceImpl.java @@ -13,21 +13,23 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; @Service public class DQServiceImpl extends ServiceImpl implements DQService { - public Map readData() { + public List> readData() { //TODO 路径要改 - String command = "Python C:\\Users\\Admin\\Desktop\\mongoPic\\dq_process.py"; - Map result = new HashMap<>(); + String command = "python F:/evaluate_backend/src/main/resources/dq_process.py"; + List> result = new ArrayList<>(); try{ Process process = Runtime.getRuntime().exec(command); System.out.println("process executed!"); //TODO: Deal with the file //TODO:路径后续进行改动 - String filePath = "C:\\Users\\Admin\\Desktop\\mongoPic\\output.txt"; + String filePath = "F:/evaluate_backend/src/main/resources/output.txt"; File file = new File(filePath); while (!file.exists()) { try { @@ -35,28 +37,41 @@ public class DQServiceImpl extends ServiceImpl implements DQServic } catch (InterruptedException e) { } - try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { - String line; - int lineNumber = 1; - - while ((line = br.readLine()) != null) { - String[] values = line.split("\\s+"); - double[] numbers = new double[values.length]; + } + try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { + String line; + int lineNumber = 1; - for (int i = 0; i < values.length; i++) { - numbers[i] = Double.parseDouble(values[i]); - } + while ((line = br.readLine()) != null) { + String[] values = line.split("\\s+"); + List numbers = new ArrayList<>(); - result.put("list" + lineNumber, numbers); - lineNumber++; + for (String value : values) { + numbers.add(Double.parseDouble(value)); } - } catch (IOException e) { - e.printStackTrace(); + + result.add(numbers); + lineNumber++; } + } catch (IOException e) { + e.printStackTrace(); } } catch (Exception e) { throw new RuntimeException(e); } return result; } + + @Override + public void openDQ() { + //TODO 根据实际情况修改路径 + String command = "F:\\DQ\\SW\\SW\\mqEXEA\\Start.bat"; + //System.out.println(command); + try{ + Process process = Runtime.getRuntime().exec(command); + System.out.println("process executed!"); + } catch (Exception e) { + throw new RuntimeException(e); + } + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 1806c56..1386fe0 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -16,8 +16,8 @@ spring: # url: jdbc:mysql://localhost:3306/evaluate_platform?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 # username: root # password: ngdwqqngjshmp7 - url: jdbc:mysql://localhost:3306/evaluate?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 - username: root + url: jdbc:mysql://10.134.49.78:3306/evaluate?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 + username: remote password: 20373189 diff --git a/src/main/resources/dq_process.py b/src/main/resources/dq_process.py new file mode 100644 index 0000000..bd8fc68 --- /dev/null +++ b/src/main/resources/dq_process.py @@ -0,0 +1,122 @@ +import re +import numpy as np +import os +import glob + + +def get_latest_modified_file(folder_path): + # 获取文件夹中所有文件的路径 + files = glob.glob(os.path.join(folder_path, '*')) + + if not files: # 如果文件夹为空 + return None + + # 找到最后修改的文件 + latest_file = max(files, key=os.path.getmtime) + + # 返回文件名 + return os.path.basename(latest_file) + + +# TODO 修改TY——Chinese路径名 +folder_path = 'F:/DQ/SW/SW/mqEXEA/MyExe/code/save/MQDataManage/TYChineseResult' +latest_file = folder_path + "/" + get_latest_modified_file(folder_path) +# 读取文件内容 +with open(latest_file, 'r', encoding='GBK') as file: + data = file.read() + +# 定义正则表达式以匹配指标 +pattern_main_prob = re.compile(r'主弹突防概率:(\d+(\.\d+)?)') +pattern_sub_prob = re.compile(r'从弹突防概率:(\d+(\.\d+)?)') +pattern_high_value_coverage = re.compile(r'高价值目标覆盖率:(\d+(\.\d+)?)') +pattern_repeated_strike_rate = re.compile(r'重复打击率:(\d+(\.\d+)?)') +pattern_search_completion = re.compile(r'搜索完成度:(\d+(\.\d+)?)') +pattern_info_sharing = re.compile(r'态势信息共享量:(\d+)') + +# 提取匹配的数值 +main_probabilities = pattern_main_prob.findall(data) +sub_probabilities = pattern_sub_prob.findall(data) +high_value_coverages = pattern_high_value_coverage.findall(data) +repeated_strike_rates = pattern_repeated_strike_rate.findall(data) +search_completions = pattern_search_completion.findall(data) +info_sharings = pattern_info_sharing.findall(data) + +# 仅保留数值部分 +main_probabilities = [float(item[0]) for item in main_probabilities] +sub_probabilities = [float(item[0]) for item in sub_probabilities] +high_value_coverages = [float(item[0]) for item in high_value_coverages] +repeated_strike_rates = [float(item[0]) for item in repeated_strike_rates] +search_completions = [float(item[0]) for item in search_completions] +info_sharings = [int(item) for item in info_sharings] +# 计算最小值和最大值 +min_val = min(info_sharings) +max_val = max(info_sharings) + +# Min-Max Scaling +info_sharings = [(x - min_val) / (max_val - min_val) for x in info_sharings] + +# 计算标准差 +std_main_probabilities = np.std(main_probabilities) +std_sub_probabilities = np.std(sub_probabilities) +std_high_value_coverages = np.std(high_value_coverages) +std_repeated_strike_rates = np.std(repeated_strike_rates) +std_search_completions = np.std(search_completions) +std_info_sharings = np.std(info_sharings) + +# 读取最新的文件内容 + +with open(latest_file, 'r', encoding='GBK') as file: + data = file.readlines() + +# 定义正则表达式以匹配每次推演结果的起始点 +pattern_start = re.compile(r"舰船剩余血量") +# 总血量 +total_health = 9.4 + +# 存储结果的数组 +health_percentages = [] + +# 遍历文件中的每一行 +for i in range(len(data)): + if pattern_start.search(data[i]): + # 提取接下来的10行中的数值 + health_values = [] + for j in range(1, 11): + match = re.search(r':\s*(\d+(\.\d+)?)', data[i + j]) + if match: + health_values.append(float(match.group(1))) + # 计算百分比 + if len(health_values) == 10: + health_percentage = sum(health_values) / total_health + health_percentages.append(health_percentage) + +std_health_percentages = np.std(health_percentages) + +# 打印结果 +print("主弹突防概率:", main_probabilities) +print("从弹突防概率:", sub_probabilities) +print("高价值目标覆盖率:", high_value_coverages) +print("重复打击率:", repeated_strike_rates) +print("搜索完成度:", search_completions) +print("态势信息共享量:", info_sharings) +print("舰船剩余血量百分比:", health_percentages) + +# 路径要改 +# 列表放入一个列表中 +lists = [main_probabilities, sub_probabilities, high_value_coverages, repeated_strike_rates, search_completions, + info_sharings, health_percentages] + +# 打开一个txt文件进行写操作 +with open('F:/evaluate_backend/src/main/resources/output.txt', "w") as file: + # 使用for循环将每个列表写入文件,每个列表占一行 + for li in lists: + file.write(' '.join(map(str, li)) + '\n') + +# 打印结果 +print("主弹突防概率标准差:", std_main_probabilities) +print("从弹突防概率标准差:", std_sub_probabilities) +print("高价值目标覆盖率标准差:", std_high_value_coverages) +print("重复打击率标准差:", std_repeated_strike_rates) +print("搜索完成度标准差:", std_search_completions) +print("态势信息共享量标准差:", std_info_sharings) +print("舰船剩余血量百分比标准差:", std_health_percentages) diff --git a/src/main/resources/output.txt b/src/main/resources/output.txt new file mode 100644 index 0000000..f14ba3f --- /dev/null +++ b/src/main/resources/output.txt @@ -0,0 +1,7 @@ +1.0 1.0 1.0 0.933333 1.0 1.0 1.0 0.933333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.933333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.933333 0.933333 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 +0.966667 0.833333 0.966667 1.0 0.933333 0.933333 0.933333 0.933333 1.0 0.933333 0.966667 1.0 0.866667 0.866667 0.966667 0.966667 0.966667 0.933333 0.966667 0.866667 0.966667 1.0 0.866667 0.966667 0.966667 0.933333 0.8 0.966667 0.933333 1.0 1.0 0.966667 0.833333 0.933333 0.966667 0.933333 1.0 0.933333 0.933333 0.933333 0.9 1.0 1.0 0.933333 0.866667 1.0 0.966667 1.0 0.8 +0.6 0.7 0.2 0.5 0.7 0.6 0.4 0.4 0.6 0.5 0.7 0.7 0.5 0.5 0.5 0.3 0.7 0.6 0.4 0.4 0.6 0.3 0.5 0.7 0.7 0.5 0.5 0.3 0.3 0.6 0.4 0.8 0.2 0.6 0.4 0.6 0.3 0.7 0.4 0.5 0.6 0.5 0.2 0.6 0.5 0.4 0.5 0.4 0.5 +0.857143 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.666667 0.0 0.0 0.0 0.857143 0.0 0.0 0.0 0.0 0.0 0.0 0.875 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.6 0.833333 0.0 0.0 0.0 0.0 0.0 0.0 0.666667 0.0 0.0 +0.8 1.0 0.9 0.9 1.0 0.9 1.0 1.0 0.9 0.9 0.8 0.9 0.8 0.9 0.8 0.8 1.0 0.9 0.7 0.8 0.8 0.6 0.8 0.9 1.0 0.8 1.0 0.9 0.8 0.9 0.9 1.0 1.0 1.0 1.0 0.8 0.6 0.8 0.8 0.8 0.8 0.9 0.8 0.7 0.7 0.9 0.8 0.9 0.8 +0.2222222222222222 0.2878787878787879 0.6666666666666666 0.398989898989899 0.4444444444444444 0.7878787878787878 0.3686868686868687 0.2878787878787879 0.51010101010101 0.5656565656565656 0.3434343434343434 0.06565656565656566 1.0 0.45454545454545453 0.4444444444444444 0.4444444444444444 0.398989898989899 0.43434343434343436 0.32323232323232326 0.5 0.51010101010101 0.23232323232323232 0.51010101010101 0.06565656565656566 0.5555555555555556 0.0 0.010101010101010102 0.2222222222222222 0.06565656565656566 0.2878787878787879 0.5 0.3888888888888889 0.398989898989899 0.5555555555555556 0.17676767676767677 0.23232323232323232 0.398989898989899 0.45454545454545453 0.2777777777777778 0.17676767676767677 0.5 0.9444444444444444 0.6666666666666666 0.51010101010101 0.2777777777777778 0.2878787878787879 0.3888888888888889 0.1111111111111111 0.6767676767676768 +0.298506170212766 0.37313265957446806 0.3168462340425532 0.3625160319148936 0.7553191489361701 0.851063829787234 0.425531914893617 0.5319148936170213 0.2811782765957447 0.33887562765957446 0.41924986170212764 0.4309772234042553 0.6605315957446808 0.7325793617021276 0.5851063829787234 0.6382978723404255 0.3527669680851063 0.43718874468085106 0.5020327659574468 0.5829155319148936 0.2612112021276596 0.326514 0.2586715531914894 0.3233394468085106 0.5340807446808511 0.574515744680851 0.450997659574468 0.525065744680851 0.48831436170212766 0.59365 0.7520028723404255 0.8469185106382978 0.26737348936170213 0.33045928723404255 0.3001079787234042 0.37513489361702124 0.6607375531914893 0.732836914893617 0.6191746808510638 0.6808831914893617 0.4032224255319149 0.4704948829787234 0.6702127659574467 0.7446808510638298 0.4656638191489362 0.5811430106382979 0.3013250319148936 0.3728724680851064 0.21988322340425534 0.2710895638297872 0.43789703191489354 0.5436074787234042 0.5818274468085106 0.7021918085106382 0.7326314893617021 0.806171489361702 0.6702127659574467 0.7446808510638298 0.3457443617021276 0.43218045744680844 0.6215327234042552 0.7321028829787234 0.2084833829787234 0.26060423404255323 0.8638705319148936 0.8936679787234043 0.4557936170212766 0.5455008510638297 0.6191871276595744 0.680898829787234 0.3425723510638298 0.42821543617021274 0.7042870212765957 0.7872736170212765 0.3031646063829787 0.3751744574468085 0.5374367021276595 0.6325968085106383 0.45842244680851063 0.47994287234042554 0.4561837021276595 0.4771445531914894 0.425531914893617 0.5319148936170213 0.8297872340425532 0.851063829787234 0.34424226595744684 0.430302829787234 0.5396728723404255 0.5815059574468084 0.5851063829787234 0.6382978723404255 0.5651096808510638 0.5499835106382978 0.6587064893617021 0.7302980851063829 0.4611856808510638 0.5755592106382978 -- Gitee