Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
traffic-signal-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
signal
traffic-signal-platform
Commits
1a5fd980
Commit
1a5fd980
authored
Feb 12, 2025
by
zhouleilei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
信控调优平台-交通体检-交通状态分布新增10分钟、15分钟,30分钟时间粒度
parent
aaf81011
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
145 additions
and
18 deletions
+145
-18
EsDateIndexUtil.java
...e/src/main/java/net/wanji/opt/common/EsDateIndexUtil.java
+6
-11
EventServiceImpl.java
...ain/java/net/wanji/opt/service/impl/EventServiceImpl.java
+128
-6
HoloEventMapper.xml
...ize-service/src/main/resources/mapper/HoloEventMapper.xml
+6
-1
EventInfoTrafficStatusDTO.java
...java/net/wanji/databus/dto/EventInfoTrafficStatusDTO.java
+5
-0
No files found.
signal-optimize-service/src/main/java/net/wanji/opt/common/EsDateIndexUtil.java
View file @
1a5fd980
...
...
@@ -5,20 +5,11 @@ import net.wanji.opt.common.enums.TimeGranularityEnum;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.filefilter.FileFilterUtils
;
import
org.apache.commons.io.filefilter.IOFileFilter
;
import
org.joda.time.DateTime
;
import
org.joda.time.Days
;
import
org.joda.time.Hours
;
import
org.joda.time.Minutes
;
import
org.joda.time.Months
;
import
org.joda.time.*
;
import
org.joda.time.format.DateTimeFormat
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.util.*
;
import
java.util.stream.Collectors
;
public
class
EsDateIndexUtil
{
...
...
@@ -60,6 +51,8 @@ public class EsDateIndexUtil {
sortedSet
.
addAll
(
EsDateIndexUtil
.
getTimeScopeList
(
start
,
end
,
TimeGranularityEnum
.
ONE_HOUR
,
EsDateIndexUtil
.
H_FORMATTER
));
}
else
if
(
Objects
.
equals
(
"4"
,
groupType
))
{
sortedSet
.
addAll
(
EsDateIndexUtil
.
getTimeScopeList
(
start
,
end
,
TimeGranularityEnum
.
ONE_DAY
,
EsDateIndexUtil
.
YMD_FORMATTER
));
}
else
if
(
Objects
.
equals
(
"5"
,
groupType
))
{
sortedSet
.
addAll
(
EsDateIndexUtil
.
getTimeScopeList
(
start
,
end
,
TimeGranularityEnum
.
TEN_MINUTE
,
EsDateIndexUtil
.
HM_FORMATTER
));
}
return
sortedSet
;
}
...
...
@@ -89,6 +82,8 @@ public class EsDateIndexUtil {
unitTime
=
60
;
}
else
if
(
Objects
.
equals
(
TimeGranularityEnum
.
ONE_DAY
,
timeGranularityEnum
))
{
unitTime
=
24
*
60
;
}
else
if
(
Objects
.
equals
(
TimeGranularityEnum
.
TEN_MINUTE
,
timeGranularityEnum
))
{
unitTime
=
10
;
}
for
(
int
i
=
0
;
i
<=
diffNum
;
i
=
i
+
unitTime
)
{
...
...
signal-optimize-service/src/main/java/net/wanji/opt/service/impl/EventServiceImpl.java
View file @
1a5fd980
...
...
@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import
net.wanji.common.enums.BaseEnum
;
import
net.wanji.common.framework.exception.DubboProviderException
;
import
net.wanji.common.utils.tool.DateUtil
;
import
net.wanji.common.utils.tool.LocalDateTimeUtil
;
import
net.wanji.databus.dao.entity.GreenwaveHistPO
;
import
net.wanji.databus.dao.mapper.BaseCrossInfoMapper
;
import
net.wanji.databus.dao.mapper.GreenwaveHistMapper
;
...
...
@@ -30,6 +31,10 @@ import org.joda.time.format.DateTimeFormat;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -209,6 +214,7 @@ public class EventServiceImpl implements EventService {
EventInfoTrafficStatusVO
eventInfoTrafficStatusVO
=
new
EventInfoTrafficStatusVO
();
String
eventType
=
eventInfoTrafficStatusDTO
.
getEventType
();
Integer
queryType
=
eventInfoTrafficStatusDTO
.
getQueryType
();
String
timeType
=
eventInfoTrafficStatusDTO
.
getTimeType
();
List
<
EventInfoTrafficStatusPO
>
eventInfoTrafficStatusPOS
=
null
;
if
(
ObjectUtil
.
equals
(
1
,
queryType
))
{
//路口
...
...
@@ -229,16 +235,62 @@ public class EventServiceImpl implements EventService {
}
List
<
GreenwaveHistPO
>
greenwaveHistPOS
=
greenwaveHistMapper
.
selectByIdAndType
(
Integer
.
valueOf
(
eventInfoTrafficStatusDTO
.
getId
()),
statusList
);
if
(
ObjectUtil
.
isNotEmpty
(
greenwaveHistPOS
))
{
eventInfoTrafficStatusPOS
=
new
ArrayList
<
EventInfoTrafficStatusPO
>();
Map
<
Integer
,
List
<
GreenwaveHistPO
>>
collect
=
greenwaveHistPOS
.
stream
().
collect
(
Collectors
.
groupingBy
(
x
->
x
.
getStartTime
().
getHours
()));
for
(
Map
.
Entry
<
Integer
,
List
<
GreenwaveHistPO
>>
entry
:
collect
.
entrySet
())
{
eventInfoTrafficStatusPOS
.
add
(
handerEntry
(
entry
));
}
eventInfoTrafficStatusPOS
=
greenwaveHistHandler
(
timeType
,
greenwaveHistPOS
);
/*eventInfoTrafficStatusPOS = new ArrayList<EventInfoTrafficStatusPO>();
if (ObjectUtil.equals(timeType,3)) {
//按小时统计,还按照之前逻辑处理
Map<Integer, List<GreenwaveHistPO>> collect = greenwaveHistPOS.stream().collect(Collectors.groupingBy(x -> x.getStartTime().getHours()));
for (Map.Entry<Integer, List<GreenwaveHistPO>> entry : collect.entrySet()) {
eventInfoTrafficStatusPOS.add(handerEntry(entry));
}
}else {
//其它十分钟,15分钟,30分钟数据有一次算一次
Map<String, List<GreenwaveHistPO>> groupedEvents = greenwaveHistPOS.stream()
.collect(Collectors.groupingBy(event -> {
GreenwaveHistPO greenwaveHistPO = (GreenwaveHistPO)event;
Date date = greenwaveHistPO.getStartTime();
LocalDateTime startTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
// 将时间向下取整到最近的15分钟(按时间聚合)
LocalDateTime roundedTime = null;
if (ObjectUtil.equals(timeType,"5")){
//十分钟
roundedTime = startTime.truncatedTo(ChronoUnit.HOURS)
.plusMinutes(10 * (startTime.getMinute() / 10));
}else if (ObjectUtil.equals(timeType,"1")){
//15分钟
roundedTime = startTime.truncatedTo(ChronoUnit.HOURS)
.plusMinutes(15 * (startTime.getMinute() / 15));
}else if (ObjectUtil.equals(timeType,"2")){
//30分钟
roundedTime = startTime.truncatedTo(ChronoUnit.HOURS)
.plusMinutes(30 * (startTime.getMinute() / 30));
}
// 格式化为"小时:分钟"字符串
return roundedTime.format(DateTimeFormatter.ofPattern("HH:mm"));
}));
Set<String> strings = groupedEvents.keySet();
for (String string : strings) {
List<GreenwaveHistPO> value = groupedEvents.get(string);
EventInfoTrafficStatusPO eventInfoTrafficStatusPO = new EventInfoTrafficStatusPO();
int size = value.size();
int sum = value.stream().mapToInt(GreenwaveHistPO::getStrategyDuration).sum();
eventInfoTrafficStatusPO.setDuration(sum);
eventInfoTrafficStatusPO.setCount(size);
eventInfoTrafficStatusPO.setTimeAxisStart(string);
eventInfoTrafficStatusPOS.add(eventInfoTrafficStatusPO);
}
}*/
}
}
//获取当前时间的时间轴
Set
<
String
>
timeScopeList
=
getTimeScopeList
(
DateTime
.
now
().
withTimeAtStartOfDay
(),
new
DateTime
(),
EsDateIndexUtil
.
H_FORMATTER
);
LocalDateTime
localDateTime
=
LocalDateTimeUtil
.
convertDateToLDT
(
new
Date
());
LocalDateTime
dayStart
=
LocalDateTimeUtil
.
getDayStart
(
localDateTime
);
String
now
=
LocalDateTimeUtil
.
formatTime
(
localDateTime
,
LocalDateTimeUtil
.
TIMEFORMATTER
);
String
startTime
=
LocalDateTimeUtil
.
formatTime
(
dayStart
,
LocalDateTimeUtil
.
TIMEFORMATTER
);
Set
<
String
>
timeScopeList
=
EsDateIndexUtil
.
getTimeGranularityAxis
(
eventInfoTrafficStatusDTO
.
getTimeType
(),
startTime
,
now
);
if
(
ObjectUtil
.
isNotEmpty
(
timeScopeList
))
{
ArrayList
<
String
>
arrayList
=
timeScopeList
.
stream
().
collect
(
Collectors
.
toCollection
(
ArrayList:
:
new
));
List
<
String
>
collect
=
arrayList
.
stream
().
sorted
(
Comparator
.
comparing
(
time
->
Integer
.
valueOf
(
time
.
split
(
":"
)[
0
]))).
collect
(
Collectors
.
toList
());
...
...
@@ -271,6 +323,76 @@ public class EventServiceImpl implements EventService {
return
eventInfoTrafficStatusVO
;
}
/**
* @Description 干线数据处理
* @Param [greenwaveHistPOS]
* @return void
**/
private
List
<
EventInfoTrafficStatusPO
>
greenwaveHistHandler
(
String
timeType
,
List
<
GreenwaveHistPO
>
greenwaveHistPOS
){
List
<
EventInfoTrafficStatusPO
>
eventInfoTrafficStatusPOS
=
new
ArrayList
<>();
//其它十分钟,15分钟,30分钟数据有一次算一次
Map
<
String
,
List
<
GreenwaveHistPO
>>
groupedEvents
=
greenwaveHistPOS
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
event
->
{
GreenwaveHistPO
greenwaveHistPO
=
(
GreenwaveHistPO
)
event
;
Date
date
=
greenwaveHistPO
.
getStartTime
();
LocalDateTime
startTime
=
LocalDateTime
.
ofInstant
(
date
.
toInstant
(),
ZoneId
.
systemDefault
());
// 将时间向下取整到最近的15分钟(按时间聚合)
LocalDateTime
roundedTime
=
null
;
if
(
ObjectUtil
.
equals
(
timeType
,
"5"
)){
//十分钟
roundedTime
=
startTime
.
truncatedTo
(
ChronoUnit
.
HOURS
)
.
plusMinutes
(
10
*
(
startTime
.
getMinute
()
/
10
));
}
else
if
(
ObjectUtil
.
equals
(
timeType
,
"1"
)){
//15分钟
roundedTime
=
startTime
.
truncatedTo
(
ChronoUnit
.
HOURS
)
.
plusMinutes
(
15
*
(
startTime
.
getMinute
()
/
15
));
}
else
if
(
ObjectUtil
.
equals
(
timeType
,
"2"
)){
//30分钟
roundedTime
=
startTime
.
truncatedTo
(
ChronoUnit
.
HOURS
)
.
plusMinutes
(
30
*
(
startTime
.
getMinute
()
/
30
));
}
else
if
(
ObjectUtil
.
equals
(
timeType
,
"3"
)){
//1小时
roundedTime
=
startTime
.
truncatedTo
(
ChronoUnit
.
HOURS
)
.
plusMinutes
(
60
*
(
startTime
.
getMinute
()
/
60
));
}
// 格式化为"小时:分钟"字符串
return
roundedTime
.
format
(
DateTimeFormatter
.
ofPattern
(
"HH:mm"
));
}));
Set
<
String
>
strings
=
groupedEvents
.
keySet
();
for
(
String
string
:
strings
)
{
EventInfoTrafficStatusPO
eventInfoTrafficStatusPO
=
new
EventInfoTrafficStatusPO
();
List
<
GreenwaveHistPO
>
value
=
groupedEvents
.
get
(
string
);
int
count
=
0
;
int
duration
=
0
;
for
(
int
i
=
0
;
i
<
value
.
size
();
i
++)
{
if
(
i
==
0
){
count
++;
//五分钟数据,则一次拥堵为300秒
duration
+=
300
;
}
else
{
if
(
value
.
get
(
i
).
getStartTime
().
getTime
()
-
value
.
get
(
i
-
1
).
getStartTime
().
getTime
()
<=
305
)
{
//视为连续拥堵,则不加次数,拥堵时长加300秒
//五分钟数据,则一次拥堵为300秒
duration
+=
300
;
}
else
{
count
++;
//五分钟数据,则一次拥堵为300秒
duration
+=
300
;
}
}
}
eventInfoTrafficStatusPO
.
setDuration
(
duration
);
eventInfoTrafficStatusPO
.
setCount
(
count
);
eventInfoTrafficStatusPO
.
setTimeAxisStart
(
string
);
eventInfoTrafficStatusPOS
.
add
(
eventInfoTrafficStatusPO
);
}
return
eventInfoTrafficStatusPOS
;
}
/**
* @return net.wanji.databus.po.EventInfoTrafficStatusPO
* @Description 干线数据处理
...
...
signal-optimize-service/src/main/resources/mapper/HoloEventMapper.xml
View file @
1a5fd980
...
...
@@ -210,7 +210,12 @@
SELECT cross_id, dt,type AS event_type,start_time,ifnull(end_time,now()) end_time,
sum( TIMESTAMPDIFF( SECOND, start_time, ifnull( end_time, now())) ) duration,
count(*) as count,
DATE_FORMAT( start_time, '%H:00' ) time_axis_start
case
when #{timeType}=5 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 10 ) * 10 ),'%H:%i' )
when #{timeType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%H:%i' )
when #{timeType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%H:%i' )
when #{timeType}=3 then DATE_FORMAT( start_time, '%H:00' )
end as time_axis_start
FROM
t_event_info
WHERE
...
...
wj-databus/src/main/java/net/wanji/databus/dto/EventInfoTrafficStatusDTO.java
View file @
1a5fd980
...
...
@@ -29,4 +29,9 @@ public class EventInfoTrafficStatusDTO {
@Range
(
min
=
1
,
max
=
7
,
message
=
"eventType 区间1-7"
)
@NotNull
(
message
=
"eventType 不能为空"
)
private
String
eventType
;
@ApiModelProperty
(
value
=
"时间粒度类型:5-10分钟,1-15分钟,2-30分钟,3-1小时"
,
notes
=
""
)
@Range
(
min
=
1
,
max
=
5
,
message
=
"timeType 区间1-5"
)
@NotNull
(
message
=
"timeType 不能为空"
)
private
String
timeType
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment