Commit 935eeb52 authored by zhoushiguang's avatar zhoushiguang

路口缓行事件计算

parent 9b9a2a94
......@@ -121,5 +121,10 @@ public interface AnalysisProblemCrossDayMapper extends BaseMapper<AnalysisProble
* 绿波干线小时粒度拥堵数据
*/
void insertGreenCrossHourData(@Param("startTime")String startTime,@Param("endTime")String endTime);
/**
* 路口缓行数据天统计
*/
void insertAnalysisCrossSlowRunDay(@Param("dt") Integer dt);
}
......@@ -78,4 +78,9 @@ public interface AnalysisProblemCrossDayService extends IService<AnalysisProblem
void insertAnalysisProblemCrossDay();
public void insertGreenCrossHourData(String startTime, String endTime);
/**
* 路口缓行数据天统计
*/
void insertAnalysisCrossSlowRunDay(Integer dt);
}
......@@ -228,4 +228,9 @@ public class AnalysisProblemCrossDayServiceImpl extends ServiceImpl<AnalysisProb
analysisProblemCrossDayMapper.insertGreenCrossHourData(startTime,endTime);
}
@Override
public void insertAnalysisCrossSlowRunDay(Integer dt) {
analysisProblemCrossDayMapper.insertAnalysisCrossSlowRunDay(dt);
}
}
package net.wanji.opt.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.dao.mapper.judgeanalysis.AnalysisProblemCrossDayMapper;
import net.wanji.opt.dao.mapper.judgeanalysis.AnalysisProblemGreenDayMapper;
......@@ -33,22 +35,35 @@ public class AnalysisProblemDayTask {
private AnalysisProblemGreenDayServiceImpl nalysisProblemGreenDayServiceImpl;
@Scheduled(cron = "0 15 0 ? * *")
public void task(){
//执行检查路口id是否还有area_id没赋值的数据
analysisProblemCrossDayServiceImpl.updateCrossAreaIdByCondition();
//执行检查绿波id是否还有area_id没赋值的数据
nalysisProblemGreenDayServiceImpl.updateGreenAreaIdByCondition();
//检查昨日数据是否有统计
List<AnalysisProblemCrossDay> list = analysisProblemCrossDayMapper.checkData();
if(list.isEmpty())
{
analysisProblemCrossDayMapper.insertAnalysisProblemCrossDay();
public void task() {
try {
//执行检查路口id是否还有area_id没赋值的数据
analysisProblemCrossDayServiceImpl.updateCrossAreaIdByCondition();
//检查昨日数据是否有统计
List<AnalysisProblemCrossDay> list = analysisProblemCrossDayMapper.checkData();
if (list.isEmpty()) {
analysisProblemCrossDayMapper.insertAnalysisProblemCrossDay();
//路口缓行事件数据单独计算
long st = System.currentTimeMillis();
DateTime yesterday = DateUtil.yesterday();
String dt = yesterday.toString("yyyyMMdd");
analysisProblemCrossDayMapper.insertAnalysisCrossSlowRunDay(Integer.valueOf(dt) );
long et = System.currentTimeMillis();
log.info("路口缓行按天统计耗时:{}ms,day:", et-st,dt);
}
} catch (Exception e) {
log.error("路口问题天数据统计异常",e);
}
//检查昨日数据是否有统计
List<AnalysisProblemGreenDay> list1 = analysisProblemGreenDayMapper.checkData();
if(list1.isEmpty())
{
analysisProblemGreenDayMapper.insertAnalysisProblemGreenDay();
try {
//执行检查绿波id是否还有area_id没赋值的数据
nalysisProblemGreenDayServiceImpl.updateGreenAreaIdByCondition();
//检查昨日数据是否有统计
List<AnalysisProblemGreenDay> list1 = analysisProblemGreenDayMapper.checkData();
if (list1.isEmpty()) {
analysisProblemGreenDayMapper.insertAnalysisProblemGreenDay();
}
}catch (Exception e) {
log.error("干线问题天数据统计异常",e);
}
}
}
......@@ -209,56 +209,134 @@
<!-- 新增表t_analysis_problem_cross_day信息 -->
<insert id="insertAnalysisProblemCrossDay">
<!-- 先设置会话级group_conct的最大长度 -->
SET SESSION group_concat_max_len = 1048576;
insert into t_analysis_problem_cross_day (id,cross_id,area_id,event_category,event_type,event_number,event_total_time,dt,insert_time,
serious_time_span,serious_duration,time_span_list,week_day,year_week)
select UUID(), a.cross_id, b.area_id,a.category,a.type,count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, a.start_time , a.end_time) ) as duration ,
DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d') as dt , now(),
SUBSTRING_INDEX(
GROUP_CONCAT(
CONCAT(
date_format(a.start_time,'%H:%i:%s'),
'~',
CONCAT(date_format(a.end_time,'%H:%i:%s'))
)
ORDER BY TIMESTAMPDIFF( SECOND, a.start_time, a.end_time ) desc
)
,',',1) as serious_time_span,
max(TIMESTAMPDIFF( SECOND, a.start_time, a.end_time )) as serious_duration,
GROUP_CONCAT(CONCAT(
date_format(a.start_time,'%H:%i:%s'),
'~',
CONCAT(date_format(a.end_time,'%H:%i:%s'))
)
) time_span_list,
(WEEKDAY(start_time)+1) week_day,
concat(year(start_time),'',(week(start_time)+1)) year_week
from t_event_info a
left join t_base_cross_info b on a.cross_id = b.id
where dt = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d') and a.type in (701,702,703,707)
group by a.cross_id, b.area_id,a.category,a.type
ON DUPLICATE KEY UPDATE
id=VALUES(id),
cross_id=VALUES(cross_id),
area_id=VALUES(area_id),
event_category=VALUES(event_category),
event_type=VALUES(event_type),
event_number=VALUES(event_number),
event_total_time=VALUES(event_total_time),
window_start_time=VALUES(window_start_time),
window_end_time=VALUES(window_end_time),
dt=VALUES(dt),
insert_time=VALUES(insert_time),
serious_time_span=VALUES(serious_time_span),
serious_duration=VALUES(serious_duration),
time_span_list=VALUES(time_span_list),
week_day=VALUES(week_day),
year_week=VALUES(year_week)
</insert>
<!-- 先设置会话级group_conct的最大长度 -->
SET SESSION group_concat_max_len = 1048576;
insert into t_analysis_problem_cross_day (id,cross_id,area_id,event_category,event_type,event_number,event_total_time,dt,insert_time,
serious_time_span,serious_duration,time_span_list,week_day,year_week)
select UUID(), a.cross_id, b.area_id,a.category,a.type,count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, a.start_time , a.end_time) ) as duration ,
DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d') as dt , now(),
SUBSTRING_INDEX(
GROUP_CONCAT(
CONCAT(
date_format(a.start_time,'%H:%i:%s'),
'~',
CONCAT(date_format(a.end_time,'%H:%i:%s'))
)
ORDER BY TIMESTAMPDIFF( SECOND, a.start_time, a.end_time ) desc
)
,',',1) as serious_time_span,
max(TIMESTAMPDIFF( SECOND, a.start_time, a.end_time )) as serious_duration,
GROUP_CONCAT(CONCAT(
date_format(a.start_time,'%H:%i:%s'),
'~',
CONCAT(date_format(a.end_time,'%H:%i:%s'))
)
) time_span_list,
(WEEKDAY(start_time)+1) week_day,
concat(year(start_time),'',(week(start_time)+1)) year_week
from t_event_info a
left join t_base_cross_info b on a.cross_id = b.id
where dt = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d') and a.type in (701,702,703,707)
group by a.cross_id, b.area_id,a.category,a.type
ON DUPLICATE KEY UPDATE
id=VALUES(id),
cross_id=VALUES(cross_id),
area_id=VALUES(area_id),
event_category=VALUES(event_category),
event_type=VALUES(event_type),
event_number=VALUES(event_number),
event_total_time=VALUES(event_total_time),
window_start_time=VALUES(window_start_time),
window_end_time=VALUES(window_end_time),
dt=VALUES(dt),
insert_time=VALUES(insert_time),
serious_time_span=VALUES(serious_time_span),
serious_duration=VALUES(serious_duration),
time_span_list=VALUES(time_span_list),
week_day=VALUES(week_day),
year_week=VALUES(year_week)
</insert>
<!-- 路口缓行数据天统计 -->
<insert id="insertAnalysisCrossSlowRunDay" parameterType="map">
<!-- 先设置会话级group_conct的最大长度 -->
SET SESSION group_concat_max_len = 1048576;
insert into t_analysis_problem_cross_day (id,cross_id,area_id,event_category,event_type,event_number,event_total_time,dt,insert_time,
serious_time_span,serious_duration,time_span_list,week_day,year_week)
select UUID(),
a.cross_id,
b.area_id,
a.category,
a.type,
count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, a.start_time , a.end_time) ) as duration ,
DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d') as dt , now(),
SUBSTRING_INDEX(
GROUP_CONCAT(
CONCAT(
date_format(a.start_time,'%H:%i:%s'),
'~',
CONCAT(date_format(a.end_time,'%H:%i:%s'))
)
ORDER BY TIMESTAMPDIFF( SECOND, a.start_time, a.end_time ) desc
)
,',',1) as serious_time_span,
max(TIMESTAMPDIFF( SECOND, a.start_time, a.end_time )) as serious_duration,
GROUP_CONCAT(
CONCAT(
date_format(a.start_time,'%H:%i:%s'),
'~',
CONCAT(date_format(a.end_time,'%H:%i:%s'))
)
) time_span_list,
(WEEKDAY(start_time)+1) week_day,
concat(year(start_time),'',(week(start_time)+1)) year_week
from (
<!-- 路口缓行计算 -->
SELECT
cross_id,
start_time,
DATE_ADD( start_time, INTERVAL 5 MINUTE ) AS end_time,
dt,
'4' AS category,
'708' AS type
FROM
t_cross_dir_data_hist
WHERE
dt = #{dt}
AND `status` = 2
GROUP BY
cross_id,
start_time
HAVING
count(*)>=2
) a
left join t_base_cross_info b on a.cross_id = b.id
where a.dt = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d')
group by a.cross_id, b.area_id,a.category,a.type
ON DUPLICATE KEY UPDATE
id=VALUES(id),
cross_id=VALUES(cross_id),
area_id=VALUES(area_id),
event_category=VALUES(event_category),
event_type=VALUES(event_type),
event_number=VALUES(event_number),
event_total_time=VALUES(event_total_time),
window_start_time=VALUES(window_start_time),
window_end_time=VALUES(window_end_time),
dt=VALUES(dt),
insert_time=VALUES(insert_time),
serious_time_span=VALUES(serious_time_span),
serious_duration=VALUES(serious_duration),
time_span_list=VALUES(time_span_list),
week_day=VALUES(week_day),
year_week=VALUES(year_week)
</insert>
<!-- 新增表t_analysis_problem_cross_dir_hour信息 -->
<insert id="insertAnalysisProblemCrossHour">
......
......@@ -86,5 +86,21 @@ public class AnalysisProblemDayTaskTest {
}
}
@Test
public void insertCrossSlowRunDayData() throws ParseException {
try {
//路口缓行事件数据单独计算
DateTime yesterday = DateUtil.yesterday();
String dt = yesterday.toString("yyyyMMdd");
for (int i = 20250401; i < 20250428; i++) {
long st = System.currentTimeMillis();
analysisProblemCrossDayMapper.insertAnalysisCrossSlowRunDay(i);
long et = System.currentTimeMillis();
log.info("路口缓行按天统计:耗时{}ms,dt={}", et-st,i);
}
} catch (Exception e) {
log.error("", e);
}
}
}
......@@ -85,7 +85,7 @@ public class AnalysisProblemGreenHourController {
@ApiImplicitParams({
@ApiImplicitParam(name = "greenId", value = "绿波干线", required = true, dataType = "Integer", defaultValue = "1"),
// @ApiImplicitParam(name = "timeType", value = "事件类型 1:近一个月 2:近一周", required = false, dataType = "Integer", defaultValue = "1"),
@ApiImplicitParam(name = "eventType", value = "事件代码 701:空放 702:路口失衡,703:路口溢出 707:路口拥堵", required = true, dataType = "String", defaultValue = "705"),
@ApiImplicitParam(name = "eventType", value = "事件代码 701:空放 702:路口失衡,703:路口溢出 707:路口拥堵 708: 路口缓行", required = true, dataType = "String", defaultValue = "705"),
@ApiImplicitParam(name = "startTime", value = "开始时间,格式:yyyyMMdd", required = false, dataType = "Integer", defaultValue = "20250317"),
@ApiImplicitParam(name = "endTime", value = "结束时间,格式:yyyyMMdd", required = false, dataType = "Integer", defaultValue = "20250318"),
})
......
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