瀏覽代碼

增加短期预测测试类

xusl 3 年之前
父節點
當前提交
3cc4902c0c

+ 100 - 0
ipfcst-console/src/test/java/com/jiayue/ipfcst/console/service/ForecastPowerShortTermServiceTest.java

@@ -0,0 +1,100 @@
+package com.jiayue.ipfcst.console.service;
+
+import com.jiayue.ipfcst.BaseTest;
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
+import com.jiayue.ipfcst.common.core.util.CommonUtil;
+import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
+import com.jiayue.ipfcst.common.core.util.DateTimeUtil;
+import com.jiayue.ipfcst.common.core.util.NumberUtils;
+import com.jiayue.ipfcst.common.data.constant.enums.PredictionModelEnum;
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
+import com.jiayue.ipfcst.common.data.entity.ForecastPowerShortTerm;
+import com.jiayue.ipfcst.common.data.entity.ForecastPowerShortTermHis;
+import com.jiayue.ipfcst.common.data.repository.ForecastPowerShortTermRepository;
+import com.jiayue.ipfcst.console.util.Constant;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.math.BigDecimal;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * 短期测试类
+ *
+ * @author xsl
+ * @version 3.0
+ */
+public class ForecastPowerShortTermServiceTest extends BaseTest {
+  @Autowired
+  ElectricFieldService electricFieldService;
+  @Autowired
+  ForecastPowerShortTermRepository forecastPowerShortTermRepository;
+  @Autowired
+  ForecastPowerShortTermService forecastPowerShortTermService;
+
+  @Test
+  public void createData() throws Exception {
+    String stationCode="J00026";
+    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    Date startDate = dateFormat.parse("2021-09-01 00:00:00");
+    Date endDate = dateFormat.parse("2021-09-04 00:00:00");
+    // 开始时间
+    Long startTime = DateMomentUtil.getMomentTime(startDate.getTime(), 1, 15 * 60 * 1000L);
+    Long endTime = DateMomentUtil.getMomentTime(endDate.getTime(), 1, 15 * 60 * 1000L);
+    ElectricField electricField = electricFieldService.getSingleStation(stationCode);
+
+    Map<Long, BigDecimal> openCapacityMap = null;
+    try {
+      openCapacityMap = electricFieldService.queryOpenCapacity(startTime, endTime, electricField.getCapacity(),stationCode);
+    } catch (BusinessException e) {
+      System.out.println("预测数据生成获取开机容量出错:" + CommonUtil.printStackTraceToString(e));
+    }
+
+    List<ForecastPowerShortTerm> addForecastPowerShortTermList = new ArrayList<>();
+    for (Long tempTime = startTime; tempTime <= endTime; tempTime = tempTime + 15 * 60 * 1000L) {
+      ForecastPowerShortTerm forecastPowerShortTerm = new ForecastPowerShortTerm();
+      forecastPowerShortTerm.setForecastTime(tempTime);
+      BigDecimal tempValue;
+      BigDecimal randomValue = new BigDecimal(CommonUtil.getRandom(97, 99) / 100.0);
+      if (DateTimeUtil.checkInSunriseAndSunset(tempTime, electricField.getLongitude().doubleValue(),
+        electricField.getLatitude().doubleValue())) {
+        // 2021-4-22 xsl修改补数取固定系数
+        String a = Constant.forecastCoe(tempTime,electricField.getElectricFieldTypeEnum());
+        tempValue = new BigDecimal(a);
+      } else {
+        // 日升日落
+        tempValue = BigDecimal.ZERO;
+      }
+
+      forecastPowerShortTerm.setFpValue(NumberUtils.multiply(tempValue, openCapacityMap.get(tempTime)).multiply(randomValue).setScale(2, BigDecimal.ROUND_HALF_UP));
+      forecastPowerShortTerm.setGenDate(new Date());
+      forecastPowerShortTerm.setPredictionModelEnum(PredictionModelEnum.E4);
+      forecastPowerShortTerm.setStationCode(stationCode);
+      addForecastPowerShortTermList.add(forecastPowerShortTerm);
+    }
+    forecastPowerShortTermRepository.saveAll(addForecastPowerShortTermList);
+  }
+
+  @Test
+  public void getForecastPowerShortTerm() throws Exception{
+    String stationCode="J00026";
+    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    Date startDate = dateFormat.parse("2021-09-01 00:00:00");
+    Date endDate = dateFormat.parse("2021-09-04 00:00:00");
+    // 开始时间
+    Long startTime = DateMomentUtil.getMomentTime(startDate.getTime(), 1, 15 * 60 * 1000L);
+    Long endTime = DateMomentUtil.getMomentTime(endDate.getTime(), 1, 15 * 60 * 1000L);
+    List<ForecastPowerShortTermHis> forecastPowerShortTermHisList = forecastPowerShortTermService.getForecastPowerShortTerm(startTime,endTime,stationCode);
+    for (ForecastPowerShortTermHis f:forecastPowerShortTermHisList){
+      System.out.println(DateFormatUtils.format(f.getForecastTime(),"yyyy-MM-dd HH:mm")+":"+f.getAbleValue());
+    }
+  }
+}