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
22ab2ed7
Commit
22ab2ed7
authored
Feb 25, 2025
by
zhoushiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
随机mock数据
parent
9a8e6f2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
16 deletions
+169
-16
ArithOfBigDecmial.java
...src/main/java/net/wanji/opt/common/ArithOfBigDecmial.java
+134
-0
GreenwaveHistProviderImpl.java
...net/wanji/opt/service/impl/GreenwaveHistProviderImpl.java
+35
-16
No files found.
signal-optimize-service/src/main/java/net/wanji/opt/common/ArithOfBigDecmial.java
0 → 100644
View file @
22ab2ed7
/**
*
*/
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/service/impl/GreenwaveHistProviderImpl.java
View file @
22ab2ed7
...
...
@@ -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
;
...
...
@@ -469,7 +470,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
//补充缺少时段数据,保留时段字段默认值
List
<
CrossLaneDataHistPoExtend
>
value
=
this
.
processData
(
entry
,
groupType
,
sortedSet
,
startTime
);
this
.
mockData
(
value
);
if
(
Objects
.
equals
(
2
,
objectType
))
{
value
=
value
.
stream
().
sorted
(
Comparator
.
comparing
(
o
->
o
.
getTurnType
())).
collect
(
Collectors
.
toList
());
...
...
@@ -477,6 +478,8 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
value
=
value
.
stream
().
sorted
(
Comparator
.
comparing
(
o
->
o
.
getLaneNo
())).
collect
(
Collectors
.
toList
());
}
this
.
mockData
(
value
);
mapList
.
put
(
"scopeCode"
,
key
);
mapList
.
put
(
"dirType"
,
dirType
);
mapList
.
put
(
"scopeName"
,
dirTurnDesc
);
...
...
@@ -515,7 +518,6 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
}
po
.
setTimeAxis
(
time
);
tmpList
.
add
(
po
);
}
this
.
mockData
(
tmpList
);
mapList
.
put
(
"list"
,
tmpList
);
...
...
@@ -540,24 +542,41 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
System
.
out
.
println
(
dateTime
.
hourOfDay
().
get
());
}
private
void
mockData
(
List
<
CrossLaneDataHistPoExtend
>
list
){
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
)
{
po
.
setSturation
(
net
.
wanji
.
opt
.
common
.
Tools
.
getDoubleRandomValue
(
70
,
30
));
po
.
setDelayTime
(
net
.
wanji
.
opt
.
common
.
Tools
.
getRandomValue
(
40
,
10
));
po
.
setGreenLightEfficiency
(
net
.
wanji
.
opt
.
common
.
Tools
.
getDoubleRandomValue
(
70
,
30
));
po
.
setVehicleLengthRatioMean
(
net
.
wanji
.
opt
.
common
.
Tools
.
getDoubleRandomValue
(
70
,
30
));
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
));
if
(
po
.
getFlow
()
==
null
)
{
po
.
setFlow
(
0
);
}
double
r
=
0
;
if
(
maxFlow
==
0
)
{
r
=
0
;
po
.
setDelayTime
(
0
);
po
.
setSpeed
(
0
D
);
}
else
{
po
.
setSpeed
(
net
.
wanji
.
opt
.
common
.
Tools
.
getDoubleRandomValue
(
50
,
30
));
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));
// }
}
}
}
...
...
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