| | |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.ResourceAccessException; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardOpenOption; |
| | | import java.sql.Timestamp; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | |
| | | // 存储任务执行状态 |
| | | private final Map<Integer, TaskStatus> taskStatusMap = new ConcurrentHashMap<>(); |
| | | // 存储任务执行的Future对象,用于取消任务 |
| | | private final Map<String, Future<?>> taskFutureMap = new ConcurrentHashMap<>(); |
| | | // @Autowired |
| | | // private ThreadPoolTaskExecutor taskExecutor; |
| | | // private final Map<String, Future<?>> taskFutureMap = new ConcurrentHashMap<>(); |
| | | |
| | | @Async("realTimeExecutor") |
| | | public void startSimulation(Simu simu) throws IOException { |
| | |
| | | //更新模拟任务的运行状态到数据库 |
| | | private void updateTaskStatus(Simu simu, String result) { |
| | | simu.setResult(result); |
| | | Timestamp now = Timestamp.from(Instant.now()); |
| | | simu.setUpdateTime(now); |
| | | simuMapper.updateResult(simu); |
| | | } |
| | | |
| | |
| | | configVo.setStation(stationFile.getAbsolutePath()); |
| | | } |
| | | int realTimeSimulateTime = 300; //模拟时间,默认为5min,即300s |
| | | int realTimeInterval = rtsConfig.getRealTimeInterval(); //每帧的间隔时间 |
| | | Double realTimeInterval = rtsConfig.getFrameInterval(); //每帧的间隔时间 |
| | | List<String> rainGauge = new ArrayList<>(); |
| | | rainGauge.add(newDatFile.getAbsolutePath());//raingage file |
| | | rainGauge.add("mm/min"); |
| | | configVo.setRaingage(rainGauge); |
| | | String saveName = serviceNameDir + File.separator + RESULT_ZARR; |
| | | ResultVo result = new ResultVo(saveName, realTimeSimulateTime / realTimeInterval, |
| | | ResultVo result = new ResultVo(saveName, (int) (realTimeSimulateTime / realTimeInterval), |
| | | realTimeInterval, "continue", null); |
| | | result.setSave_interval(realTimeInterval); |
| | | result.setSave_timestamp0(TimeFormatUtil.formatTime(currentTime, YYYY_MM_DD_HH_MM_SS)); |
| | |
| | | configVo.setStation(stationFile.getAbsolutePath()); |
| | | } |
| | | int realTimeSimulateTime = 300; //模拟时间,默认为5min,即300s |
| | | int realTimeInterval = rtsConfig.getRealTimeInterval(); //每帧的间隔时间 |
| | | Double frameInterval = rtsConfig.getFrameInterval(); //每帧的间隔时间 |
| | | configVo.getRaingage().set(0, newDatFile.getAbsolutePath()); //raingage file |
| | | ResultVo result = configVo.getResult(); |
| | | Integer lastFrames = result.getLastFrames(); |
| | |
| | | lastFrames = 0; |
| | | } |
| | | Integer saveStart = result.getSave_start(); |
| | | Integer saveInterval = result.getSave_interval(); |
| | | Double saveInterval = result.getSave_interval(); |
| | | Integer saveFrames = result.getSave_frames(); |
| | | int newStartPoint = saveStart + (saveFrames - lastFrames) * saveInterval; |
| | | int newSaveFrames = saveFrames + (realTimeSimulateTime / realTimeInterval); |
| | | int newStartPoint = (int) (saveStart + (saveFrames - lastFrames) * saveInterval); |
| | | int newSaveFrames = (int) (saveFrames + (realTimeSimulateTime / frameInterval)); |
| | | result.setSave_start(newStartPoint); //起始时间要在上次时间的基础上开始 |
| | | result.setLastFrames(saveFrames); |
| | | result.setSave_frames(newSaveFrames); //保留5帧,在原来的基础上增加5帧 |
| | |
| | | |
| | | //将雨量计中空值(intensity为-1)的部分填充值 |
| | | private void fillEmptyValue(List<RainRecord> rainRecords) { |
| | | double[] rainValues = rainRecords.stream().mapToDouble(r -> r.getIntensity()).toArray(); |
| | | double[] rainValues = rainRecords.stream().mapToDouble(RainRecord::getIntensity).toArray(); |
| | | double[] forwardValues = forwardFill(rainValues); |
| | | double[] backwordValues = backwordFill(rainValues); |
| | | for (int i = 0; i < rainRecords.size(); i++) { |
| | |
| | | input.setFilterObject(filterObject); |
| | | String url = rtsConfig.getUrl(); |
| | | String token = rtsConfig.getToken(); |
| | | ResponseEntity<String> post = HttpRequestUtil.post(url, input, String.class, token); |
| | | String body = post.getBody(); |
| | | JsonNode jsonNode = mapper.readTree(body); |
| | | JsonNode pageData = jsonNode.get("data").get("pageData"); |
| | | if (!pageData.isEmpty()) { |
| | | return pageData.get(0).get("value").asDouble(); |
| | | try { |
| | | ResponseEntity<String> post = HttpRequestUtil.post(url, input, String.class, token); |
| | | String body = post.getBody(); |
| | | JsonNode jsonNode = mapper.readTree(body); |
| | | JsonNode pageData = jsonNode.get("data").get("pageData"); |
| | | if (!pageData.isEmpty()) { |
| | | return pageData.get(0).get("value").asDouble(); |
| | | } |
| | | } catch (ResourceAccessException e) { |
| | | log.error("无法获取到雨量站数据:", e); |
| | | } |
| | | return -1D; |
| | | } |