|
@@ -2,10 +2,8 @@ package com.jjt.biz.util;
|
|
|
|
|
|
import com.jjt.biz.vo.ScoreVO;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* DataUtil$
|
|
@@ -84,4 +82,40 @@ public class DataUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 补数据
|
|
|
+ *
|
|
|
+ * @param standTime
|
|
|
+ * @param result
|
|
|
+ */
|
|
|
+ public static void standTimeNet(List<Date> standTime, List<Map<String, Object>> result) {
|
|
|
+ for (Map<String, Object> map : result) {
|
|
|
+ // 创建一个新的 times 和 scores 列表,以确保它们与标准时间序列对齐
|
|
|
+ List<Date> alignedTimes = new ArrayList<>();
|
|
|
+ List<Float> alignedScores = new ArrayList<>();
|
|
|
+ // 使用一个Map来存储原始数据,以便快速查找
|
|
|
+ Map<Date, Float> timeScoreMap = new HashMap<>();
|
|
|
+ List<Map<String, Object>> trendList = (List<Map<String, Object>>) map.get("data");
|
|
|
+ List<Map<String, Object>> newTrend = new ArrayList<>();
|
|
|
+ Map<Date, Float> map1 = trendList.stream().collect(Collectors.toMap(mp -> (Date) mp.get("time"), mp -> (Float) mp.get("value")));
|
|
|
+ for (Date d : map1.keySet()) {
|
|
|
+ timeScoreMap.put(d, map1.get(d));
|
|
|
+ }
|
|
|
+ // 遍历标准时间序列,并根据需要添加空值或实际值
|
|
|
+ for (Date time : standTime) {
|
|
|
+ Map<String, Object> map2 = new HashMap<>(16);
|
|
|
+ map2.put("time", time);
|
|
|
+ map2.put("value", timeScoreMap.getOrDefault(time, 0F));
|
|
|
+ newTrend.add(map2);
|
|
|
+ }
|
|
|
+ map.remove("data");
|
|
|
+ map.put("data", newTrend);
|
|
|
+ // 更新原有的 times 和 scores 列表
|
|
|
+// trendList.clear();
|
|
|
+// trendList.addAll(newTrend);
|
|
|
+// scores.clear();
|
|
|
+// scores.addAll(alignedScores);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|