Commit b3be9964 authored by duanruiming's avatar duanruiming

[update] review-优化常量字段名称

parent d3372495
...@@ -12,7 +12,10 @@ import org.springframework.util.CollectionUtils; ...@@ -12,7 +12,10 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.OptionalDouble;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -51,7 +54,7 @@ public class CrossDirWeekAvgFlowCache implements CommandLineRunner { ...@@ -51,7 +54,7 @@ public class CrossDirWeekAvgFlowCache implements CommandLineRunner {
if (average.isPresent()) { if (average.isPresent()) {
dirFlowAvg = average.getAsDouble() == 0.0 ? 1.0 : average.getAsDouble(); dirFlowAvg = average.getAsDouble() == 0.0 ? 1.0 : average.getAsDouble();
} }
crossDirWeekAvgFlowMap.put(currentCrossId.concat(Constants.underline).concat(String.valueOf(dir)), dirFlowAvg); crossDirWeekAvgFlowMap.put(currentCrossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)), dirFlowAvg);
} }
} }
} }
......
...@@ -50,7 +50,7 @@ public class CrossDirWeekMaxFlowCache implements CommandLineRunner { ...@@ -50,7 +50,7 @@ public class CrossDirWeekMaxFlowCache implements CommandLineRunner {
List<CrossDirDataHistPO> dirDataHistPOS = entry.getValue(); List<CrossDirDataHistPO> dirDataHistPOS = entry.getValue();
String currentCrossId = dirDataHistPOS.get(0).getCrossId(); String currentCrossId = dirDataHistPOS.get(0).getCrossId();
int dirFlowMax = dirDataHistPOS.stream().map(CrossDirDataHistPO::getFlow).mapToInt(Integer::intValue).max().getAsInt(); int dirFlowMax = dirDataHistPOS.stream().map(CrossDirDataHistPO::getFlow).mapToInt(Integer::intValue).max().getAsInt();
crossDirWeekMaxFlowMap.put(currentCrossId.concat(Constants.underline).concat(String.valueOf(dir)), dirFlowMax); crossDirWeekMaxFlowMap.put(currentCrossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)), dirFlowMax);
} }
} }
} }
......
...@@ -55,7 +55,7 @@ public class CrossTurnWeekMaxFlowCache implements CommandLineRunner { ...@@ -55,7 +55,7 @@ public class CrossTurnWeekMaxFlowCache implements CommandLineRunner {
if (!CollectionUtils.isEmpty(turnDataHistPOList)) { if (!CollectionUtils.isEmpty(turnDataHistPOList)) {
OptionalInt max = turnDataHistPOList.stream().map(CrossTurnDataHistPO::getFlow).mapToInt(Integer::intValue).max(); OptionalInt max = turnDataHistPOList.stream().map(CrossTurnDataHistPO::getFlow).mapToInt(Integer::intValue).max();
if (max.isPresent()) { if (max.isPresent()) {
String key = crossId.concat(Constants.underline).concat(String.valueOf(dir)).concat(Constants.underline).concat(turn); String key = crossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)).concat(Constants.UNDERLINE).concat(turn);
crossTurnWeekMaxFlowMap.put(key, max.getAsInt()); crossTurnWeekMaxFlowMap.put(key, max.getAsInt());
} }
} }
......
...@@ -60,7 +60,7 @@ public class WeekDirFreeFlowSpeedCache implements CommandLineRunner { ...@@ -60,7 +60,7 @@ public class WeekDirFreeFlowSpeedCache implements CommandLineRunner {
if (freeFlowSpeed == 0.0) { if (freeFlowSpeed == 0.0) {
freeFlowSpeed = 60.0; freeFlowSpeed = 60.0;
} }
crossDirFreeFlowSpeedMap.put(crossId.concat(Constants.underline).concat(String.valueOf(dir)), freeFlowSpeed); crossDirFreeFlowSpeedMap.put(crossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)), freeFlowSpeed);
CrossDirFreeFlowSpeedDTO crossDirFreeFlowSpeedDTO = new CrossDirFreeFlowSpeedDTO(); CrossDirFreeFlowSpeedDTO crossDirFreeFlowSpeedDTO = new CrossDirFreeFlowSpeedDTO();
crossDirFreeFlowSpeedDTO.setCrossId(crossId); crossDirFreeFlowSpeedDTO.setCrossId(crossId);
crossDirFreeFlowSpeedDTO.setDir(dir); crossDirFreeFlowSpeedDTO.setDir(dir);
......
...@@ -62,7 +62,7 @@ public class WeekTurnFreeFlowSpeedCache implements CommandLineRunner { ...@@ -62,7 +62,7 @@ public class WeekTurnFreeFlowSpeedCache implements CommandLineRunner {
OptionalDouble average = weekTurnSpeeds.subList(startIndex, endIndex).stream().mapToDouble(Double::doubleValue).average(); OptionalDouble average = weekTurnSpeeds.subList(startIndex, endIndex).stream().mapToDouble(Double::doubleValue).average();
if (average.isPresent()) { if (average.isPresent()) {
double turnFreeFlowSpeed = average.getAsDouble(); double turnFreeFlowSpeed = average.getAsDouble();
String key = currentCrossId.concat(Constants.underline).concat(String.valueOf(dir)).concat(Constants.underline).concat(turn); String key = currentCrossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)).concat(Constants.UNDERLINE).concat(turn);
crossTurnFreeFlowSpeedMap.put(key, turnFreeFlowSpeed); crossTurnFreeFlowSpeedMap.put(key, turnFreeFlowSpeed);
} }
} }
......
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
* @date 2023/09/22 9:50 * @date 2023/09/22 9:50
*/ */
public class Constants { public class Constants {
public static final String underline = "_"; public static final String UNDERLINE = "_";
// 横向方向列表 // 横向方向列表
public static final List<Integer> X_DIR_LIST = Arrays.asList(2, 3, 6, 7); public static final List<Integer> X_DIR_LIST = Arrays.asList(2, 3, 6, 7);
public static final String LANE_SNAPSHOT_DATA_ES_INDEX = "datacenter_lane_snapshot_data"; public static final String LANE_SNAPSHOT_DATA_ES_INDEX = "datacenter_lane_snapshot_data";
......
...@@ -252,8 +252,8 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService { ...@@ -252,8 +252,8 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService {
speedLaneCount = 1; speedLaneCount = 1;
} }
StringJoiner stringJoiner = new StringJoiner(""); StringJoiner stringJoiner = new StringJoiner("");
String crossTurnId = stringJoiner.add(crossId).add(Constants.underline).add(String.valueOf(inDir)) String crossTurnId = stringJoiner.add(crossId).add(Constants.UNDERLINE).add(String.valueOf(inDir))
.add(Constants.underline).add(turnType).toString(); .add(Constants.UNDERLINE).add(turnType).toString();
crossTurnDataRealTimePO.setId(crossTurnId); crossTurnDataRealTimePO.setId(crossTurnId);
crossTurnDataRealTimePO.setCrossId(crossId); crossTurnDataRealTimePO.setCrossId(crossId);
crossTurnDataRealTimePO.setTurnType(turnType); crossTurnDataRealTimePO.setTurnType(turnType);
...@@ -374,7 +374,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService { ...@@ -374,7 +374,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService {
Double dirSaturation = 0.0; // 通过方向七天流量最大值计算饱和度 Double dirSaturation = 0.0; // 通过方向七天流量最大值计算饱和度
Map<String, Integer> crossWeekMaxFlowMap = CrossDirWeekMaxFlowCache.crossDirWeekMaxFlowMap; Map<String, Integer> crossWeekMaxFlowMap = CrossDirWeekMaxFlowCache.crossDirWeekMaxFlowMap;
if (Objects.nonNull(crossWeekMaxFlowMap) && !crossWeekMaxFlowMap.isEmpty()) { if (Objects.nonNull(crossWeekMaxFlowMap) && !crossWeekMaxFlowMap.isEmpty()) {
Integer dirMaxFlow = crossWeekMaxFlowMap.get(crossId.concat(Constants.underline).concat(String.valueOf(dir))); Integer dirMaxFlow = crossWeekMaxFlowMap.get(crossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)));
if (Objects.isNull(dirMaxFlow) || dirMaxFlow == 0) { if (Objects.isNull(dirMaxFlow) || dirMaxFlow == 0) {
dirMaxFlow = 100; dirMaxFlow = 100;
} }
...@@ -382,7 +382,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService { ...@@ -382,7 +382,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService {
} }
crossDirDataRealTimePO.setSturation((Double.valueOf(decimalFormat.format(dirSaturation)))); crossDirDataRealTimePO.setSturation((Double.valueOf(decimalFormat.format(dirSaturation))));
// 平均饱和度 // 平均饱和度
Double dirFlowAvg = CrossDirWeekAvgFlowCache.crossDirWeekAvgFlowMap.get(crossId.concat(Constants.underline).concat(String.valueOf(dir))); Double dirFlowAvg = CrossDirWeekAvgFlowCache.crossDirWeekAvgFlowMap.get(crossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)));
if (Objects.nonNull(dirFlowAvg)) { if (Objects.nonNull(dirFlowAvg)) {
saturationAverage = flow / dirFlowAvg; saturationAverage = flow / dirFlowAvg;
} }
...@@ -390,7 +390,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService { ...@@ -390,7 +390,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService {
// 所有方向饱和度平方后求和 // 所有方向饱和度平方后求和
saturationSum += (dirSaturation - saturationAverage) * (dirSaturation - saturationAverage); saturationSum += (dirSaturation - saturationAverage) * (dirSaturation - saturationAverage);
StringJoiner stringJoiner = new StringJoiner(""); StringJoiner stringJoiner = new StringJoiner("");
stringJoiner.add(crossId).add(Constants.underline).add(String.valueOf(dir)).add(Constants.underline).add("1").add(Constants.underline).add("1"); stringJoiner.add(crossId).add(Constants.UNDERLINE).add(String.valueOf(dir)).add(Constants.UNDERLINE).add("1").add(Constants.UNDERLINE).add("1");
crossDirDataRealTimePO.setId(stringJoiner.toString()); crossDirDataRealTimePO.setId(stringJoiner.toString());
crossDirDataRealTimePO.setCrossId(crossId); crossDirDataRealTimePO.setCrossId(crossId);
crossDirDataRealTimePO.setDirType(dir); crossDirDataRealTimePO.setDirType(dir);
...@@ -425,7 +425,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService { ...@@ -425,7 +425,7 @@ public class LanePeriodicDataProcessServiceImpl implements DataProcessService {
if (Constants.X_DIR_LIST.contains(dir)) { // 东西方向自由流计算延时指数 if (Constants.X_DIR_LIST.contains(dir)) { // 东西方向自由流计算延时指数
Map<String, Double> crossFreeFlowSpeedMap = WeekDirFreeFlowSpeedCache.crossDirFreeFlowSpeedMap; Map<String, Double> crossFreeFlowSpeedMap = WeekDirFreeFlowSpeedCache.crossDirFreeFlowSpeedMap;
if (!crossFreeFlowSpeedMap.isEmpty()) { if (!crossFreeFlowSpeedMap.isEmpty()) {
Double freeFlowSpeed = crossFreeFlowSpeedMap.get(crossId.concat(Constants.underline).concat(String.valueOf(dir))); Double freeFlowSpeed = crossFreeFlowSpeedMap.get(crossId.concat(Constants.UNDERLINE).concat(String.valueOf(dir)));
if (Objects.isNull(freeFlowSpeed) || freeFlowSpeed == 0.0) { if (Objects.isNull(freeFlowSpeed) || freeFlowSpeed == 0.0) {
freeFlowSpeed = 60.0; freeFlowSpeed = 60.0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment