|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|