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
a488cc3f
Commit
a488cc3f
authored
Aug 30, 2023
by
hanbing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 新信号评价-场景评价-异常事件时空图
parent
ffe0ac76
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
159 additions
and
6 deletions
+159
-6
SceneEvaluateServiceImpl.java
.../net/wanji/opt/service/impl/SceneEvaluateServiceImpl.java
+141
-5
SceneEvaluateabnormalDistributeVO.java
...a/net/wanji/opt/vo/SceneEvaluateabnormalDistributeVO.java
+18
-1
No files found.
signal-optimize-service/src/main/java/net/wanji/opt/service/impl/SceneEvaluateServiceImpl.java
View file @
a488cc3f
...
...
@@ -10,10 +10,7 @@ import net.wanji.opt.vo.RunningEvaluateMetricsDetailVO;
import
net.wanji.opt.vo.SceneEvaluateabnormalDistributeVO
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -40,12 +37,151 @@ public class SceneEvaluateServiceImpl implements SceneEvaluateService {
SceneEvaluateabnormalDistributeVO
vo
=
new
SceneEvaluateabnormalDistributeVO
();
List
<
SceneEvaluateabnormalDistributeVO
.
TimeDistribution
>
timeDistributionList
=
buildTimeDistributionList
(
crossId
,
startDate
,
endDate
);
vo
.
set
TimeDistributionList
(
timeDistributionList
);
vo
.
set
FinalTimeDistributionList
(
buildFinalTimeDistributionList
(
timeDistributionList
)
);
setCounts
(
timeDistributionList
,
vo
);
return
vo
;
}
public
List
<
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
>
buildFinalTimeDistributionList
(
List
<
SceneEvaluateabnormalDistributeVO
.
TimeDistribution
>
timeDistributionList
)
{
List
<
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
>
finalTimeDistributionList
=
new
ArrayList
<>();
for
(
SceneEvaluateabnormalDistributeVO
.
TimeDistribution
timeDistribution
:
timeDistributionList
)
{
Date
problemDate
=
timeDistribution
.
getProblemDate
();
for
(
RunningEvaluateMetricsDetailVO
.
ProblemStatus
problemStatus
:
timeDistribution
.
getProblemStatusList
())
{
Integer
status
=
problemStatus
.
getStatus
();
Date
startTime
=
problemStatus
.
getStartTime
();
Date
endTime
=
problemStatus
.
getEndTime
();
// 生成 FinalTimeDistribution 对象
for
(
Date
time
=
getStartTimeOfDay
();
time
.
before
(
getEndTimeOfDay
());
time
=
addFiveMinutes
(
time
))
{
if
(
isTimeIntersecting
(
time
,
addFiveMinutes
(
time
),
startTime
,
endTime
))
{
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
finalTimeDistribution
=
new
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
();
finalTimeDistribution
.
setProblemDate
(
problemDate
);
finalTimeDistribution
.
setStatus
(
status
);
// 将 time 中的年、月、日设置为 problemDate 中的年、月、日
Calendar
calTime
=
Calendar
.
getInstance
();
Calendar
calProblemDate
=
Calendar
.
getInstance
();
calTime
.
setTime
(
time
);
calProblemDate
.
setTime
(
problemDate
);
calTime
.
set
(
Calendar
.
YEAR
,
calProblemDate
.
get
(
Calendar
.
YEAR
));
calTime
.
set
(
Calendar
.
MONTH
,
calProblemDate
.
get
(
Calendar
.
MONTH
));
calTime
.
set
(
Calendar
.
DAY_OF_MONTH
,
calProblemDate
.
get
(
Calendar
.
DAY_OF_MONTH
));
Date
newTime
=
calTime
.
getTime
();
finalTimeDistribution
.
setDistributionTime
(
newTime
);
finalTimeDistributionList
.
add
(
finalTimeDistribution
);
}
}
}
// 填满 finalTimeDistributionList
// 生成时间列表
List
<
Date
>
timeList
=
new
ArrayList
<>();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
problemDate
);
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
for
(
int
i
=
0
;
i
<
24
*
60
;
i
+=
5
)
{
timeList
.
add
(
cal
.
getTime
());
cal
.
add
(
Calendar
.
MINUTE
,
5
);
}
for
(
Date
time
:
timeList
)
{
boolean
exists
=
finalTimeDistributionList
.
stream
()
.
anyMatch
(
item
->
item
.
getDistributionTime
().
equals
(
time
)
&&
isSameDay
(
item
.
getProblemDate
(),
problemDate
));
if
(!
exists
)
{
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
newItem
=
new
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
();
newItem
.
setProblemDate
(
problemDate
);
newItem
.
setDistributionTime
(
time
);
newItem
.
setStatus
(
null
);
finalTimeDistributionList
.
add
(
newItem
);
}
}
}
// 重新排序
finalTimeDistributionList
.
sort
(
Comparator
.
comparing
(
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
::
getProblemDate
)
.
thenComparing
(
SceneEvaluateabnormalDistributeVO
.
FinalTimeDistribution
::
getDistributionTime
));
return
finalTimeDistributionList
;
}
private
boolean
isSameDay
(
Date
date1
,
Date
date2
)
{
Calendar
cal1
=
Calendar
.
getInstance
();
Calendar
cal2
=
Calendar
.
getInstance
();
cal1
.
setTime
(
date1
);
cal2
.
setTime
(
date2
);
return
cal1
.
get
(
Calendar
.
YEAR
)
==
cal2
.
get
(
Calendar
.
YEAR
)
&&
cal1
.
get
(
Calendar
.
DAY_OF_YEAR
)
==
cal2
.
get
(
Calendar
.
DAY_OF_YEAR
);
}
// 辅助方法:判断两个时间段是否相交
public
boolean
isTimeIntersecting
(
Date
eventStartTime
,
Date
eventEndTime
,
Date
sectionStartTime
,
Date
sectionEndTime
)
{
Calendar
cal
=
java
.
util
.
Calendar
.
getInstance
();
cal
.
setTime
(
eventStartTime
);
int
eventStartHour
=
cal
.
get
(
java
.
util
.
Calendar
.
HOUR_OF_DAY
);
int
eventStartMinute
=
cal
.
get
(
java
.
util
.
Calendar
.
MINUTE
);
cal
.
setTime
(
eventEndTime
);
int
eventEndHour
=
cal
.
get
(
java
.
util
.
Calendar
.
HOUR_OF_DAY
);
int
eventEndMinute
=
cal
.
get
(
java
.
util
.
Calendar
.
MINUTE
);
cal
.
setTime
(
sectionStartTime
);
int
sectionStartHour
=
cal
.
get
(
Calendar
.
HOUR_OF_DAY
);
int
sectionStartMinute
=
cal
.
get
(
Calendar
.
MINUTE
);
cal
.
setTime
(
sectionEndTime
);
int
sectionEndHour
=
cal
.
get
(
Calendar
.
HOUR_OF_DAY
);
int
sectionEndMinute
=
cal
.
get
(
Calendar
.
MINUTE
);
// 将小时和分钟转换为分钟数以便比较
int
eventStartInMinutes
=
eventStartHour
*
60
+
eventStartMinute
;
int
eventEndInMinutes
=
eventEndHour
*
60
+
eventEndMinute
;
int
sectionStartInMinutes
=
sectionStartHour
*
60
+
sectionStartMinute
;
int
sectionEndInMinutes
=
sectionEndHour
*
60
+
sectionEndMinute
;
// 判断两个时间段是否相交
return
(
eventStartInMinutes
<
sectionEndInMinutes
&&
eventEndInMinutes
>
sectionStartInMinutes
)
||
(
sectionStartInMinutes
<
eventEndInMinutes
&&
sectionEndInMinutes
>
eventStartInMinutes
);
}
// 辅助方法:获取当天的开始时间(00:00)
private
static
Date
getStartTimeOfDay
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
// 辅助方法:获取当天的结束时间(23:59)
private
static
Date
getEndTimeOfDay
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
calendar
.
getTime
();
}
// 辅助方法:给时间加上5分钟
private
static
Date
addFiveMinutes
(
Date
time
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
time
);
calendar
.
add
(
Calendar
.
MINUTE
,
5
);
return
calendar
.
getTime
();
}
private
static
void
setCounts
(
List
<
SceneEvaluateabnormalDistributeVO
.
TimeDistribution
>
timeDistributionList
,
SceneEvaluateabnormalDistributeVO
vo
)
{
int
congestionDuration
=
0
;
...
...
signal-optimize-service/src/main/java/net/wanji/opt/vo/SceneEvaluateabnormalDistributeVO.java
View file @
a488cc3f
...
...
@@ -31,7 +31,7 @@ public class SceneEvaluateabnormalDistributeVO {
Integer
spilloverDuration
;
@ApiModelProperty
(
value
=
"时间分布"
)
List
<
TimeDistribution
>
t
imeDistributionList
;
List
<
FinalTimeDistribution
>
finalT
imeDistributionList
;
@NoArgsConstructor
@Data
...
...
@@ -44,4 +44,21 @@ public class SceneEvaluateabnormalDistributeVO {
@ApiModelProperty
(
value
=
"状态列表"
)
private
List
<
RunningEvaluateMetricsDetailVO
.
ProblemStatus
>
problemStatusList
;
}
@NoArgsConstructor
@Data
public
static
class
FinalTimeDistribution
{
@ApiModelProperty
(
value
=
"日期"
)
@JsonFormat
(
shape
=
JsonFormat
.
Shape
.
STRING
,
pattern
=
"M/d"
,
timezone
=
"GMT+8"
)
private
Date
problemDate
;
@ApiModelProperty
(
value
=
"路口状态 0正常 1 失衡 2 拥堵 3 溢出"
)
private
Integer
status
;
@ApiModelProperty
(
value
=
"时间"
)
@JsonFormat
(
shape
=
JsonFormat
.
Shape
.
STRING
,
pattern
=
"HH:mm"
,
timezone
=
"GMT+8"
)
private
Date
distributionTime
;
}
}
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