fanxiaoyu 5 месяцев назад
Родитель
Сommit
f0119d37b4

+ 40 - 0
cpp-admin/src/main/java/com/cpp/web/domain/accuracy/ShortTermSinglePointDeviation.java

@@ -0,0 +1,40 @@
+package com.cpp.web.domain.accuracy;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.cpp.web.domain.BaseCppEntity;
+import com.cpp.web.domain.enums.DataSourcesEnum;
+import com.cpp.web.domain.enums.ForecastTypeEnum;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 短期单点偏差(E4)
+ */
+@Data
+@TableName("cpp_short_term_single_point_deviation")
+@EqualsAndHashCode(callSuper = true)
+@ApiModel(value = "cpp_short_term_single_point_deviation")
+public class ShortTermSinglePointDeviation extends BaseCppEntity {
+
+    //时间
+    @ApiModelProperty(value = "时间")
+    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
+    private Date time;
+
+    //单点偏差累加
+    @ApiModelProperty(value = "单点偏差")
+    private BigDecimal deviation;
+
+    /**
+     * 提前多久预测
+     */
+    @ApiModelProperty(value = "提前多久预测")
+    private Integer forecastHowLongAgo;
+
+}

+ 15 - 0
cpp-admin/src/main/java/com/cpp/web/mapper/accuracy/ShortTermSinglePointDeviationMapper.java

@@ -0,0 +1,15 @@
+package com.cpp.web.mapper.accuracy;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cpp.web.domain.accuracy.ShortTermSinglePointDeviation;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * idp_forecast_power_short_term
+ *
+ * @author tl
+ * @date 2024-09-23 15:28:33
+ */
+@Mapper
+public interface ShortTermSinglePointDeviationMapper extends BaseMapper<ShortTermSinglePointDeviation> {
+}

+ 18 - 0
cpp-admin/src/main/java/com/cpp/web/service/accuracy/ShortTermSinglePointDeviationService.java

@@ -0,0 +1,18 @@
+package com.cpp.web.service.accuracy;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.cpp.web.domain.accuracy.ShortTermSinglePointDeviation;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * idp_forecast_power_short_term
+ *
+ * @author tl
+ * @date 2024-09-23 15:28:33
+ */
+public interface ShortTermSinglePointDeviationService extends IService<ShortTermSinglePointDeviation> {
+
+    List<ShortTermSinglePointDeviation> findByTimeBetweenAndHowLongAgoAndStationCode(Date startTime,Date endTime,int ago,String stationCode);
+}

+ 92 - 0
cpp-admin/src/main/java/com/cpp/web/service/accuracy/impl/ShortTermSinglePointDeviationServiceImpl.java

@@ -0,0 +1,92 @@
+package com.cpp.web.service.accuracy.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cpp.web.domain.accuracy.ShortTermSinglePointDeviation;
+import com.cpp.web.mapper.accuracy.ShortTermSinglePointDeviationMapper;
+import com.cpp.web.service.accuracy.ShortTermSinglePointDeviationService;
+import org.springframework.security.core.parameters.P;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * idp_forecast_power_short_term
+ *
+ * @author tl
+ * @date 2024-09-23 15:28:33
+ */
+@Service
+public class ShortTermSinglePointDeviationServiceImpl extends ServiceImpl<ShortTermSinglePointDeviationMapper, ShortTermSinglePointDeviation> implements ShortTermSinglePointDeviationService {
+
+    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+    @Override
+    public List<ShortTermSinglePointDeviation> findByTimeBetweenAndHowLongAgoAndStationCode(Date startTime, Date endTime, int ago, String stationCode) {
+        QueryWrapper<ShortTermSinglePointDeviation> wrapper = new QueryWrapper<>();
+        if (null != stationCode && !"".equals(stationCode)){
+            wrapper.eq("station_code",stationCode);
+        }
+        if (null != startTime && !"".equals(startTime) && null != endTime && !"".equals(endTime)){
+            wrapper.between("time",startTime,endTime);
+        }
+        wrapper.eq("forecast_how_long_ago",ago);
+
+        List<ShortTermSinglePointDeviation> list = list(wrapper);
+
+        Map<String, List<Double>> groupedByDate = list.stream()
+                .collect(Collectors.groupingBy(
+                        std -> sdf.format(std.getTime()),
+                        Collectors.mapping( std -> std.getDeviation().doubleValue(), Collectors.toList())
+                ));
+
+
+//        double[][] arr = new int[3][3];
+
+        return null;
+    }
+
+
+
+
+
+    public static double[] plot(double[] data) {
+        Arrays.sort(data);
+        // 1/4
+        double q1 = calculateQuantile(data, 0.25);
+        // 1/2
+        double q2 = calculateQuantile(data, 0.5);
+        // 3/4
+        double q3 = calculateQuantile(data, 0.75);
+        double iqr = q3 - q1;
+        //最大观测值
+        double maxInRegion = q3 + 1.5 * iqr;
+        //最小观测值
+        double mixInRegion = q1 - 1.5 * iqr;
+        return new double[]{BigDecimal.valueOf(mixInRegion).setScale(2, RoundingMode.HALF_UP).doubleValue(),
+                BigDecimal.valueOf(q1).setScale(2, RoundingMode.HALF_UP).doubleValue(),
+                BigDecimal.valueOf(q2).setScale(2, RoundingMode.HALF_UP).doubleValue(),
+                BigDecimal.valueOf(q3).setScale(2, RoundingMode.HALF_UP).doubleValue(),
+                BigDecimal.valueOf(maxInRegion).setScale(2, RoundingMode.HALF_UP).doubleValue()};
+    }
+
+    private static double calculateQuantile(double[] data, double percentile) {
+        double index = (data.length - 1) * percentile;
+        int floor = (int) Math.floor(index);
+        int ceil = (int) Math.ceil(index);
+
+        if (floor == ceil) {
+            return data[floor];
+        } else {
+            double lowerValue = data[floor] * (ceil - index);
+            double upperValue = data[ceil] * (index - floor);
+            return lowerValue + upperValue;
+        }
+    }
+
+
+}