高级算法模块暂降综合评估
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
package com.njcn.advance.utils;
|
||||
|
||||
import com.njcn.advance.pojo.bo.QtIdxArray;
|
||||
import com.njcn.advance.pojo.bo.QvvrDataStruct;
|
||||
import com.njcn.advance.pojo.dto.BalanceInfo;
|
||||
import com.njcn.advance.pojo.dto.QtIdx;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2023/6/20
|
||||
*/
|
||||
@Component
|
||||
public class GetBalanceUtils {
|
||||
|
||||
|
||||
@Data
|
||||
public static class Sarifi {
|
||||
private Float sarifiValue;
|
||||
private Float time;
|
||||
private Float pt1;
|
||||
private Float pt2;
|
||||
}
|
||||
|
||||
|
||||
public void translateData(List<BalanceInfo> list) {
|
||||
QvvrDataStruct qvvrDataStruct = new QvvrDataStruct();
|
||||
|
||||
// 过滤数据
|
||||
List<BalanceInfo> newList = new ArrayList<>();
|
||||
filterData(list, newList);
|
||||
|
||||
// 如果newList为空则不带入dll计算
|
||||
if (newList.size() > 0) {
|
||||
packageData(newList, qvvrDataStruct);
|
||||
JnaCallDllOrSo jnaCallDll = new JnaCallBalance("qvvr_balance.dll");
|
||||
jnaCallDll.setPath();
|
||||
|
||||
// 计算暂降综合评估
|
||||
try {
|
||||
JnaCallBalance.Balancelibrary INSTANTCE = JnaCallBalance.Balancelibrary.INSTANTCE;
|
||||
INSTANTCE.qvvr_fun_cause(qvvrDataStruct);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
resultPackage(newList, qvvrDataStruct, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void resultPackage(List<BalanceInfo> list, QvvrDataStruct qvvrDataStruct, List<BalanceInfo> list2) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
for (BalanceInfo balanceInfo : list2) {
|
||||
if (balanceInfo.getAreaIndex().equals(list.get(i).getAreaIndex())) {
|
||||
balanceInfo.setCi(qvvrDataStruct.sys_res[i].CI);
|
||||
balanceInfo.setIsCount(1); // 已计算
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < list.get(i).getList().size(); j++) {
|
||||
list.get(i).getList().get(j).setCiv(qvvrDataStruct.sys_res[i].CIV[j]); // 设置监测点的评估数据
|
||||
list.get(i).getList().get(j).setL(qvvrDataStruct.sys_res[i].L[j]); // 设置监测点的评估等级
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void packageData(List<BalanceInfo> list, QvvrDataStruct qvvrDataStruct) {
|
||||
qvvrDataStruct.sys_num = list.size(); // 系统数目
|
||||
|
||||
for (int i = 0; i < qvvrDataStruct.sys_num; i++) {
|
||||
qvvrDataStruct.line_num[i] = list.get(i).getList().size(); // 监测点数目
|
||||
QtIdxArray qtIdxArray = new QtIdxArray();
|
||||
|
||||
for (int j = 0; j < list.get(i).getList().size(); j++) {
|
||||
qtIdxArray.qtIdxs[j] = list.get(i).getList().get(j).getQtIdx(); // 各监测点数据
|
||||
}
|
||||
|
||||
qvvrDataStruct.line_idx[i] = qtIdxArray;
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤掉没有监测点,没有暂降事件的数据
|
||||
private void filterData(List<BalanceInfo> list, List<BalanceInfo> listResult) {
|
||||
for (BalanceInfo balanceInfo : list) {
|
||||
BalanceInfo balanceInfo2 = new BalanceInfo();
|
||||
List<BalanceInfo.PointInfo> list2 = new ArrayList<>();
|
||||
|
||||
if (balanceInfo.getList() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < balanceInfo.getList().size(); i++) {
|
||||
QtIdx qtIdx = balanceInfo.getList().get(i).getQtIdx();
|
||||
|
||||
if (qtIdx == null || qtIdx.sarfi_90 == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list2.add(balanceInfo.getList().get(i));
|
||||
}
|
||||
|
||||
// 发生事件的监测点数目少于4组不带入计算
|
||||
if (list2.size() > 4) {
|
||||
balanceInfo2.setAreaIndex(balanceInfo.getAreaIndex());
|
||||
balanceInfo2.setList(list2);
|
||||
listResult.add(balanceInfo2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BalanceInfo.PointInfo newObj(BalanceInfo.PointInfo info, double v1, int c1, int c2, double v2, double v3) {
|
||||
info.getQtIdx().r_esm = (float) v1;
|
||||
info.getQtIdx().sarfi_90 = c1;
|
||||
info.getQtIdx().sarifi_50 = c2;
|
||||
info.getQtIdx().r_asei = (float) v2;
|
||||
info.getQtIdx().r_assi = (float) v3;
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.advance.utils;
|
||||
|
||||
import com.njcn.advance.pojo.bo.QvvrDataStruct;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2023/6/20
|
||||
*/
|
||||
public class JnaCallBalance extends JnaCallDllOrSo{
|
||||
|
||||
public static String strpath;
|
||||
|
||||
public JnaCallBalance(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPath() {
|
||||
JnaCallBalance.strpath = super.getStrpath();
|
||||
}
|
||||
|
||||
public interface Balancelibrary extends Library {
|
||||
// 加载Lib库
|
||||
Balancelibrary INSTANTCE = (Balancelibrary) Native.loadLibrary(JnaCallBalance.strpath, Balancelibrary.class);
|
||||
|
||||
// 定义方法--->与C方法相对应
|
||||
void qvvr_fun_cause(QvvrDataStruct data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.njcn.advance.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2023/6/20
|
||||
*/
|
||||
@Slf4j
|
||||
public class JnaCallDllOrSo {
|
||||
private String path = "";
|
||||
private String pathDll = "";
|
||||
private String nameDll;
|
||||
public static String jarPath = "";
|
||||
|
||||
public JnaCallDllOrSo(String name) {
|
||||
super();
|
||||
this.nameDll = name;
|
||||
|
||||
try {
|
||||
String os = System.getProperty("os.name"); // 获取当前操作系统的类型
|
||||
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;// windows操作系统为1 否则为0
|
||||
if(beginIndex == 0){
|
||||
//linux操作系统
|
||||
this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
|
||||
}else {
|
||||
this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8");
|
||||
}
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (JnaCallDllOrSo.jarPath.equals("")) {
|
||||
JnaCallDllOrSo.jarPath = this.path.substring(0, this.path.lastIndexOf('/'));
|
||||
}
|
||||
}
|
||||
|
||||
public String packagePath(String path) {
|
||||
return path + "/" + this.nameDll;
|
||||
}
|
||||
|
||||
public boolean judgeFileType() { //判断打包方式是否为jar方式
|
||||
String pathPackage = this.getClass().getPackage().toString().replaceAll("package ", "/");
|
||||
pathPackage = pathPackage.replace('.', '/');
|
||||
this.pathDll = packagePath(path + pathPackage);
|
||||
this.pathDll = path + pathPackage + "/" + this.nameDll;
|
||||
|
||||
return path.endsWith(".jar");//如果dll在jar包内部返回true,否则返回true
|
||||
}
|
||||
|
||||
public boolean exitFile() {//判断dll文件是否存在
|
||||
File file = new File(packagePath(JnaCallDllOrSo.jarPath));
|
||||
return file.exists() || file.isFile();
|
||||
}
|
||||
|
||||
public void copyDll2Path() {//复制jar包中的dll到指定位置
|
||||
InputStream is = this.getClass().getResourceAsStream(nameDll);
|
||||
File file = new File(packagePath(JnaCallDllOrSo.jarPath));
|
||||
byte[] bytes = new byte[1024];
|
||||
int readBytes;
|
||||
|
||||
try {
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
while ((readBytes = is.read(bytes)) != -1) {
|
||||
os.write(bytes, 0, readBytes);
|
||||
}
|
||||
os.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getStrpath() {
|
||||
if (judgeFileType()) {
|
||||
if (!exitFile()) {
|
||||
copyDll2Path();
|
||||
}
|
||||
|
||||
return packagePath(JnaCallDllOrSo.jarPath);
|
||||
} else {
|
||||
return this.pathDll;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPath() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user