1.优化源项重建功能,给连接Rserve服务的功能添加关闭连接功能
This commit is contained in:
parent
dcdea2e2f1
commit
6a422277e1
|
|
@ -23,6 +23,8 @@ import org.jeecg.task.SourceRebuildTaskExec;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
|
@ -149,7 +151,7 @@ public class SourceRebuildTaskServiceImpl extends ServiceImpl<SourceRebuildTaskM
|
|||
//删除结果文件
|
||||
StringBuilder outputPath = new StringBuilder();
|
||||
outputPath.append(sourceRebuildProperties.getROutput());
|
||||
outputPath.append("/");
|
||||
outputPath.append(File.separator);
|
||||
outputPath.append(sourceRebuildTask.getTaskName());
|
||||
if(FileUtil.exist(outputPath.toString())){
|
||||
FileUtil.del(outputPath.toString());
|
||||
|
|
|
|||
|
|
@ -215,6 +215,8 @@ public class TaskResultDataServiceImpl implements TaskResultDataService {
|
|||
throw new RuntimeException("RDS读取异常",e);
|
||||
} catch (REXPMismatchException e) {
|
||||
throw new RuntimeException("RDS 文件不是一个列表结构",e);
|
||||
}finally {
|
||||
this.closeRConnection(conn);
|
||||
}
|
||||
return result;
|
||||
|
||||
|
|
@ -267,6 +269,8 @@ public class TaskResultDataServiceImpl implements TaskResultDataService {
|
|||
throw new RuntimeException("RDS读取异常",e);
|
||||
} catch (REXPMismatchException e) {
|
||||
throw new RuntimeException("RDS 文件不是一个列表结构",e);
|
||||
}finally {
|
||||
this.closeRConnection(conn);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -310,6 +314,8 @@ public class TaskResultDataServiceImpl implements TaskResultDataService {
|
|||
throw new RuntimeException("RDS读取异常",e);
|
||||
} catch (REXPMismatchException e) {
|
||||
throw new RuntimeException("RDS 文件不是一个矩阵结构",e);
|
||||
}finally {
|
||||
this.closeRConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -402,6 +408,8 @@ public class TaskResultDataServiceImpl implements TaskResultDataService {
|
|||
throw new RuntimeException("RDS读取异常",e);
|
||||
} catch (REXPMismatchException e) {
|
||||
throw new RuntimeException("RDS 文件不是一个数组结构",e);
|
||||
}finally {
|
||||
this.closeRConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1336,6 +1344,8 @@ public class TaskResultDataServiceImpl implements TaskResultDataService {
|
|||
throw new RuntimeException("RDS读取异常",e);
|
||||
} catch (REXPMismatchException e) {
|
||||
throw new RuntimeException("RDS 文件不是一个列表结构",e);
|
||||
}finally {
|
||||
this.closeRConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,11 +76,11 @@ public class SourceRebuildTaskExec extends Thread{
|
|||
String titleLog = "Entity,Metric,Date,Value,Uncertainty,MDC Value";
|
||||
this.generateLog(monitorDataLog);
|
||||
this.generateLog(titleLog);
|
||||
// this.generateMonitoringDataFile();
|
||||
this.generateMonitoringDataFile();
|
||||
//生成SRS关系文件
|
||||
String srsDataLog = "----------------------------------------生成SRS数据输入文件----------------------------------------";
|
||||
this.generateLog(srsDataLog);
|
||||
// this.generateSRSDataFile();
|
||||
this.generateSRSDataFile();
|
||||
String sourceProcessDataLog = "----------------------------------------配置源项分析参数并执行源项重建----------------------------------------";
|
||||
this.generateLog(sourceProcessDataLog);
|
||||
this.execSourceRebuild();
|
||||
|
|
@ -104,7 +104,7 @@ public class SourceRebuildTaskExec extends Thread{
|
|||
private void generateMonitoringDataFile(){
|
||||
//根据监测数据生成文件(input_subexp1.dat)
|
||||
String inputPath = this.getInputPath();
|
||||
File inputSubexp1 = new File(inputPath.toString() +File.separator+ "input_subexp1.dat");
|
||||
File inputSubexp1 = new File(inputPath +File.separator+ "input_subexp1.dat");
|
||||
if(!FileUtil.exist(inputSubexp1)){
|
||||
FileUtil.touch(inputSubexp1);
|
||||
}
|
||||
|
|
@ -223,8 +223,8 @@ public class SourceRebuildTaskExec extends Thread{
|
|||
conn.assign("dbHost", this.sourceRebuildProperties.getDbHost());
|
||||
conn.assign("dbPort", new REXPInteger(this.sourceRebuildProperties.getDbPort()));
|
||||
conn.assign("dbName", this.sourceRebuildProperties.getDbName());
|
||||
conn.assign("dbUser", this.sourceRebuildProperties.getUsername());
|
||||
conn.assign("dbPassword", this.sourceRebuildProperties.getPassword());
|
||||
conn.assign("dbUser", this.sourceRebuildProperties.getDbUsername());
|
||||
conn.assign("dbPassword", this.sourceRebuildProperties.getDbPassword());
|
||||
//任务关联ID
|
||||
conn.assign("taskId", this.sourceRebuildTask.getId().toString());
|
||||
//半衰期
|
||||
|
|
@ -277,9 +277,14 @@ public class SourceRebuildTaskExec extends Thread{
|
|||
}
|
||||
} catch (RserveException e) {
|
||||
String log = "Rserve 执行过程报错,请检查配置参数";
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(log);
|
||||
} catch (REXPMismatchException e) {
|
||||
throw new RuntimeException(e);
|
||||
}finally {
|
||||
if(Objects.nonNull(conn) && conn.isConnected()){
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -331,10 +336,10 @@ public class SourceRebuildTaskExec extends Thread{
|
|||
private String getSRSFilePath(){
|
||||
StringBuilder srsFilePath = new StringBuilder();
|
||||
srsFilePath.append(sourceRebuildProperties.getSrsFilePath());
|
||||
// if(!FileUtil.exist(srsFilePath.toString())){
|
||||
// String srsNotExistLog = "SRS 文件存储目录不存在";
|
||||
// throw new RuntimeException(srsNotExistLog);
|
||||
// }
|
||||
if(!FileUtil.exist(srsFilePath.toString())){
|
||||
String srsNotExistLog = "SRS 文件存储目录不存在";
|
||||
throw new RuntimeException(srsNotExistLog);
|
||||
}
|
||||
return srsFilePath.toString();
|
||||
}
|
||||
|
||||
|
|
@ -345,7 +350,7 @@ public class SourceRebuildTaskExec extends Thread{
|
|||
private String getOutputPath(){
|
||||
StringBuilder outputPath = new StringBuilder();
|
||||
outputPath.append(sourceRebuildProperties.getROutput());
|
||||
outputPath.append("/");
|
||||
outputPath.append(File.separator);
|
||||
outputPath.append(sourceRebuildTask.getTaskName());
|
||||
if(!FileUtil.exist(outputPath.toString())){
|
||||
FileUtil.mkdir(outputPath.toString());
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import org.rosuda.REngine.*;
|
||||
import org.rosuda.REngine.Rserve.RConnection;
|
||||
import org.rosuda.REngine.Rserve.RserveException;
|
||||
|
|
@ -5,24 +7,23 @@ import org.rosuda.REngine.Rserve.RserveException;
|
|||
public class RTest {
|
||||
|
||||
public static void main(String[] args) throws RserveException, REXPMismatchException {
|
||||
String host = "192.168.186.142";
|
||||
int port = 6311;
|
||||
String host = "192.168.186.143";
|
||||
int port = 6312;
|
||||
// 如果有认证
|
||||
String user = "rserve";
|
||||
String password = "123456";
|
||||
String scriptPath = "/home/centos/r_workspace/FREAR-master/test_case/expdir/main.R";
|
||||
|
||||
RConnection conn = new RConnection(host, port);
|
||||
conn.login(user, password);
|
||||
System.out.println(conn.isConnected());
|
||||
if(conn.isConnected()){
|
||||
//重建任务名称
|
||||
conn.assign("experiment", "test");
|
||||
conn.assign("experiment", "FREAR_syntheticTestCase");
|
||||
//重建任务输入数据目录
|
||||
conn.assign("expdir", "test_case/expdir");
|
||||
conn.assign("datadir", "test_case/data");
|
||||
//重建任务输出数据目录
|
||||
conn.assign("outbasedir", "/home/centos/r_workspace/work_output");
|
||||
conn.assign("outbasedir", "/opt/rserve/work_output");
|
||||
//数据库相关
|
||||
conn.assign("dbHost", "192.168.42.54");
|
||||
conn.assign("dbPort", new REXPInteger(5432));
|
||||
|
|
@ -38,20 +39,26 @@ public class RTest {
|
|||
//设置最大总累积源项Bq
|
||||
conn.assign("Qmax", new REXPDouble(Math.pow(10, 15)));
|
||||
|
||||
//未知源#settings$trueValues <- c(NA,NA,NA,NA,NA)
|
||||
//已知源位置经度
|
||||
//已知源位置纬度
|
||||
//已知源位置源强
|
||||
//已知源位置开始时间
|
||||
//已知源结束时间
|
||||
//重建经纬度、分辨率
|
||||
Double lonmin = 125D;
|
||||
Double latmin = 38D;
|
||||
Double lonmax = 130D;
|
||||
Double latmax = 40D;
|
||||
String resolution = ".5";
|
||||
String domain = String.format("domain <- list(lonmin=%s,latmin=%s,lonmax=%s,latmax=%s,dx=%s,dy=%s)",lonmin,latmin,lonmax,latmax,resolution,resolution);
|
||||
conn.eval(domain);
|
||||
//设置时间范围
|
||||
String srsStartTime = "2024-11-30";
|
||||
String srsEndTime = "2024-12-08";
|
||||
String times = String.format("times <- expression(seq(as.POSIXct('%s'),as.POSIXct('%s'),by=3*3600))",srsStartTime,srsEndTime);
|
||||
conn.eval(times);
|
||||
|
||||
// 反演经纬度、分辨率
|
||||
conn.eval("domain <- list(lonmin=125, latmin=38, lonmax=130, latmax=40, dx=.5, dy=.5)");
|
||||
conn.eval("trueValues <- c(NA,NA,NA,NA,NA)");
|
||||
//设置工作目录
|
||||
conn.eval("setwd(\"/home/centos/r_workspace/FREAR-master\")");
|
||||
conn.eval("setwd(\"/opt/FREAR-master\")");
|
||||
//执行脚本
|
||||
conn.eval("source(\"test_case/expdir/set_up.R\")");
|
||||
REXP outputREXP = conn.eval("capture.output({source(\"test_case/expdir/main.R\")})");
|
||||
conn.eval("source(\"R_scripts/set_up.R\")");
|
||||
REXP outputREXP = conn.eval("capture.output({source(\"R_scripts/main.R\")})");
|
||||
// 将输出作为字符串数组获取
|
||||
String[] outputLines = outputREXP.asStrings();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user