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
ef35556f
Commit
ef35556f
authored
Feb 26, 2025
by
duanruiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
1faf1d59
b1ebe6b2
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1651 additions
and
8 deletions
+1651
-8
ArithOfBigDecmial.java
...src/main/java/net/wanji/opt/common/ArithOfBigDecmial.java
+134
-0
Tools.java
...ize-service/src/main/java/net/wanji/opt/common/Tools.java
+1449
-0
GreenwaveHistProviderImpl.java
...net/wanji/opt/service/impl/GreenwaveHistProviderImpl.java
+62
-5
RunningEvaluateServiceImpl.java
...et/wanji/opt/service/impl/RunningEvaluateServiceImpl.java
+3
-3
GreenwaveHistMapper.xml
...service/src/main/resources/mapper/GreenwaveHistMapper.xml
+3
-0
No files found.
signal-optimize-service/src/main/java/net/wanji/opt/common/ArithOfBigDecmial.java
0 → 100644
View file @
ef35556f
/**
*
*/
package
net
.
wanji
.
opt
.
common
;
/*
* @author 周士广
* @date 2019年5月29日
*/
import
java.math.BigDecimal
;
/**
* 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。
*/
public
class
ArithOfBigDecmial
{
// 默认除法运算精度
private
static
final
int
DEF_DIV_SCALE
=
10
;
// 这个类不能实例化
private
ArithOfBigDecmial
()
{
}
/**
* 提供精确的加法运算。
*
* @param v1 被加数
* @param v2 加数
* @return 两个参数的和
*/
public
static
double
add
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
add
(
b2
).
doubleValue
();
}
/**
* 提供精确的减法运算。
*
* @param v1 被减数
* @param v2 减数
* @return 两个参数的差
*/
public
static
double
sub
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
subtract
(
b2
).
doubleValue
();
}
/**
* 提供精确的乘法运算。
*
* @param v1 被乘数
* @param v2 乘数
* @return 两个参数的积
*/
public
static
double
mul
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
multiply
(
b2
).
doubleValue
();
}
/**
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后10位,以后的数字四舍五入。
*
* @param v1 被除数
* @param v2 除数
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
)
{
return
div
(
v1
,
v2
,
DEF_DIV_SCALE
);
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
*
* @param v1 被除数
* @param v2 除数
* @param scale 表示表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
,
int
scale
)
{
if
(
scale
<
0
)
{
throw
new
IllegalArgumentException
(
"The scale must be a positive integer or zero"
);
}
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
divide
(
b2
,
scale
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
*
* @param v1 被除数
* @param v2 除数
* @param scale 表示表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
,
int
scale
,
int
roundingMode
)
{
if
(
scale
<
0
)
{
throw
new
IllegalArgumentException
(
"The scale must be a positive integer or zero"
);
}
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
divide
(
b2
,
scale
,
roundingMode
).
doubleValue
();
}
/**
* 提供精确的小数位四舍五入处理。
*
* @param v 需要四舍五入的数字
* @param scale 小数点后保留几位
* @return 四舍五入后的结果
*/
public
static
double
round
(
double
v
,
int
scale
)
{
if
(
scale
<
0
)
{
throw
new
IllegalArgumentException
(
"The scale must be a positive integer or zero"
);
}
BigDecimal
b
=
new
BigDecimal
(
Double
.
toString
(
v
));
BigDecimal
one
=
new
BigDecimal
(
"1"
);
return
b
.
divide
(
one
,
scale
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
}
}
signal-optimize-service/src/main/java/net/wanji/opt/common/Tools.java
0 → 100644
View file @
ef35556f
This diff is collapsed.
Click to expand it.
signal-optimize-service/src/main/java/net/wanji/opt/service/impl/GreenwaveHistProviderImpl.java
View file @
ef35556f
...
...
@@ -19,6 +19,7 @@ import net.wanji.databus.po.CrossTurnDataHistPO;
import
net.wanji.databus.po.CrossTurnInfoPO
;
import
net.wanji.databus.po.TBaseCrossInfo
;
import
net.wanji.opt.bo.BottomMenuBO
;
import
net.wanji.opt.common.ArithOfBigDecmial
;
import
net.wanji.opt.common.EsDateIndexUtil
;
import
net.wanji.opt.common.enums.TimeGranularityEnum
;
import
net.wanji.opt.constant.ServiceLevelEnum
;
...
...
@@ -35,6 +36,7 @@ import org.joda.time.DateTime;
import
org.joda.time.Seconds
;
import
org.joda.time.format.DateTimeFormat
;
import
org.joda.time.format.DateTimeFormatter
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
...
...
@@ -79,6 +81,9 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
@Resource
BaseCrossInfoMapper
baseCrossInfoMapper
;
@Value
(
"${data.mock.flag}"
)
private
boolean
mockFlag
;
@Override
public
BaseInterfaceMapper
<
GreenwaveHist
>
getBaseInterfaceMapper
()
{
return
this
.
greenwaveHistoryMapper
;
...
...
@@ -401,7 +406,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
}
@Override
public
JSONObject
findCrossObjectIndex
(
String
crossId
,
String
startTime
,
String
endTime
,
String
groupType
,
Integer
objectType
,
String
directionName
)
throws
DubboProviderException
{
public
JSONObject
findCrossObjectIndex
(
String
crossId
,
String
startTime
,
String
endTime
,
String
groupType
,
Integer
objectType
,
String
directionName
)
throws
DubboProviderException
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"crossId"
,
crossId
);
params
.
put
(
"startDate"
,
startTime
);
...
...
@@ -466,11 +471,16 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
//补充缺少时段数据,保留时段字段默认值
List
<
CrossLaneDataHistPoExtend
>
value
=
this
.
processData
(
entry
,
groupType
,
sortedSet
,
startTime
);
if
(
Objects
.
equals
(
2
,
objectType
))
{
value
=
value
.
stream
().
sorted
(
Comparator
.
comparing
(
o
->
o
.
getTurnType
())).
collect
(
Collectors
.
toList
());
}
else
if
(
Objects
.
equals
(
3
,
objectType
))
{
value
=
value
.
stream
().
sorted
(
Comparator
.
comparing
(
o
->
o
.
getLaneNo
())).
collect
(
Collectors
.
toList
());
}
if
(
Objects
.
equals
(
3
,
objectType
)){
//车道指标mock数据
this
.
mockData
(
value
);
}
mapList
.
put
(
"scopeCode"
,
key
);
mapList
.
put
(
"dirType"
,
dirType
);
...
...
@@ -508,8 +518,12 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
tmpList
.
add
(
po
);
po
.
setTimeAxis
(
time
);
tmpList
.
add
(
po
);
}
if
(
Objects
.
equals
(
3
,
objectType
)){
//车道指标mock数据
this
.
mockData
(
tmpList
);
}
mapList
.
put
(
"list"
,
tmpList
);
allList
.
add
(
mapList
);
...
...
@@ -518,7 +532,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
}
allList
=
allList
.
stream
().
sorted
(
Comparator
.
comparing
(
o
->
Integer
.
valueOf
(
o
.
get
(
"dirType"
).
toString
()))).
collect
(
Collectors
.
toList
());
if
(
params
.
get
(
"dir"
)
!=
null
)
{
allList
=
allList
.
stream
().
filter
(
o
->
Objects
.
equals
(
params
.
get
(
"dir"
).
toString
(),
o
.
get
(
"dirType"
).
toString
())).
collect
(
Collectors
.
toList
());
allList
=
allList
.
stream
().
filter
(
o
->
Objects
.
equals
(
params
.
get
(
"dir"
).
toString
(),
o
.
get
(
"dirType"
).
toString
())).
collect
(
Collectors
.
toList
());
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"timeList"
,
sortedSet
);
...
...
@@ -528,6 +542,49 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
return
jsonObject
;
}
public
static
void
main
(
String
[]
args
)
{
DateTime
dateTime
=
new
DateTime
(
new
Date
());
System
.
out
.
println
(
dateTime
.
hourOfDay
().
get
());
}
private
void
mockData
(
List
<
CrossLaneDataHistPoExtend
>
list
)
{
if
(
mockFlag
)
{
int
maxFlow
=
list
.
stream
().
filter
(
o
->
Objects
.
nonNull
(
o
.
getFlow
())).
mapToInt
(
CrossLaneDataHistPoExtend:
:
getFlow
).
max
().
orElse
(
0
);
for
(
CrossLaneDataHistPoExtend
po
:
list
)
{
if
(
po
.
getFlow
()
==
null
)
{
po
.
setFlow
(
0
);
}
double
r
=
0
;
if
(
maxFlow
==
0
)
{
r
=
0
;
po
.
setDelayTime
(
0
);
po
.
setSpeed
(
0
D
);
}
else
{
r
=
ArithOfBigDecmial
.
div
(
po
.
getFlow
(),
maxFlow
,
2
);
po
.
setDelayTime
((
int
)
ArithOfBigDecmial
.
round
(
5
+
r
*
20
,
0
));
po
.
setSpeed
(
ArithOfBigDecmial
.
round
(
30
+
30
*
(
1
-
r
),
2
));
}
po
.
setSturation
(
ArithOfBigDecmial
.
round
(
r
*
100
,
2
));
po
.
setGreenLightEfficiency
(
ArithOfBigDecmial
.
round
(
r
*
0.8
*
100
,
2
));
po
.
setVehicleLengthRatioMean
(
ArithOfBigDecmial
.
round
(
r
*
0.9
*
100
,
2
));
if
(
po
.
getFlow
()==
0
){
po
.
setDelayTime
(
0
);
}
// DateTime dateTime = new DateTime(po.getStartTime());
// int hour = dateTime.hourOfDay().get();
// if (hour < 6) {
// po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(80, 50));
// } else if (hour < 8) {
// po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(50, 30));
// } else if (hour < 17) {
// po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(60, 40));
// } else {
// po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(50, 30));
// }
}
}
}
@Override
public
JSONObject
findCrossAvgIndex
(
String
crossId
,
String
startTime
,
String
endTime
,
String
groupType
,
Integer
objectType
)
throws
DubboProviderException
{
...
...
@@ -640,7 +697,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
mapList
.
put
(
"scopeCode"
,
key
);
mapList
.
put
(
"dirName"
,
dirTurnDesc
);
mapList
.
put
(
"scopeName"
,
crossName
);
mapList
.
put
(
"scopeName"
,
crossName
);
mapList
.
put
(
"dirType"
,
BaseEnum
.
SignalDirectionEnum
.
getCodeByName
(
dirTurnDesc
.
substring
(
0
,
dirTurnDesc
.
indexOf
(
"进口"
))));
mapList
.
put
(
"list"
,
value
);
allList
.
add
(
mapList
);
...
...
@@ -685,7 +742,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
mapList
.
put
(
"scopeCode"
,
null
);
mapList
.
put
(
"isLost"
,
true
);
mapList
.
put
(
"dirName"
,
dirDesc
+
"进口"
);
mapList
.
put
(
"scopeName"
,
crossName
);
mapList
.
put
(
"scopeName"
,
crossName
);
mapList
.
put
(
"dirType"
,
tmpEntry
.
getKey
());
mapList
.
put
(
"list"
,
tmpEntry
.
getValue
());
allList
.
add
(
mapList
);
...
...
signal-optimize-service/src/main/java/net/wanji/opt/service/impl/RunningEvaluateServiceImpl.java
View file @
ef35556f
...
...
@@ -180,17 +180,17 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
vo
.
setUnbalanceTimes
(
groupList
.
get
(
EventAbnormalEnum
.
CROSS_UNBALANCE
.
getType
())
==
null
?
0
:
groupList
.
get
(
EventAbnormalEnum
.
CROSS_UNBALANCE
.
getType
()).
getCount
());
int
unbalanceSum
=
groupList
.
get
(
EventAbnormalEnum
.
CROSS_UNBALANCE
.
getType
())
==
null
?
0
:
groupList
.
get
(
EventAbnormalEnum
.
CROSS_UNBALANCE
.
getType
()).
getDuration
();
vo
.
setUnbalanceSum
(
Math
.
round
(
unbalanceSum
/
60
));
vo
.
setUnbalanceSum
(
Math
.
round
(
unbalanceSum
));
vo
.
setSpilloverTimes
(
groupList
.
get
(
EventAbnormalEnum
.
CROSS_OVERFLOW
.
getType
())
==
null
?
0
:
groupList
.
get
(
EventAbnormalEnum
.
CROSS_OVERFLOW
.
getType
()).
getCount
());
int
spilloverSum
=
groupList
.
get
(
EventAbnormalEnum
.
CROSS_OVERFLOW
.
getType
())
==
null
?
0
:
groupList
.
get
(
EventAbnormalEnum
.
CROSS_OVERFLOW
.
getType
()).
getDuration
();
vo
.
setSpilloverSum
(
Math
.
round
(
spilloverSum
/
60
));
vo
.
setSpilloverSum
(
Math
.
round
(
spilloverSum
));
int
emptyPhaseCount
=
groupList
.
get
(
EventAbnormalEnum
.
CROSS_PHASE_EMPTY
.
getType
())
==
null
?
0
:
groupList
.
get
(
EventAbnormalEnum
.
CROSS_PHASE_EMPTY
.
getType
()).
getCount
();
int
emptyPhaseSum
=
groupList
.
get
(
EventAbnormalEnum
.
CROSS_PHASE_EMPTY
.
getType
())
==
null
?
0
:
groupList
.
get
(
EventAbnormalEnum
.
CROSS_PHASE_EMPTY
.
getType
()).
getDuration
();
vo
.
setEmptyPhaseTimes
(
emptyPhaseCount
);
vo
.
setEmptyPhaseSum
(
Math
.
round
(
emptyPhaseSum
/
60
));
vo
.
setEmptyPhaseSum
(
Math
.
round
(
emptyPhaseSum
));
// *******************************************************************************************************//
return
vo
;
...
...
signal-optimize-service/src/main/resources/mapper/GreenwaveHistMapper.xml
View file @
ef35556f
...
...
@@ -441,6 +441,9 @@
<if
test=
"crossId !=null and crossId !=''"
>
and cross_id = #{crossId}
</if>
<if
test=
"greenId !=null and greenId !=''"
>
and green_id = #{greenId}
</if>
GROUP BY type
</select>
...
...
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