优化洪水预测

master
chenxiwang 2024-08-20 10:19:10 +08:00
parent 17898f5677
commit c5d3ca5de6
3 changed files with 44 additions and 4 deletions

View File

@ -1,6 +1,5 @@
package com.gunshi.project.xyt.controller; package com.gunshi.project.xyt.controller;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@ -30,8 +29,10 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable; import java.io.Serializable;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* : _ * : _
@ -43,6 +44,8 @@ import java.util.Objects;
@RequestMapping(value="/forecastProject") @RequestMapping(value="/forecastProject")
public class ForecastProjectController { public class ForecastProjectController {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Autowired @Autowired
private ForecastProjectService service; private ForecastProjectService service;
@ -129,7 +132,26 @@ public class ForecastProjectController {
} }
List<ForecastResults> resultList = forecastResultsService.list(new QueryWrapper<ForecastResults>().eq("project_id", projectId).orderBy(true, true, "tm")); List<ForecastResults> resultList = forecastResultsService.list(new QueryWrapper<ForecastResults>().eq("project_id", projectId).orderBy(true, true, "tm"));
if (CollectionUtils.isNotEmpty(resultList)) { if (CollectionUtils.isNotEmpty(resultList)) {
forecastProject.setVoList(JSON.parseArray(JSON.toJSONString(resultList), ForecastResultVo.class)); List<ForecastResultVo> vos = resultList.stream()
.map(result -> {
ForecastResultVo vo = new ForecastResultVo();
vo.setTm(sdf.format(result.getTm()));
vo.setYcRkQValue(result.getYcRkQValue());
vo.setRealRkQValue(result.getRealRkQValue());
vo.setYcCkQValue(result.getYcCkQValue());
vo.setRealCkQValue(result.getRealCkQValue());
vo.setYcSwHValue(result.getYcSwHValue());
vo.setRealSwHValue(result.getRealSwHValue());
vo.setSwHDValue(result.getYcSwHValue().subtract(result.getRealSwHValue()));// 处理预测与实测水位差
vo.setDrp(result.getDrp());
vo.setIspreDrp(result.getIspreDrp());
vo.setR(result.getR());
vo.setFlLowLimLev(result.getFlLowLimLev());
vo.setCurrentYdgdyjz(result.getCurrentYdgdyjz());
vo.setPa(result.getPa());
return vo;
}).collect(Collectors.toList());
forecastProject.setVoList(vos);
forecastResultsService.handleVoList(forecastProject); forecastResultsService.handleVoList(forecastProject);
} }
return R.ok(forecastProject); return R.ok(forecastProject);

View File

@ -58,6 +58,12 @@ public class ForecastResultVo {
@Schema(description="实际水库水位") @Schema(description="实际水库水位")
private BigDecimal realSwHValue; private BigDecimal realSwHValue;
/**
* -
*/
@Schema(description="水位:预测-实测")
private BigDecimal swHDValue;
/** /**
* *
*/ */

View File

@ -40,6 +40,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -252,6 +253,7 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
if (realRsvrMap.containsKey(dateMinuteStr)) { if (realRsvrMap.containsKey(dateMinuteStr)) {
BigDecimal realSwHValue = new BigDecimal(realRsvrMap.get(dateMinuteStr));// 根据时间取更准确 BigDecimal realSwHValue = new BigDecimal(realRsvrMap.get(dateMinuteStr));// 根据时间取更准确
resultVo.setRealSwHValue(realSwHValue);// 真实水库水位 resultVo.setRealSwHValue(realSwHValue);// 真实水库水位
resultVo.setSwHDValue(resultVo.getYcSwHValue().subtract(resultVo.getRealSwHValue()));// 预测与真实水位差
H1 = realSwHValue.doubleValue();// 如果有真实水位,将最后一条的真实水位作为下一次预测段的初始水位 H1 = realSwHValue.doubleValue();// 如果有真实水位,将最后一条的真实水位作为下一次预测段的初始水位
// 真实出库流量=真实水库水位与泄流量曲线差值法 // 真实出库流量=真实水库水位与泄流量曲线差值法
if (realSwHValue != null && CollectionUtils.isNotEmpty(stZqrlBList)) { if (realSwHValue != null && CollectionUtils.isNotEmpty(stZqrlBList)) {
@ -348,7 +350,12 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
rsvrRRealList = rsvrRRealList.stream().filter(entity -> { rsvrRRealList = rsvrRRealList.stream().filter(entity -> {
Date date = entity.getTm(); Date date = entity.getTm();
return date.getMinutes() == 0 && date.getSeconds() == 0; return date.getMinutes() == 0 && date.getSeconds() == 0;
}).collect(Collectors.toList()); }).collect(Collectors.toMap(
e -> e.getStcd() + "_" + e.getTm(), // 使用属性组合作为键
Function.identity(),
(existing, replacement) -> existing // 如果有冲突,保留现有的
)).values().stream().collect(Collectors.toList());
rsvrRRealList.sort(Comparator.comparing(StRsvrR::getTm));
// 每次加0小时30分钟根据dt设置此时dt=0.5小时 // 每次加0小时30分钟根据dt设置此时dt=0.5小时
int totalMinutes = (int) Math.round(dt * 60); int totalMinutes = (int) Math.round(dt * 60);
// 计算小时数 // 计算小时数
@ -400,7 +407,12 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
filterList = filterList.stream().filter(entity -> { filterList = filterList.stream().filter(entity -> {
Date date = entity.getTm(); Date date = entity.getTm();
return date.getMinutes() == 0 && date.getSeconds() == 0; return date.getMinutes() == 0 && date.getSeconds() == 0;
}).collect(Collectors.toList()); }).collect(Collectors.toMap(
e -> e.getStcd() + "_" + e.getTm(), // 使用属性组合作为键
Function.identity(),
(existing, replacement) -> existing // 如果有冲突,保留现有的
)).values().stream().collect(Collectors.toList());
filterList.sort(Comparator.comparing(StPptnR::getTm));
Map<String, List<StPptnR>> retMap = new HashMap<>(); Map<String, List<StPptnR>> retMap = new HashMap<>();
Map<String, String> tmDrpMap = filterList.stream().collect(Collectors.toMap(pptnR -> sdfMinute.format(pptnR.getTm()), StPptnR::getDrp)); Map<String, String> tmDrpMap = filterList.stream().collect(Collectors.toMap(pptnR -> sdfMinute.format(pptnR.getTm()), StPptnR::getDrp));
List<StPptnR> listForForecast = new ArrayList<>();// 传给预测程序使用缺失的数据为0 List<StPptnR> listForForecast = new ArrayList<>();// 传给预测程序使用缺失的数据为0