Commit c757e95c authored by zhoushiguang's avatar zhoushiguang

拥堵时段、峰期计算表bug修改

parent f7d8b3b5
......@@ -546,10 +546,16 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
}
}
public static void main(String[] args) {
System.out.println( LocalDate.of(2025,6,1).toString());
}
public void selectCountByLandData() throws ParseException {
LocalDate currentDate = LocalDate.now();
// currentDate = LocalDate.of(2025,6,2);
// 获取本周一的日期
LocalDate mondayOfThisWeek = currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
LocalDate mondayOfThisWeek = currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
// 获取上周一的日期
LocalDate todayOfWeek = mondayOfThisWeek.plusDays(-7);
//获取上周日的日期
......@@ -576,13 +582,13 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
if(temp.getGreenId().equals(greenId)){
if(queue.size() == 2){
//判断流量是否大于阀值
if(trafficThreshold < temp.getTrafficIndex() && com.github.pagehelper.util.StringUtil.isEmpty(startTime)){
if(trafficThreshold < temp.getTrafficIndex() && StringUtil.isEmpty(startTime)){
startTime = temp.getStartTime();
list.add(temp);
} else if( temp.getTrafficIndex() < trafficThreshold &&
queue.getFirst().getTrafficIndex() < trafficThreshold &&
queue.getLast().getTrafficIndex() < trafficThreshold &&
!com.github.pagehelper.util.StringUtil.isEmpty(startTime) ){
!StringUtil.isEmpty(startTime) ){
if(list.size() < 10){
startTime = "";
list.clear();
......@@ -637,7 +643,11 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("avgFlow",avgFlow);
map.put("greenId",temp.getGreenId());
map.put("trafficThreshold",trafficThreshold);
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
try {
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
}catch (Exception e){
log.error("入库异常,params:"+map,e);
}
//清空数据
startTime = "";
endTime = "";
......@@ -656,7 +666,7 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
greenId = temp.getGreenId();
roadDirection = temp.getRoadDirection();
//计算该干线交通指数阈值,取一天的9点至16点30之间交通指数倒序的90%的数值为动态阈值
List<laneDataHist> greenTrafficList = analysisGreenCongestionPeriodMapper.selectGreenTrafficThreshold(date.toString().replaceAll("-",""),greenId,roadDirection);
List<laneDataHist> greenTrafficList = analysisGreenCongestionPeriodMapper.selectGreenTrafficThreshold(date.toString(),greenId,roadDirection);
if(greenTrafficList.get(9).getTrafficIndex() <= 1.5) {
trafficThreshold = 1.5;
}else {
......@@ -735,7 +745,11 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("avgFlow",avgFlow);
map.put("greenId",queue.getFirst().getGreenId());
map.put("trafficThreshold",trafficThreshold);
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
try {
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
}catch (Exception e){
log.error("入库异常,params:"+map,e);
}
queueCorss.clear();
if(peakDetailList.get(b).getPeakType().equals("2")) {
startTime = date.toString() + " 08:00:00";
......@@ -802,7 +816,11 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("avgFlow",avgFlow);
map.put("greenId",peakDetailList.get(b).getGreenId());
map.put("trafficThreshold",trafficThreshold);
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
try {
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
}catch (Exception e){
log.error("入库异常,params:"+map,e);
}
startTime = "";
endTime = "";
queue.clear();
......@@ -860,7 +878,11 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("avgFlow", avgFlow);
map.put("greenId", peakDetailList.get(b).getGreenId());
map.put("trafficThreshold", trafficThreshold);
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
try {
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
}catch (Exception e){
log.error("入库异常,params:"+map,e);
}
startTime = "";
endTime = "";
queueCorss.clear();
......@@ -922,7 +944,11 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("avgFlow",avgFlow);
map.put("greenId",queue.getFirst().getGreenId());
map.put("trafficThreshold",trafficThreshold);
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
try {
analysisGreenCongestionPeriodMapper.insertLaneDataHist(map);
}catch (Exception e){
log.error("入库异常,params:"+map,e);
}
startTime = "";
endTime = "";
queueCorss.clear();
......@@ -966,13 +992,13 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
if(temp.getCrossId().equals(crossId)){
if(queue.size() == 2){
//判断流量是否大于阀值
if(trafficThreshold < temp.getTrafficIndex() && com.github.pagehelper.util.StringUtil.isEmpty(startTime)){
if(trafficThreshold < temp.getTrafficIndex() && StringUtil.isEmpty(startTime)){
startTime = temp.getStartTime();
list.add(temp);
} else if( temp.getTrafficIndex() < trafficThreshold &&
queue.getFirst().getTrafficIndex() < trafficThreshold &&
queue.getLast().getTrafficIndex() < trafficThreshold &&
!com.github.pagehelper.util.StringUtil.isEmpty(startTime) ){
!StringUtil.isEmpty(startTime) ){
if(list.size() < 10){
startTime = "";
list.clear();
......@@ -1436,13 +1462,13 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
if(temp.getCrossId().equals(crossId)){
if(queue.size() == 2){
//判断流量是否大于阀值
if(trafficThreshold < temp.getTrafficIndex() && com.github.pagehelper.util.StringUtil.isEmpty(startTime)){
if(trafficThreshold < temp.getTrafficIndex() && StringUtil.isEmpty(startTime)){
startTime = temp.getStartTime();
list.add(temp);
} else if( temp.getTrafficIndex() < trafficThreshold &&
queue.getFirst().getTrafficIndex() < trafficThreshold &&
queue.getLast().getTrafficIndex() < trafficThreshold &&
!com.github.pagehelper.util.StringUtil.isEmpty(startTime) ){
!StringUtil.isEmpty(startTime) ){
if(list.size() < 10){
startTime = "";
list.clear();
......
......@@ -31,7 +31,7 @@ public class AnalysisGreenCongestionPeriodWeekTask {
@Scheduled(cron = "0 30 2 ? * 1")
//@PostConstruct
public void task() throws ParseException {
public void task() {
try {
long st = System.currentTimeMillis();
......
......@@ -88,7 +88,7 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
long st = System.currentTimeMillis();
try {
//获取上周数据
List<StrategyGreenOptHistDTO> list = strategyGreenOptHistMapper.findGreenWaveOptHist();
//按干线+天分组
Map<String, List<StrategyGreenOptHistDTO>> groupByGreenId = list.stream().collect(Collectors.groupingBy(o -> o.getGreenId()+"_"+DateUtil.format(o.getControlTime(), Constants.DATE_FORMAT.E_DATE_FORMAT_DAY)));
......@@ -192,7 +192,7 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
/**
* 单点策略优化时长计算
* 单点策略优化时长计算【每天计算一次】
*/
// @Scheduled(cron = "0 0/6 * * * * ")
@Scheduled(cron = "0 20 3 * * * ")
......@@ -201,19 +201,24 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
long st = System.currentTimeMillis();
try {
//路口策略下方记录
Date nowDate = cn.hutool.core.date.DateUtil.date();
Date beginOfDay = cn.hutool.core.date.DateUtil.beginOfDay(nowDate);//.lastWeek();//
//从昨天凌晨开始
Date beginOfDay = cn.hutool.core.date.DateUtil.yesterday();
beginOfDay = cn.hutool.core.date.DateUtil.beginOfDay(beginOfDay);
beginOfDay = cn.hutool.core.date.DateUtil.lastWeek();
beginOfDay = cn.hutool.core.date.DateUtil.beginOfWeek(beginOfDay);
Date endOfDay = cn.hutool.core.date.DateUtil.beginOfDay(new Date());
Date endOfDay = cn.hutool.core.date.DateUtil.endOfDay(nowDate);//DateUtil.endOfDay(DateUtil.date());
//=========================================================//
//手动补充数据
//beginOfDay = DateUtil.parse("2025-06-08 00:00:00","yyyy-MM-dd HH:mm:ss");
//endOfDay = DateUtil.parse("2025-06-09 00:00:00","yyyy-MM-dd HH:mm:ss");
//==========================================================//
while (beginOfDay.before(endOfDay)) {
String startDate = cn.hutool.core.date.DateUtil.format(beginOfDay, "yyyy-MM-dd HH:mm:ss");
//向后推一天
beginOfDay = cn.hutool.core.date.DateUtil.offsetDay(beginOfDay, 1);
String endDate = cn.hutool.core.date.DateUtil.format(beginOfDay, "yyyy-MM-dd HH:mm:ss");
//==========================================================================================================//
......@@ -251,7 +256,7 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
//==========================================================================================================//
List<AnalysisReportCrossOptimizeDetail> optimizeList = new ArrayList<>();
this.saveOptimizeInfo(optimizeList, list, startDate);
this.saveCrossOptimizeInfo(optimizeList, list, startDate);
//==========================================================================================================//
if (!optimizeList.isEmpty()) {
analysisReportCrossOptimizeDetailMapper.insertBatch(optimizeList);
......@@ -268,7 +273,7 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
}
private void saveOptimizeInfo(List<AnalysisReportCrossOptimizeDetail> optimizeList, List<StrategyCrossResultEntity> list, String startDate) {
private void saveCrossOptimizeInfo(List<AnalysisReportCrossOptimizeDetail> optimizeList, List<StrategyCrossResultEntity> list, String startDate) {
long et1 = System.currentTimeMillis();
Map<String, List<StrategyCrossResultEntity>> groupByCross = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getCurrentAlgo()));
for (Map.Entry<String, List<StrategyCrossResultEntity>> entry : groupByCross.entrySet()) {
......@@ -433,10 +438,4 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
}
public static void main(String[] args) {
DateTime issueTime = new DateTime();
System.out.println(issueTime.getDayOfWeek());
}
}
......@@ -14,6 +14,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
@Component
......@@ -28,11 +30,12 @@ public class TablePartitionManagerTask {
@Value("${partition.table.list}")
private String partitionTableList;
@Scheduled(cron = "0 1/60 * * * *")
@Scheduled(cron = "0 0/60 * * * *")
public void createTablePartition() {
String[] tableList = partitionTableList.split(",");
DateTime tomorrow = DateTime.now().offset(DateField.HOUR,1);
DateTime tomorrow = DateTime.now().offset(DateField.HOUR,24);
Integer dt = Integer.parseInt(DateUtil.format(tomorrow.toJdkDate(), "yyyyMMdd"));
......
......@@ -53,21 +53,21 @@
<!-- 查询上周优化记录 -->
<select id="findGreenWaveOptHist" resultType="net.wanji.opt.dto.report.StrategyGreenOptHistDTO">
SELECT a.green_id,
a.dir AS road_direction,
a.type AS stragety_id,
a.control_time,
a.control_duration,
a.control_method,
MIN(CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) + 7) * INTERVAL '1 day') AS week_start_day,
MAX(CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) + 1) * INTERVAL '1 day') AS week_end_day,
EXTRACT(YEAR FROM control_time) || '' || (TO_CHAR(control_time, 'WW') :: INT + 1) AS year_week,
EXTRACT(DOW FROM control_time) + 1 AS week_day
a.dir AS road_direction,
a.type AS stragety_id,
a.control_time,
a.control_duration,
a.control_method,
MIN(CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) + 6) * INTERVAL '1 day') AS week_start_day,
MAX(CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) -1) * INTERVAL '1 day' - INTERVAL '1 second') AS week_end_day,
EXTRACT(YEAR FROM control_time) || '' || (TO_CHAR(control_time, 'WW') :: INT + 1) AS year_week,
EXTRACT(DOW FROM control_time) AS week_day
FROM t_strategy_green_opt_hist a
WHERE control_time >= CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) + 7) * INTERVAL '1 day'
AND control_time &lt; CURRENT_DATE - EXTRACT(DOW FROM CURRENT_DATE) * INTERVAL '1 day'
AND control_method IN (-1, 1)
WHERE control_time >= CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) + 6) * INTERVAL '1 day'
AND control_time &lt;= CURRENT_DATE - (EXTRACT(DOW FROM CURRENT_DATE) -1) * INTERVAL '1 day' - INTERVAL '1 second'
AND control_method IN (-1, 1)
GROUP BY green_id, control_time, control_duration, control_method
ORDER BY green_id, control_time
ORDER BY green_id, control_time;
</select>
</mapper>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<!-- 表子分区创建 -->
<select id="createTablePartition">
create table ${partitionName} partition of ${tableName} for values in (${dt});
create table if not exists ${partitionName} partition of ${tableName} for values in (${dt});
</select>
......
......@@ -60,7 +60,7 @@
select t.green_id,t1.key_cross_id as cross_id, t1.road_direction,t1.dir,t1.turn,t.start_time,t.traffic_index
from t_greenwave_hist t
left join t_greenwave_key_cross_lane t1 on t.green_id = t1.green_id and t.road_direction = t1.road_direction
where t.start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 00:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 23:59:59')
where t.start_time::DATE BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD') and TO_TIMESTAMP(#{date},'YYYY-MM-DD')
and t1.dir is not null
order by t.green_id,t1.road_direction,t1.dir,t1.turn,t.start_time
</select>
......@@ -68,7 +68,7 @@
<select id="selectGreenTrafficThreshold" parameterType="String" resultMap="AnalysisLaneDataHistMap">
select t.green_id,t.traffic_index
from t_greenwave_hist t
where t.start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 09:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 16:30:10')
where t.start_time BETWEEN TO_TIMESTAMP(#{date}||' 09:00:00','YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(#{date}||' 16:30:10','YYYY-MM-DD HH24:MI:SS')
and CAST(t.green_id AS VARCHAR) = #{greenId}
and t.road_direction = #{roadDirection}
order by t.traffic_index desc
......@@ -78,9 +78,12 @@
select t4.cross_id,t4.start_time,sum(t4.flow) as flow from
(select t2.id , t3.key_cross_id as cross_id , t2.start_time , t2.flow from t_lane_data_hist t2
left join
(select t.id , t1.key_cross_id from t_base_lane_info t
left join t_greenwave_key_cross_lane t1 on t1.key_cross_id = t.cross_id and t1.dir = t.dir
where t1.key_cross_id is not null and t.type = 2) t3 on t2.id = t3.id
(
select t.id , t1.key_cross_id from t_base_lane_info t
left join t_greenwave_key_cross_lane t1
on t1.key_cross_id = t.cross_id and t1.dir::INT = t.dir
where t1.key_cross_id is not null and t.type = 2
) t3 on t2.id = t3.id
where t3.key_cross_id is not null and dt = CAST(#{date} AS INT4) ) t4
where t4.cross_id = #{crossId}
and t4.start_time between DATE_SUB(#{startTime},INTERVAL '10 MINUTE') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
......@@ -100,7 +103,7 @@
and CAST(a.green_id AS VARCHAR) = #{greenId}
and a.road_direction = #{roadDirection}
ON CONFLICT (green_id,road_direction,week_day,peak_start_time,status,year_week)
ON CONFLICT (green_id,road_direction,week_day,peak_start_time,year_week)
DO UPDATE SET
traffic_index=excluded.traffic_index ,
status=excluded.status ,
......
......@@ -350,13 +350,14 @@
<!-- 新增表t_analysis_problem_cross_dir_hour信息 -->
<insert id="insertAnalysisProblemCrossHour">
insert into t_analysis_problem_cross_dir_hour (id,cross_id,area_id,event_category,event_type,dir,event_number,event_total_time,window_start_time,window_end_time,dt,insert_time)
insert into t_analysis_problem_cross_dir_hour (id,cross_id,area_id,event_category,event_type,dir,turn,event_number,event_total_time,window_start_time,window_end_time,dt,insert_time)
select uuid_generate_v4(),
d.cross_id,
e.area_id,
d.category,
d.type,
cast(d.dir as int),
cast((case when d.turn='ul' then '0' else d.turn end) as int),
count(1) as event_number ,
sum( extract(epoch from (d.end_time - d.start_time)) ) as duration ,
TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL '1 HOUR') AS VARCHAR),'YYYY-MM-DD HH24:00:00') as dh1,
......@@ -365,9 +366,9 @@
now()
from
(
select DISTINCT b.cross_id,b.category,b.type,b.start_time,b.end_time, unnest(string_to_array(dir, ',')) AS dir
select DISTINCT b.cross_id,b.category,b.type,b.start_time,b.end_time, unnest(string_to_array(dir, ',')) AS dir,unnest(string_to_array(turn, ',')) AS turn
from
(select a.cross_id,a.category,a.type,a.start_time,a.end_time,SUBSTR(a.dir,2,LENGTH(a.dir)-2) as dir
(select a.cross_id,a.category,a.type,a.start_time,a.end_time,SUBSTR(a.dir,2,LENGTH(a.dir)-2) as dir,SUBSTR(a.turn,2,LENGTH(a.turn)-2) as turn
from t_event_info a
where a.start_time >= TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL '1 HOUR') AS VARCHAR),'YYYY-MM-DD HH24:00:00')
and a.start_time <![CDATA[ < ]]> TO_TIMESTAMP(CAST(now() AS VARCHAR),'YYYY-MM-DD HH24:00:00')
......@@ -377,7 +378,7 @@
) b
) d
left join t_base_cross_info e on d.cross_id = e.id
group by d.cross_id, e.area_id,d.category,d.type,d.dir
group by d.cross_id, e.area_id,d.category,d.type,d.dir,d.turn
ON CONFLICT(dt,dir,cross_id,window_start_time,event_type)
DO UPDATE SET
id=excluded.id,
......@@ -386,7 +387,9 @@
event_number=excluded.event_number,
event_total_time=excluded.event_total_time,
window_end_time=excluded.window_end_time,
insert_time=excluded.insert_time
insert_time=excluded.insert_time,
dir = excluded.dir,
turn = excluded.turn
;
</insert>
......
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