|
@@ -9,9 +9,7 @@ import com.cpp.web.domain.station.ElectricField;
|
|
|
import com.cpp.web.mapper.accuracy.ShortTermSinglePointDeviationMapper;
|
|
|
import com.cpp.web.service.accuracy.ShortTermSinglePointDeviationService;
|
|
|
import com.cpp.web.service.station.ElectricFieldService;
|
|
|
-import com.cpp.web.utils.DateTimeUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
@@ -58,18 +56,18 @@ public class ShortTermSinglePointDeviationServiceImpl extends ServiceImpl<ShortT
|
|
|
List timeList = new ArrayList<>();
|
|
|
List abnormalList = new ArrayList<>();
|
|
|
|
|
|
- Map<String,List<List>> deviationMap = new HashMap<>();
|
|
|
+ Map<String, List<List>> deviationMap = new HashMap<>();
|
|
|
for (String s : dateList) {
|
|
|
timeList.add(s);
|
|
|
if (groupedByDate.get(s) != null) {
|
|
|
double[] array = groupedByDate.get(s).stream().map(ShortTermSinglePointDeviation::getDeviation).mapToDouble(m -> m.doubleValue()).toArray();
|
|
|
// 所需盒须值
|
|
|
- Object[] result = plot(array,s);
|
|
|
+ Object[] result = plot(array, s);
|
|
|
dataList.add(result);
|
|
|
- if (StrUtil.isBlankIfStr(stationCode)){
|
|
|
+ if (StrUtil.isBlankIfStr(stationCode)) {
|
|
|
List<ElectricField> electricFieldList = electricFieldService.list();
|
|
|
double min = (Double) result[0];
|
|
|
- double max = (Double)result[4];
|
|
|
+ double max = (Double) result[4];
|
|
|
// 每天的获取异常值
|
|
|
List<ShortTermSinglePointDeviation> shortTermSinglePointDeviationList = groupedByDate.get(s).stream()
|
|
|
.filter(f -> f.getDeviation().doubleValue() < min || f.getDeviation().doubleValue() > max).collect(Collectors.toList());
|
|
@@ -77,39 +75,25 @@ public class ShortTermSinglePointDeviationServiceImpl extends ServiceImpl<ShortT
|
|
|
// 遍历异常
|
|
|
for (ShortTermSinglePointDeviation shortTermSinglePointDeviation : shortTermSinglePointDeviationList) {
|
|
|
List<Object> ycDataList = new ArrayList<>();
|
|
|
- ycDataList.add(DateUtil.format(shortTermSinglePointDeviation.getTime(),"yyyy-MM-dd"));
|
|
|
+ ycDataList.add(DateUtil.format(shortTermSinglePointDeviation.getTime(), "yyyy-MM-dd"));
|
|
|
ycDataList.add(shortTermSinglePointDeviation.getDeviation());
|
|
|
shortTermSinglePointDeviation.getStationCode();
|
|
|
ElectricField electricField = electricFieldList.stream().filter(e -> e.getStationCode().equals(shortTermSinglePointDeviation.getStationCode())).findFirst().get();
|
|
|
|
|
|
- if (deviationMap.get(electricField.getName())!=null){
|
|
|
+ if (deviationMap.get(electricField.getName()) != null) {
|
|
|
List<List> deviationList = deviationMap.get(electricField.getName());
|
|
|
deviationList.add(ycDataList);
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
List<List> deviationList = new ArrayList<>();
|
|
|
deviationList.add(ycDataList);
|
|
|
- deviationMap.put(electricField.getName(),deviationList);
|
|
|
+ deviationMap.put(electricField.getName(), deviationList);
|
|
|
}
|
|
|
}
|
|
|
map.put("abnormal", deviationMap);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
double q3 = (Double) result[3];
|
|
|
- double q1 = (Double)result[1];
|
|
|
- // 获取异常值
|
|
|
- List<Double> doubleList = groupedByDate.get(s).stream()
|
|
|
- .filter(f -> f.getDeviation().doubleValue() < q1 || f.getDeviation().doubleValue() > q3)
|
|
|
- .map(f -> f.getDeviation().doubleValue()).collect(Collectors.toList());
|
|
|
-
|
|
|
- if (doubleList.size() > 0) {
|
|
|
- for (Double v : doubleList) {
|
|
|
- List ycDataList = new ArrayList<>();
|
|
|
- ycDataList.add(s);
|
|
|
- ycDataList.add(v);
|
|
|
- abnormalList.add(ycDataList);
|
|
|
- }
|
|
|
- }
|
|
|
- map.put("abnormal", abnormalList);
|
|
|
+ double q1 = (Double) result[1];
|
|
|
+ abnormalList.addAll(accuracyPlotAbnormal(groupedByDate, s, q1, q3));
|
|
|
}
|
|
|
} else {
|
|
|
dataList.add("");
|
|
@@ -117,10 +101,40 @@ public class ShortTermSinglePointDeviationServiceImpl extends ServiceImpl<ShortT
|
|
|
}
|
|
|
map.put("result", dataList);
|
|
|
map.put("time", timeList);
|
|
|
+ map.put("abnormalList", abnormalList);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public static Object[] plot(double[] data,String date) {
|
|
|
+ /**
|
|
|
+ * 获取准确率盒须图异常值
|
|
|
+ * @param groupedByDate
|
|
|
+ * @param dateStr
|
|
|
+ * @param q1
|
|
|
+ * @param q3
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List accuracyPlotAbnormal(Map<String, List<ShortTermSinglePointDeviation>> groupedByDate, String dateStr, double q1, double q3) {
|
|
|
+
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
|
|
|
+
|
|
|
+ List abnormalList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (groupedByDate.size() > 0) {
|
|
|
+ for (ShortTermSinglePointDeviation shortTermSinglePointDeviation : groupedByDate.get(dateStr)) {
|
|
|
+ if (shortTermSinglePointDeviation.getDeviation().doubleValue() < q1 || shortTermSinglePointDeviation.getDeviation().doubleValue() > q3) {
|
|
|
+ List ycDataList = new ArrayList<>();
|
|
|
+ ycDataList.add(dateStr);
|
|
|
+ ycDataList.add(shortTermSinglePointDeviation.getDeviation());
|
|
|
+ ycDataList.add(simpleDateFormat.format(shortTermSinglePointDeviation.getTime()));
|
|
|
+ abnormalList.add(ycDataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return abnormalList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Object[] plot(double[] data, String date) {
|
|
|
Arrays.sort(data);
|
|
|
// 1/4
|
|
|
double q1 = calculateQuantile(data, 0.25);
|
|
@@ -137,7 +151,7 @@ public class ShortTermSinglePointDeviationServiceImpl extends ServiceImpl<ShortT
|
|
|
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(),date};
|
|
|
+ BigDecimal.valueOf(maxInRegion).setScale(2, RoundingMode.HALF_UP).doubleValue(), date};
|
|
|
}
|
|
|
|
|
|
private static double calculateQuantile(double[] data, double percentile) {
|
|
@@ -153,6 +167,7 @@ public class ShortTermSinglePointDeviationServiceImpl extends ServiceImpl<ShortT
|
|
|
return lowerValue + upperValue;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public List<String> getDatesInRange(Date startTime, Date endTime) {
|
|
|
List<String> dateList = new ArrayList<>();
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|