Commit f74c43eb authored by 杜伟's avatar 杜伟

路口级查询

parent 32a958d0
......@@ -344,6 +344,12 @@ public class TrendController {
/**
* 车道交通指标 - 路口级
* 条件:
* {
* "granularity": "5m",
* "crossId": "12345",
* "start": "2024-05-15 10:00:00",
* "end": "2025-05-15 11:00:00"
* }
* @param periodCrossingVO
* @return
* @throws Exception
......
......@@ -19,6 +19,7 @@ import net.wanji.databus.dao.mapper.*;
import net.wanji.databus.dto.MetricHistDTO;
import net.wanji.databus.po.*;
import net.wanji.databus.vo.AbnormalCrossListVO;
import net.wanji.databus.vo.CrossDataHistVO;
import net.wanji.databus.vo.CrossDirDataHistVO;
import net.wanji.databus.vo.GreenwaveListVO;
import net.wanji.opt.bo.*;
......@@ -1641,31 +1642,40 @@ public class TrendServiceImpl implements TrendService {
* @param poExtList
* @return
*/
private List<CrossingQueryVO.CycleDataElement> buildCrossingCycleData(String crossId, List<CrossLaneDataHistPOExt> poExtList) {
private List<CrossingQueryVO.CycleDataElement> buildCrossingCycleData(String crossId, List<CrossDataHistVO> poExtList) {
List<CrossingQueryVO.CycleDataElement> res = new ArrayList<>();
int pedFlow = 0;
for (CrossLaneDataHistPOExt po : poExtList) {
for (CrossDataHistVO po : poExtList) {
CrossingQueryVO.CycleDataElement vo = new CrossingQueryVO.CycleDataElement();
if (po.getId().contains(crossId.concat(Constants.SystemParam.SEPARATOR_MINUS))) {
pedFlow += po.getFlow();
}
Integer batchTime = po.getBatchTime();
// 将10位时间戳转换为毫秒
long millis = batchTime * 1000L;
// 使用毫秒值创建Date对象
Date dateFromTimestamp = new Date(millis);
vo.setTime(dateFromTimestamp);
// vo.setDir(po.getDir());
// vo.setDirName(BaseEnum.SignalDirectionEnum.getNameByCode(po.getDir()));
vo.setTime(po.getStartTime());
vo.setFlow(po.getFlow());
vo.setPedFlow(pedFlow);
vo.setNonMotorFlow(0);//非机动车流量
vo.setTrafficFlowA( po.getTrafficFlowA());
vo.setTrafficFlowB( po.getTrafficFlowB());
vo.setTrafficFlowC( po.getTrafficFlowC());
Double speed = po.getSpeed();
vo.setSpeed((int) Math.round(speed));
vo.setVehheadDist(0d);//车头间距
Double vehheadTime = 0d;
vo.setVehheadTime((int) Math.round(vehheadTime));//车头时距
Double queueLength = po.getQueueLength();
vo.setQueueLength((int) Math.round(queueLength));
Double stopTimes = po.getStopTimes();
vo.setStopTimes((int) Math.round(stopTimes));
//----------------------------------------------------------------------------------------------
// if (po.getId().contains(crossId.concat(Constants.SystemParam.SEPARATOR_MINUS))) {
// pedFlow += po.getFlow();
// }
// Integer batchTime = po.getBatchTime();
// 将10位时间戳转换为毫秒
// long millis = batchTime * 1000L;
// 使用毫秒值创建Date对象
// Date dateFromTimestamp = new Date(millis);
// vo.setTime(dateFromTimestamp);
Integer delayTime = po.getDelayTime();
vo.setDelayTime(delayTime);
......@@ -1674,10 +1684,6 @@ public class TrendServiceImpl implements TrendService {
//效率评价等级
vo.setEfficiencyEvaluateLevel(0.0);
Double stopTimes = po.getStopTimes();
vo.setStopTimes((int) Math.round(stopTimes));
Double vehheadTime = po.getVehheadTime();
vo.setVehheadTime((int) Math.round(vehheadTime));
//饱和度
vo.setSaturation(0.0);//po.getSaturation()
//拥堵指数
......@@ -1735,20 +1741,16 @@ public class TrendServiceImpl implements TrendService {
//行人闯红灯率
vo.setPedCrossRedLightRate(0.0);
vo.setVehheadDist(po.getVehheadDist());
vo.setTrafficFlowA(po.getTrafficFlowA());
vo.setTrafficFlowB(po.getTrafficFlowB());
vo.setTrafficFlowC(po.getTrafficFlowC());
// vo.setVehheadDist(po.getVehheadDist());
// vo.setTrafficFlowA(po.getTrafficFlowA());
// vo.setTrafficFlowB(po.getTrafficFlowB());
// vo.setTrafficFlowC(po.getTrafficFlowC());
vo.setNonMotorFlow(po.getNonMotorFlow());
vo.setV85(Math.round(po.getV85() * 100) / 100);
vo.setPedFlow(pedFlow);
vo.setAllFlow(pedFlow + po.getNonMotorFlow() + po.getFlow());
vo.setAllVehiceleFlow(po.getFlow() + po.getNonMotorFlow());
vo.setTurn(po.getTurn());
String dirName = BaseEnum.SignalDirectionEnum.getNameByCode(po.getDir());
String turnName = TurnConvertEnum.getDescByKey(po.getTurn());
vo.setLaneSort(String.join("-", dirName, turnName, String.valueOf(po.getSort())));
// vo.setTurn(po.getTurn());
res.add(vo);
}
......@@ -2317,10 +2319,11 @@ public class TrendServiceImpl implements TrendService {
String granularity = lanePeriodTurnVO.getGranularity();
if (StringUtils.isBlank(granularity)) {
granularity = "5";
}else {
granularity = granularity.replace("m", "");
}
// 查询周期数据
// List<CrossLaneDataHistPOExt> poExtList = crossLaneDataHistMapper.selectByCrossIdAndTimeSpan(crossId, start, end);
List<CrossDirDataHistVO> vo = crossDirDataHistMapper.selectByCrossIdAndStartEndDir(crossId, start, end, dirType, granularity);
return buildCrossingDirectionCycleData(crossId, vo);
} catch (Exception e) {
......@@ -2340,23 +2343,19 @@ public class TrendServiceImpl implements TrendService {
try {
//路口
String crossId = lanePeriodTurnVO.getCrossId();
// Date start = lanePeriodTurnVO.getStart();
// Date end = lanePeriodTurnVO.getEnd();
int start = (int) (lanePeriodTurnVO.getStart().getTime() / 1000);
int end = (int) (lanePeriodTurnVO.getEnd().getTime() / 1000);
//分析粒度【5m:五分钟 10m:10分钟 30m:30分钟 1h:一小时】
String granularity = lanePeriodTurnVO.getGranularity();
if (StringUtils.isBlank(granularity)) {
granularity = "5m";
granularity = "5";
}else {
granularity = granularity.replace("m", "");
}
// LambdaQueryWrapper<AnalysisRidTurnIndicators> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(AnalysisRidTurnIndicators::getCrossId, crossId);
// queryWrapper.eq(AnalysisRidTurnIndicators::getGranularity, granularity);
// queryWrapper.between(AnalysisRidTurnIndicators::getWindowStartTime, start, end);
// queryWrapper.orderByDesc(AnalysisRidTurnIndicators::getWindowStartTime);
// return ridTurnIndicatorsMapper.selectList(queryWrapper);
// 查询周期数据
List<CrossLaneDataHistPOExt> poExtList = crossLaneDataHistMapper.selectByCrossIdAndTimeSpan(crossId, start, end);
return buildCrossingCycleData(crossId, poExtList);
List<CrossDataHistVO> vo = crossDataHistMapper.selectByCrossIdAndStartEndStat(crossId, start, end, granularity);
return buildCrossingCycleData(crossId, vo);
} catch (Exception e) {
log.error("路口周期数据方向级查询异常:", e);
throw new OptServiceException(e);
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.databus.dto.MetricHistDTO;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDataHistPOExt;
import net.wanji.databus.vo.CrossDataHistVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -24,6 +25,8 @@ public interface CrossDataHistMapper extends BaseMapper<CrossDataHistPO> {
List<CrossDataHistPO> selectByCrossIdAndStartEnd(String crossId, int startStamp, int endStamp);
List<CrossDataHistVO> selectByCrossIdAndStartEndStat(String crossId, int startStamp, int endStamp, String granularity);
List<MetricHistDTO> selectMetricHistDTO(String crossId, int startStamp, int endStamp);
Double selectMaxSaturation(String crossId, int startStamp, int endStamp);
......
package net.wanji.databus.vo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import net.wanji.databus.po.CrossDataRealtimePO;
/**
* 路口统统计VO
*/
@Data
@ApiModel(value = "CrossDataHistVO", description = "路口实时数据历史")
public class CrossDataHistVO extends CrossDataRealtimePO {
}
......@@ -95,6 +95,44 @@
and batch_time <![CDATA[ <= ]]> #{endStamp}
order by batch_time
</select>
<!-- 交通指标-路口级统计 -->
<select id="selectByCrossIdAndStartEndStat" resultType="net.wanji.databus.vo.CrossDataHistVO">
SELECT
cross_id AS crossId,
<choose>
<!-- 小时 -->
<when test="granularity==1">
DATE_FORMAT(start_time, '%Y-%m-%d %H:00:00') AS startTime,
</when>
<!-- 分钟 -->
<otherwise>
DATE_FORMAT(
CONCAT( DATE ( start_time ), ' ', HOUR ( start_time ), ':', FLOOR( MINUTE ( start_time ) / #{granularity} ) * #{granularity} ),
'%Y-%m-%d %H:%i:00'
) AS startTime,
</otherwise>
</choose>
SUM( flow ) AS flow,
avg( traffic_flow_C ) AS trafficFlowC,
avg( traffic_flow_B ) AS trafficFlowB,
avg( traffic_flow_A ) AS trafficFlowA,
avg( speed ) AS speed,
MAX( queue_length ) AS queueLength,
AVG( stop_times ) AS stopTimes
FROM
t_cross_data_hist
WHERE 1=1
<if test="crossId != null">
AND cross_id = #{crossId}
</if>
and batch_time <![CDATA[ >= ]]> #{startStamp}
and batch_time <![CDATA[ <= ]]> #{endStamp}
GROUP BY
cross_id,
startTime
ORDER BY
startTime DESC
</select>
<select id="selectMetricHistDTO" resultType="net.wanji.databus.dto.MetricHistDTO">
select status, start_time, duration, flow, speed, sturation, stop_times, delay_time, batch_time, one_stop_rate, queue_length, effusion_rate, no_stop_rate, green_light_efficiency, load_balance
......
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