Commit 3b9149ec authored by hanbing's avatar hanbing

[update] 城市大脑-干线评价-兼容环比跨天查询

parent 7656cac6
...@@ -30,4 +30,8 @@ public class MainlineSchemeEvaluateBO { ...@@ -30,4 +30,8 @@ public class MainlineSchemeEvaluateBO {
@ApiModelProperty(value = "分析时段结束时间 格式 yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "分析时段结束时间 格式 yyyy-MM-dd HH:mm:ss")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime; private Date endTime;
@ApiModelProperty(value = "是否用于城市大脑")
private Integer isCityBrain;
} }
...@@ -913,6 +913,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -913,6 +913,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
String metricName = bo.getMetricName(); String metricName = bo.getMetricName();
Date boStartTime = bo.getStartTime(); Date boStartTime = bo.getStartTime();
Date boEndTime = bo.getEndTime(); Date boEndTime = bo.getEndTime();
Integer isCityBrain = bo.getIsCityBrain();
MainlineSchemeEvaluateVO res = new MainlineSchemeEvaluateVO(); MainlineSchemeEvaluateVO res = new MainlineSchemeEvaluateVO();
...@@ -932,7 +933,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -932,7 +933,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
String strategyCode = strategyPO.getStrategyCode(); String strategyCode = strategyPO.getStrategyCode();
setCurveElementListAndEvaluateList(dirName, metricName, greenwaveId, boStartTime, boEndTime, startHourMinuteStr, setCurveElementListAndEvaluateList(dirName, metricName, greenwaveId, boStartTime, boEndTime, startHourMinuteStr,
endHourMinuteStr, res, strategyCode); endHourMinuteStr, res, strategyCode, isCityBrain);
return res; return res;
} }
...@@ -1383,7 +1384,8 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -1383,7 +1384,8 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
private void setCurveElementListAndEvaluateList( private void setCurveElementListAndEvaluateList(
String dirName, String metricName, Integer greenwaveId, Date boStartTime, Date boEndTime, String dirName, String metricName, Integer greenwaveId, Date boStartTime, Date boEndTime,
String startHourMinuteStr, String endHourMinuteStr, MainlineSchemeEvaluateVO res, String strategyCode) { String startHourMinuteStr, String endHourMinuteStr, MainlineSchemeEvaluateVO res, String strategyCode,
Integer isCityBrain) {
String boStartTimeStr = sdf.format(boStartTime); String boStartTimeStr = sdf.format(boStartTime);
String boEndTimeStr = sdf.format(boEndTime); String boEndTimeStr = sdf.format(boEndTime);
...@@ -1391,16 +1393,25 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -1391,16 +1393,25 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
// 获取绿波历史数据 // 获取绿波历史数据
List<GreenwaveHistPO> greenwaveHistPOList = greenwaveHistMapper List<GreenwaveHistPO> greenwaveHistPOList = greenwaveHistMapper
.selectByIdAndTimeSection(greenwaveId, boStartTimeStr, boEndTimeStr); .selectByIdAndTimeSection(greenwaveId, boStartTimeStr, boEndTimeStr);
// 过滤时段内的数据
List<GreenwaveHistPO> filteredGreenwaveList = greenwaveHistPOList.stream() List<GreenwaveHistPO> filteredGreenwaveList;
.filter(po -> { if (ObjectUtil.isEmpty(isCityBrain)) {
try { // 过滤时段内的数据
return isTimeInRange(po.getGmtModified(), startHourMinuteStr, endHourMinuteStr); filteredGreenwaveList = greenwaveHistPOList.stream()
} catch (ParseException e) { .filter(po -> {
throw new RuntimeException(e); try {
} return isTimeInRange(po.getGmtModified(), startHourMinuteStr, endHourMinuteStr);
}) } catch (ParseException e) {
.collect(Collectors.toList()); throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
} else {
filteredGreenwaveList = greenwaveHistPOList.stream()
.filter(greenwaveHistPO -> !boStartTime.after(greenwaveHistPO.getGmtModified())
&& !boEndTime.before(greenwaveHistPO.getGmtModified()))
.collect(Collectors.toList());
}
// 获取绿波指标 // 获取绿波指标
double noparkPassRate = filteredGreenwaveList.stream() double noparkPassRate = filteredGreenwaveList.stream()
.mapToDouble(GreenwaveHistPO::getNoparkPassRate) .mapToDouble(GreenwaveHistPO::getNoparkPassRate)
...@@ -1556,7 +1567,12 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -1556,7 +1567,12 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
res.setEvaluateList(evaluateList); res.setEvaluateList(evaluateList);
// 生成曲线图 // 生成曲线图
List<String> timeArray = TimeArrayUtil.getCustomTimeIntervals(startHourMinuteStr, endHourMinuteStr, 5); List<String> timeArray;
if (ObjectUtil.isEmpty(isCityBrain)) {
timeArray = TimeArrayUtil.getCustomTimeIntervals(startHourMinuteStr, endHourMinuteStr, 5);
} else {
timeArray = TimeArrayUtil.getMultiDayTimeIntervals(boStartTime, boEndTime, 5);
}
if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.NO_PARK_PASS_RATE.getDescription()) if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.NO_PARK_PASS_RATE.getDescription())
|| Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.CORD_RELIABILITY.getDescription()) || Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.CORD_RELIABILITY.getDescription())
|| Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.UNCOORDINATE_PHASE_QUEUE.getDescription()) || Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.UNCOORDINATE_PHASE_QUEUE.getDescription())
......
...@@ -3,8 +3,9 @@ package net.wanji.common.utils.tool; ...@@ -3,8 +3,9 @@ package net.wanji.common.utils.tool;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author Kent HAN * @author Kent HAN
...@@ -90,4 +91,24 @@ public class TimeArrayUtil { ...@@ -90,4 +91,24 @@ public class TimeArrayUtil {
System.out.println(interval); System.out.println(interval);
} }
} }
/**
* 跨天生成时间数组。如 ["23:55", "00:00" ... ]
* minutes,分钟段。如按每15分钟生成,则 minute 传15。
* @author Kent HAN
* @date 2022/11/3 16:30
*/
public static List<String> getMultiDayTimeIntervals(Date boStartTime, Date boEndTime, int minutes) {
List<String> intervals = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Calendar calendar = Calendar.getInstance();
calendar.setTime(boStartTime);
while (!calendar.getTime().after(boEndTime)) {
intervals.add(sdf.format(calendar.getTime()));
calendar.add(Calendar.MINUTE, minutes);
}
return intervals;
}
} }
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