insert into t_analysis_problem_green_day (id,green_id,area_id,event_category,event_type,event_number,event_total_time,dt,insert_time)
select UUID(), a.green_id, b.area_id,a.category,a.type,count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, a.start_time , a.end_time) ) as duration ,
select uuid_generate_v4(), a.green_id, b.area_id,a.category,a.type,count(1) as event_number ,
sum( extract(epoch from (a.end_time - a.start_time)) ) as duration ,
dt , now()
from t_event_info a
left join t_greenwave_info b on a.green_id = b.id
where dt = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY),'%Y%m%d') and a.type in (705,706) and a.green_id != ''
where dt = CAST(TO_CHAR(DATE_SUB(now(),INTERVAL 1 DAY),'YYYYMMDD') AS INT4) and a.type in ('705','706') and a.green_id != ''
group by a.green_id, b.area_id,a.category,a.type
ON DUPLICATE KEY UPDATE
id=VALUES(id),
green_id=VALUES(green_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)
ON CONFLICT (green_id,event_type,dt)
DO UPDATE SET
id=excluded.id,
area_id=excluded.area_id,
event_category=excluded.event_category,
event_number=excluded.event_number,
event_total_time=excluded.event_total_time,
window_start_time=excluded.window_start_time,
window_end_time=excluded.window_end_time,
insert_time=excluded.insert_time
</insert>
<!-- 新增表t_analysis_problem_green_hour信息 -->
<insertid="insertAnalysisProblemGreenHour">
insert into t_analysis_problem_green_hour (id,green_id,area_id,event_category,event_type,dir,event_number,event_total_time,window_start_time,window_end_time,dt,insert_time)
select uuid(), d.green_id, e.area_id,d.category,d.type,d.dir,count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, d.start_time , d.end_time) ) as duration ,
DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 HOUR),'%Y-%m-%d %H:00:00') as dh1, DATE_FORMAT(now(),'%Y-%m-%d %H:00:00') as dh2,
DATE_FORMAT(now(),'%Y%m%d') as dt , now()
select uuid_generate_v4(), d.green_id, e.area_id,d.category,d.type,d.dir,count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, d.start_time , d.end_time) ) as duration ,
DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 HOUR),'YYYY-MM-DD HH24:00:00') as dh1, DATE_FORMAT(now(),'YYYY-MM-DD HH24:00:00') as dh2,
DATE_FORMAT(now(),'YYYYMMDD') as dt , now()
from
(select DISTINCT b.green_id,b.category,b.type,b.start_time,b.end_time, SUBSTRING_INDEX( SUBSTRING_INDEX( b.dir, ',', c.help_topic_id + 1 ), ',', -1 ) AS dir
(select DISTINCT b.green_id,b.category,b.type,b.start_time,b.end_time, unnest(string_to_array(dir, ',')) AS dir
from
(select a.green_id,a.category,a.type,a.start_time,a.end_time,SUBSTR(a.dir,2,LENGTH(a.dir)-2) as dir
from t_event_info a
where DATE_FORMAT(a.start_time,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 HOUR),'%Y-%m-%d %H:00:00')
and DATE_FORMAT(a.start_time,'%Y-%m-%d %H:%i:%s') <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y-%m-%d %H:00:00')
and a.type in (705,706) and a.green_id != ''
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')
and a.type in ('705','706') and a.green_id != ''
and a.dir is not null
and length(a.dir)>2
) b
INNER JOIN mysql.help_topic c ON c.help_topic_id <![CDATA[ < ]]> (
and congest_start_time > #{peakStartTime} and congest_end_time < #{peakEndTime}
and congest_start_time > to_timestamp(#{peakStartTime},'YYYY-MM-DD HH24:00:00') and congest_end_time < to_timestamp(#{peakEndTime},'YYYY-MM-DD HH24:00:00')
SELECT green_id,road_direction,max(traffic_index) max_congest_index,avg(traffic_index) congest_index,sum(status>=3 and status <=4)*60*5 congest_duration,avg(speed) speed,avg(trval_time) travel_time
from t_greenwave_hist where start_time BETWEEN #{startDate} AND #{endDate} AND TIME( start_time ) BETWEEN #{startTime} AND #{endTime} GROUP BY green_id,road_direction
sum(status>=3 and status<=4)*60*5 congest_duration,avg(speed) speed,avg(trval_time) travel_time
from t_greenwave_hist where start_time BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(#{endDate} ,'YYYY-MM-DD HH24:MI:SS')
(select cross_id from t_greenwave_cross where green_id = #{greenId} and is_key_route = 1 limit 1) cross_data
left join
(SELECT sum(flow) as flow,cross_id from t_cross_dir_data_hist where start_time BETWEEN #{startDate} AND #{endDate} and dir_type = #{dir} GROUP BY cross_id) cross_flow on cross_data.cross_id = cross_flow.cross_id
(SELECT sum(flow) as flow,cross_id from t_cross_dir_data_hist
where start_time BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(#{endDate} ,'YYYY-MM-DD HH24:MI:SS')
and dir_type = #{dir} GROUP BY cross_id) cross_flow on cross_data.cross_id = cross_flow.cross_id
insert into t_analysis_green_wave_congest_time_span (green_id,road_direction,week_day,congest_start_time,congest_end_time,congest_index,status,travel_time,speed,peak_type,year_week,week_start_time,week_end_time,insert_time)
SELECT a.green_id,a.road_direction,#{weekDay} as week_day, TO_TIMESTEMP(#{startTime},'%Y-%m-%d %H:%i:%s') as congest_start_time,TO_TIMESTAMP(DATE_ADD(#{endTime},INTERVAL 5 MINUTE),'%Y-%m-%d %H:%i:%s') as congest_end_time,AVG(traffic_index),#{status} as status,CEIL(AVG(trval_time)),AVG(speed),
#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'%Y-%m-%d') as week_start_time,TO_TIMESTAMP(#{weekEndTime},'%Y-%m-%d') as week_end_time,now()
SELECT a.green_id,a.road_direction,#{weekDay} as week_day, TO_TIMESTEMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') as congest_start_time,TO_TIMESTAMP(DATE_ADD(#{endTime},INTERVAL 5 MINUTE),'YYYY-MM-DD HH24:MI:SS') as congest_end_time,AVG(traffic_index),#{status} as status,CEIL(AVG(trval_time)),AVG(speed),
#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now()
FROM t_greenwave_hist a
where a.start_time between TO_TIMESTAMP(#{startTime},'%Y-%m-%d %H:%i:%s') and TO_TIMESTAMP(#{endTime},'%Y-%m-%d %H:%i:%s')
where a.start_time between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
and CAST(a.green_id AS VARCHAR) = #{greenId}
and a.road_direction = #{roadDirection}
</insert>
...
...
@@ -48,7 +48,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},'%Y-%m-%d 00:00:00') and TO_TIMESTAMP(#{date},'%Y-%m-%d 23:59:59')
where t.start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 00:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 23:59:59')
and t1.dir is not null
order by t.green_id,t1.road_direction,t1.dir,t1.turn,t.start_time
where t.start_time BETWEEN TO_TIMESTAMP(#{date},'%Y-%m-%d 09:00:00') and TO_TIMESTAMP(#{date},'%Y-%m-%d 16:30:10')
where t.start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 09:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 16:30:10')
and CAST(t.green_id AS VARCHAR) = #{greenId}
and t.road_direction = #{roadDirection}
order by t.traffic_index desc
...
...
@@ -71,7 +71,7 @@
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 TO_TIMESTAMP(DATE_SUB(#{startTime},INTERVAL 10 MINUTE),'%Y-%m-%d %H:%i:00') and TO_TIMESTAMP(#{endTime},'%Y-%m-%d %H:%i:%s')
and t4.start_time between TO_TIMESTAMP(DATE_SUB(#{startTime},INTERVAL 10 MINUTE),'YYYY-MM-DD HH24:MI:00') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
group by t4.cross_id,t4.start_time
</select>
...
...
@@ -79,12 +79,12 @@
insert into t_analysis_green_wave_peak_detail (green_id,road_direction,week_day,peak_start_time,peak_end_time,
select a.green_id,a.road_direction,#{weekDay} as week_day,TO_TIMESTAMP(#{startTime},'%Y-%m-%d %H:%i:%s') as peak_start_time,
TO_TIMESTAMP(#{endTime},'%Y-%m-%d %H:%i:%s') as peak_end_time, AVG(traffic_index),CEIL(AVG(trval_time)),AVG(speed),
#{avgFlow} as flow,#{maxFlow} as max_flow,#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'%Y-%m-%d') as week_start_time,
TO_TIMESTAMP(#{weekEndTime},'%Y-%m-%d') as week_end_time,now(),#{trafficThreshold} as traffic_threshold
select a.green_id,a.road_direction,#{weekDay} as week_day,TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') as peak_start_time,
TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS') as peak_end_time, AVG(traffic_index),CEIL(AVG(trval_time)),AVG(speed),
#{avgFlow} as flow,#{maxFlow} as max_flow,#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,
TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now(),#{trafficThreshold} as traffic_threshold
from t_greenwave_hist a
where TO_TIMESTAMP(a.start_time,'%Y-%m-%d %H:%i:00') between TO_TIMESTAMP(#{startTime},'%Y-%m-%d %H:%i:%s') and TO_TIMESTAMP(DATE_SUB(#{endTime},INTERVAL 5 MINUTE),'%Y-%m-%d %H:%i:%s')
where TO_TIMESTAMP(a.start_time,'YYYY-MM-DD HH24:MI:00') between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(DATE_SUB(#{endTime},INTERVAL 5 MINUTE),'YYYY-MM-DD HH24:MI:SS')
and CAST(a.green_id AS VARCHAR) = #{greenId}
and a.road_direction = #{roadDirection}
</insert>
...
...
@@ -93,7 +93,7 @@
select t.green_id,t1.key_cross_id as cross_id, t.road_direction,t.peak_start_time as start_time,t.peak_end_time as endTime ,t.traffic_index,t.peak_type
from t_analysis_green_wave_peak_detail t
left join t_greenwave_key_cross_lane t1 on t1.green_id = t.green_id
where t.peak_start_time BETWEEN TO_TIMESTAMP(#{date},'%Y-%m-%d 00:00:00') and TO_TIMESTAMP(#{date},'%Y-%m-%d 23:59:59')
where t.peak_start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 00:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 23:59:59')
order by t.green_id,t1.key_cross_id ,t.road_direction,t.peak_type,t.traffic_index desc