From 378a66a369b27ba35dc1d4d1cbddd90b626d7046 Mon Sep 17 00:00:00 2001 From: wuww <252740454@qq.com> Date: 星期二, 06 五月 2025 16:29:03 +0800 Subject: [PATCH] 生成降雨文件 --- src/main/java/com/se/nsl/service/ResolveService.java | 83 +++++++++++++++++++++++++++++++++-------- 1 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/se/nsl/service/ResolveService.java b/src/main/java/com/se/nsl/service/ResolveService.java index 462aae4..75c4e9a 100644 --- a/src/main/java/com/se/nsl/service/ResolveService.java +++ b/src/main/java/com/se/nsl/service/ResolveService.java @@ -1,10 +1,11 @@ package com.se.nsl.service; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.se.nsl.config.PropertiesConfig; -import com.se.nsl.domain.po.DataPo; +import com.se.nsl.domain.po.Rainfall; import com.se.nsl.domain.po.Simu; import com.se.nsl.domain.po.SimuData; import com.se.nsl.domain.vo.ConfigVo; @@ -13,24 +14,21 @@ import com.se.nsl.helper.WebHelper; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.apache.axis.utils.StringUtils; import org.gdal.ogr.Geometry; import org.gdal.ogr.ogr; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import javax.annotation.Resource; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.sql.Timestamp; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -49,6 +47,10 @@ @Resource TestService testService; + + Integer DIGIT = 1000000; + + SimpleDateFormat YYYYMDHM = new SimpleDateFormat("yyyy M d H m "); public int start(Simu simu) { Date now = new Date(); @@ -95,19 +97,20 @@ private void cope(Simu simu) { try { - DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); + SimuData data = JSONUtil.toBean(simu.getData(), SimuData.class); update(simu, 1, "鍒濆鍖栧弬鏁�"); initArgs(data); + createRainfallFile(data); - update(simu, 2, "璋冪敤姹傝В鍣�"); + /*update(simu, 2, "璋冪敤姹傝В鍣�"); callUwSolver(data); update(simu, 3, "璋冪敤Zarr杞琓if"); callZarr2tif(data); update(simu, 4, "瑙f瀽鏁版嵁"); - createNsl(data); + createNsl(data);*/ update(simu, 10, "瀹屾垚"); } catch (Exception ex) { @@ -127,7 +130,7 @@ /** * 鍒濆鍖栧弬鏁� */ - private void initArgs(DataPo data) throws IOException { + private void initArgs(SimuData data) throws IOException { String inPath = config.getInPath() + File.separator + data.getInPath(); createDir(inPath); createDir(inPath + File.separator + "depth"); @@ -149,14 +152,62 @@ f.mkdirs(); } + private void createRainfallFile(SimuData data) throws Exception { + List<Rainfall> rainfalls = data.getRainfalls(); + if (null == rainfalls || rainfalls.size() < 2) return; // CollUtil.isEmpty + + List<String> list = new ArrayList<>(); + list.add(config.getRainfallTitle()); + + double centerX = ComHelper.getMinVal((data.getMinx() + data.getMaxx()) / 2, DIGIT); + double centerY = ComHelper.getMinVal((data.getMiny() + data.getMaxy()) / 2, DIGIT); + String prefix = config.getRainfallSite() + " " + centerX + " " + centerY + " "; + int unit = StringUtils.isEmpty(data.getIntensityUnit()) || "mm/h".equals(data.getIntensityUnit()) ? 60 : 5; + + int c = rainfalls.size() - 1; + for (int i = 0; i < c; i++) { + Rainfall r1 = rainfalls.get(i); + Rainfall r2 = rainfalls.get(i + 1); + + list.addAll(calcRainfall(r1, r2, prefix, unit)); + } + list.add(prefix + YYYYMDHM.format(rainfalls.get(c).getTime()) + ComHelper.getMinVal(rainfalls.get(c).getIntensity() / unit, DIGIT)); + + String rainfallFile = config.getInPath() + File.separator + data.getInPath() + File.separator + "rainfall.dat"; + Files.write(Paths.get(rainfallFile), list, StandardCharsets.UTF_8); + } + + // beijing 116.0 40.0 2025 1 1 0 13 1.666666 + private List<String> calcRainfall(Rainfall r1, Rainfall r2, String prefix, int unit) { + long mins = Math.abs(r2.getTime().getTime() - r1.getTime().getTime()) / (1000 * 60); // 璁$畻鍒嗛挓鏁� + double diff = ComHelper.getMinVal((r1.getIntensity() - r2.getIntensity()) / mins / unit, DIGIT); + + Calendar cal = Calendar.getInstance(); + cal.setTime(r1.getTime()); + + List<String> list = new ArrayList<>(); + for (int i = 0; i < mins; i++) { + list.add(prefix + YYYYMDHM.format(cal.getTime()) + r1.getIntensity() + diff * i); + cal.add(Calendar.MINUTE, 1); + } + + return list; + } + /** * 璋冪敤UWSolver */ - private String callUwSolver(DataPo data) throws Exception { + private String callUwSolver(SimuData data) throws Exception { File uwBat = new File(config.getUwSolverBat()); - ConfigVo vo = new ConfigVo(data.getDuration(), config.getSaveFrames()); - //String configFile = uwBat.getParent() + File.separator + data.getInPath() + ".json"; + int duration = 3600 * data.getDuration(); // 绉掓暟 + if (null != data.getRainfalls() && data.getRainfalls().size() > 1) { + duration = (int) (Math.abs(data.getRainfalls().get(data.getRainfalls().size() - 1).getTime().getTime() - data.getRainfalls().get(0).getTime().getTime()) / 60); + } + + String rainfallFile = config.getInPath() + File.separator + data.getInPath() + File.separator + "rainfall.dat"; + ConfigVo vo = new ConfigVo(duration, config.getSaveFrames(), rainfallFile); + String configFile = config.getInPath() + File.separator + data.getInPath() + File.separator + data.getInPath() + ".json"; ComHelper.writeJson(configFile, JSON.toJSONString(vo)); @@ -168,7 +219,7 @@ /** * 璋冪敤zarr2tif */ - private String callZarr2tif(DataPo data) throws Exception { + private String callZarr2tif(SimuData data) throws Exception { File uwBat = new File(config.getUwSolverBat()); String zarrFile = uwBat.getParent() + File.separator + "result.zarr"; String inPath = config.getInPath() + File.separator + data.getInPath(); @@ -206,7 +257,7 @@ } } - private void createNsl(DataPo data) throws Exception { + private void createNsl(SimuData data) throws Exception { String inPath = config.getInPath() + File.separator + data.getInPath() + File.separator + "depth"; procTifs(inPath, inPath, data.getStartTime()); -- Gitblit v1.9.3