Commit 698a167f authored by zhoushiguang's avatar zhoushiguang

干线路段时间问题修改

parent 3a2c806f
......@@ -57,6 +57,7 @@ import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
......@@ -1046,6 +1047,7 @@ public class TrendServiceImpl implements TrendService {
}
List<Integer> coordDirList = new ArrayList<Integer>();
int direction = greenwaveInfoPO.getDir();
if (direction == 0) { // 正向
Integer dirCode = BaseEnum.SignalDirectionEnum.getCodeByName(dirName1);
dirCode = convertDirCode(dirName1, crossId, dirCode);
......@@ -1069,31 +1071,41 @@ public class TrendServiceImpl implements TrendService {
crossDirDataHistMapper.selectByCrossIdAndStartEnd(crossId, preSeconds, currentSeconds);
greenwaveCrossMetricsVO.setNoparkPassRate(calcNoparkPassRate(crossDirDataHistPOList, coordDirList));
greenwaveCrossMetricsVO.setUncoordinatePhaseQueue(
calcUncoordinatePhaseQueue(crossDirDataHistPOList, coordDirList));
greenwaveCrossMetricsVO.setTrvalTime(calcTravelTime(crossId, greenwaveCrossPO.getInDir()));
greenwaveCrossMetricsVO.setUncoordinatePhaseQueue(calcUncoordinatePhaseQueue(crossDirDataHistPOList, coordDirList));
greenwaveCrossMetricsVO.setTrvalTime(calcTravelTime(greenwaveCrossPO,crossDirDataHistPOList,crossId, coordDirList));
res.add(greenwaveCrossMetricsVO);
}
return res;
}
private Integer calcTravelTime(String crossId, Integer inDir) throws Exception {
try {
// 从 Redis 中获取路段行程时间
String redisKey = crossId + ":" + inDir;
Object element = redisUtils.getMaxScoreElement(redisKey);
ObjectMapper objectMapper = new ObjectMapper();
if (element != null) {
CrossEventDTO dto = objectMapper.readValue(element.toString(), CrossEventDTO.class);
return dto.getTransitTime().intValue();
}
} catch (Exception e) {
log.error("获取绿波旅行时间异常:", e);
throw new RuntimeException(e);
}
return 0;
}
private Integer calcTravelTime(GreenwaveCrossPO greenwaveCrossPO, List<CrossDirDataHistPO> crossDirDataHistPOList, String crossId, List<Integer> coordDirList) throws Exception {
double average = crossDirDataHistPOList.stream()
.filter(po -> po.getInOutType() == 1 && coordDirList.contains(po.getDirType()))
.mapToDouble(o->greenwaveCrossPO.getNextCrossLen()/o.getSpeed()/3.6)
.average()
.orElse(0.0);
BigDecimal bigDecimal = new BigDecimal(average);
bigDecimal = bigDecimal.setScale(0,RoundingMode.HALF_UP);
return bigDecimal.intValue();
}
// private Integer calcTravelTime(String crossId, Integer inDir) throws Exception {
// try {
// // 从 Redis 中获取路段行程时间
// String redisKey = crossId + ":" + inDir;
// Object element = redisUtils.getMaxScoreElement(redisKey);
// ObjectMapper objectMapper = new ObjectMapper();
// if (element != null) {
// CrossEventDTO dto = objectMapper.readValue(element.toString(), CrossEventDTO.class);
// return dto.getTransitTime().intValue();
// }
// } catch (Exception e) {
// log.error("获取绿波旅行时间异常:", e);
// throw new RuntimeException(e);
// }
// return 0;
// }
private Integer calcUncoordinatePhaseQueue(
List<CrossDirDataHistPO> crossDirDataHistPOList, List<Integer> coordDirList) {
......
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