Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
ZHHT-IRN-BD-ANALYSIS
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
李凯旋
ZHHT-IRN-BD-ANALYSIS
Commits
4db835cc
Commit
4db835cc
authored
Oct 30, 2022
by
余根龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
绿信比
parent
0afe921a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
67 deletions
+98
-67
Cycle.java
...am-streaming/src/main/java/com/zhht/irn/entity/Cycle.java
+17
-17
Phase.java
...am-streaming/src/main/java/com/zhht/irn/entity/Phase.java
+21
-21
GreenRadioJob.java
...eaming/src/main/java/com/zhht/irn/flow/GreenRadioJob.java
+25
-15
GreenRadioSink.java
...aming/src/main/java/com/zhht/irn/sink/GreenRadioSink.java
+35
-14
No files found.
realtime/hologram-streaming/src/main/java/com/zhht/irn/entity/Cycle.java
View file @
4db835cc
...
@@ -10,32 +10,32 @@ import java.util.List;
...
@@ -10,32 +10,32 @@ import java.util.List;
*/
*/
public
class
Cycle
{
public
class
Cycle
{
// 周期编号
// 周期编号
private
int
id
;
private
Long
id
;
// 路口编号
// 路口编号
private
String
crossCode
;
private
String
crossCode
;
// 周期开始时间
// 周期开始时间
private
Date
beginTime
;
private
String
beginTime
;
// 周期结束时间
// 周期结束时间
private
Date
endTime
;
private
String
endTime
;
private
Long
duration
;
private
int
duration
;
// 周期序号
// 周期序号
private
int
cycleOrder
;
private
int
cycleOrder
;
//绿信比
//绿信比
private
Double
greenRa
d
io
;
private
Double
greenRa
t
io
;
// 周期内相位列表(依次执行)
// 周期内相位列表(依次执行)
private
List
<
Phase
>
phaseList
;
private
List
<
Phase
>
phaseList
;
public
int
getId
()
{
public
Long
getId
()
{
return
id
;
return
id
;
}
}
public
void
setId
(
int
id
)
{
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
this
.
id
=
id
;
}
}
...
@@ -47,27 +47,27 @@ public class Cycle {
...
@@ -47,27 +47,27 @@ public class Cycle {
this
.
crossCode
=
crossCode
;
this
.
crossCode
=
crossCode
;
}
}
public
Date
getBeginTime
()
{
public
String
getBeginTime
()
{
return
beginTime
;
return
beginTime
;
}
}
public
void
setBeginTime
(
Date
beginTime
)
{
public
void
setBeginTime
(
String
beginTime
)
{
this
.
beginTime
=
beginTime
;
this
.
beginTime
=
beginTime
;
}
}
public
Date
getEndTime
()
{
public
String
getEndTime
()
{
return
endTime
;
return
endTime
;
}
}
public
void
setEndTime
(
Date
endTime
)
{
public
void
setEndTime
(
String
endTime
)
{
this
.
endTime
=
endTime
;
this
.
endTime
=
endTime
;
}
}
public
Long
getDuration
()
{
public
int
getDuration
()
{
return
duration
;
return
duration
;
}
}
public
void
setDuration
(
Long
duration
)
{
public
void
setDuration
(
int
duration
)
{
this
.
duration
=
duration
;
this
.
duration
=
duration
;
}
}
...
@@ -87,11 +87,11 @@ public class Cycle {
...
@@ -87,11 +87,11 @@ public class Cycle {
this
.
phaseList
=
phaseList
;
this
.
phaseList
=
phaseList
;
}
}
public
Double
getGreenRa
d
io
()
{
public
Double
getGreenRa
t
io
()
{
return
greenRa
d
io
;
return
greenRa
t
io
;
}
}
public
void
setGreenRa
dio
(
Double
greenRad
io
)
{
public
void
setGreenRa
tio
(
Double
greenRat
io
)
{
this
.
greenRa
dio
=
greenRad
io
;
this
.
greenRa
tio
=
greenRat
io
;
}
}
}
}
realtime/hologram-streaming/src/main/java/com/zhht/irn/entity/Phase.java
View file @
4db835cc
...
@@ -14,28 +14,28 @@ public class Phase {
...
@@ -14,28 +14,28 @@ public class Phase {
// 相位编号
// 相位编号
private
String
phaseValue
;
private
String
phaseValue
;
// 相位开始时间
// 相位开始时间
private
Date
beginTime
;
private
String
beginTime
;
// 相位结束时间
// 相位结束时间
private
Date
endTime
;
private
String
endTime
;
// 相位持续时长
// 相位持续时长
private
Long
duration
;
private
int
duration
;
// 相位绿灯时间
// 相位绿灯时间
private
Long
green
;
private
int
green
;
// 相位黄灯时间
// 相位黄灯时间
private
Long
yellow
;
private
int
yellow
;
// 相位全红时间
// 相位全红时间
private
Long
allRed
;
private
int
allRed
;
// 阶段绿信比
// 阶段绿信比
private
Double
greenRatio
;
private
Double
greenRatio
;
// 阶段有效绿灯时长
// 阶段有效绿灯时长
private
Long
validGreen
;
private
int
validGreen
;
public
String
getPhaseValue
()
{
public
String
getPhaseValue
()
{
return
phaseValue
;
return
phaseValue
;
...
@@ -45,51 +45,51 @@ public class Phase {
...
@@ -45,51 +45,51 @@ public class Phase {
this
.
phaseValue
=
phaseValue
;
this
.
phaseValue
=
phaseValue
;
}
}
public
Date
getBeginTime
()
{
public
String
getBeginTime
()
{
return
beginTime
;
return
beginTime
;
}
}
public
void
setBeginTime
(
Date
beginTime
)
{
public
void
setBeginTime
(
String
beginTime
)
{
this
.
beginTime
=
beginTime
;
this
.
beginTime
=
beginTime
;
}
}
public
Date
getEndTime
()
{
public
String
getEndTime
()
{
return
endTime
;
return
endTime
;
}
}
public
void
setEndTime
(
Date
endTime
)
{
public
void
setEndTime
(
String
endTime
)
{
this
.
endTime
=
endTime
;
this
.
endTime
=
endTime
;
}
}
public
Long
getDuration
()
{
public
int
getDuration
()
{
return
duration
;
return
duration
;
}
}
public
void
setDuration
(
Long
duration
)
{
public
void
setDuration
(
int
duration
)
{
this
.
duration
=
duration
;
this
.
duration
=
duration
;
}
}
public
Long
getGreen
()
{
public
int
getGreen
()
{
return
green
;
return
green
;
}
}
public
void
setGreen
(
Long
green
)
{
public
void
setGreen
(
int
green
)
{
this
.
green
=
green
;
this
.
green
=
green
;
}
}
public
Long
getYellow
()
{
public
int
getYellow
()
{
return
yellow
;
return
yellow
;
}
}
public
void
setYellow
(
Long
yellow
)
{
public
void
setYellow
(
int
yellow
)
{
this
.
yellow
=
yellow
;
this
.
yellow
=
yellow
;
}
}
public
Long
getAllRed
()
{
public
int
getAllRed
()
{
return
allRed
;
return
allRed
;
}
}
public
void
setAllRed
(
Long
allRed
)
{
public
void
setAllRed
(
int
allRed
)
{
this
.
allRed
=
allRed
;
this
.
allRed
=
allRed
;
}
}
...
@@ -117,11 +117,11 @@ public class Phase {
...
@@ -117,11 +117,11 @@ public class Phase {
this
.
greenRatio
=
greenRatio
;
this
.
greenRatio
=
greenRatio
;
}
}
public
Long
getValidGreen
()
{
public
int
getValidGreen
()
{
return
validGreen
;
return
validGreen
;
}
}
public
void
setValidGreen
(
Long
validGreen
)
{
public
void
setValidGreen
(
int
validGreen
)
{
this
.
validGreen
=
validGreen
;
this
.
validGreen
=
validGreen
;
}
}
}
}
realtime/hologram-streaming/src/main/java/com/zhht/irn/flow/GreenRadioJob.java
View file @
4db835cc
...
@@ -27,44 +27,54 @@ public class GreenRadioJob {
...
@@ -27,44 +27,54 @@ public class GreenRadioJob {
// {"PhaseValue":"104","BeginTime":"","EndTime":"","Duration":"","Green":"","Yellow":"","AllRed":""}]
// {"PhaseValue":"104","BeginTime":"","EndTime":"","Duration":"","Green":"","Yellow":"","AllRed":""}]
// 造一条数据
// 造一条数据
DataStream
<
String
>
stream
=
env
.
fromElements
(
"{\"id\":\"1\",\"crossCode\":\"0001\",\"beginTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:05:00\",\"duration\":\"300\",\"cycleOrder\":\"1\",\"phaseList\":[{\"phaseValue\":\"101\",\"beginTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:01:00\",\"duration\":\"60\",\"green\":\"30\",\"yellow\":\"3\",\"allRed\":\"0\"},{\"phaseValue\":\"10
1
\",\"beginTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:05:00\",\"duration\":\"240\",\"green\":\"120\",\"yellow\":\"3\",\"allRed\":\"0\"}]}"
);
DataStream
<
String
>
stream
=
env
.
fromElements
(
"{\"id\":\"1\",\"crossCode\":\"0001\",\"beginTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:05:00\",\"duration\":\"300\",\"cycleOrder\":\"1\",\"phaseList\":[{\"phaseValue\":\"101\",\"beginTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:01:00\",\"duration\":\"60\",\"green\":\"30\",\"yellow\":\"3\",\"allRed\":\"0\"},{\"phaseValue\":\"10
2
\",\"beginTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:05:00\",\"duration\":\"240\",\"green\":\"120\",\"yellow\":\"3\",\"allRed\":\"0\"}]}"
);
DataStream
<
Cycle
>
lxbStream
=
stream
.
map
(
new
MapFunction
<
String
,
Cycle
>()
{
DataStream
<
Cycle
>
lxbStream
=
stream
.
map
(
new
MapFunction
<
String
,
Cycle
>()
{
@Override
@Override
public
Cycle
map
(
String
s
)
throws
Exception
{
public
Cycle
map
(
String
s
)
throws
Exception
{
//启动损失时间 = 2 ,从配置文件读取,正常情况下都是2,不排除个别城市有差异
//启动损失时间 = 2 ,从配置文件读取,正常情况下都是2,不排除个别城市有差异
//清场损失时间 = 黄灯时长 + 全红时长 - 2
//清场损失时间 = 黄灯时长 + 全红时长 - 2
//绿信比 = 每个相位的绿灯时长累加 - 启动损失时间 - 清场损失时间
//阶段损失时间 = 启动损失时间 + 清场损失时间
//阶段有效绿灯时间 = 绿灯时长+黄灯时长+全红时长 - 阶段损失时间
//阶段绿信比 = 阶段有效绿灯时间/周期时长
//周期绿信比 = 阶段绿信比之和
Cycle
cycle
=
JSON
.
parseObject
(
s
,
Cycle
.
class
);
Cycle
cycle
=
JSON
.
parseObject
(
s
,
Cycle
.
class
);
long
cycleId
=
cycle
.
getId
();
long
cycleId
=
cycle
.
getId
();
long
duration
=
cycle
.
getDuration
();
int
duration
=
cycle
.
getDuration
();
String
crossCode
=
cycle
.
getCrossCode
();
String
crossCode
=
cycle
.
getCrossCode
();
double
cycleGreenRa
d
io
=
0
;
double
cycleGreenRa
t
io
=
0
;
List
<
Phase
>
phaseList
=
cycle
.
getPhaseList
();
List
<
Phase
>
phaseList
=
cycle
.
getPhaseList
();
for
(
Phase
phase
:
phaseList
)
{
for
(
Phase
phase
:
phaseList
)
{
//相位号
//相位号
String
phaseValue
=
phase
.
getPhaseValue
();
String
phaseValue
=
phase
.
getPhaseValue
();
// 绿灯时间
// 绿灯时间
long
green
=
phase
.
getGreen
();
int
green
=
phase
.
getGreen
();
// 黄灯时间
// 黄灯时间
long
yellow
=
phase
.
getYellow
();
int
yellow
=
phase
.
getYellow
();
// 全红时间
// 全红时间
long
allRed
=
phase
.
getAllRed
();
int
allRed
=
phase
.
getAllRed
();
// 启动损失时间
取
一般定义:2s
// 启动损失时间
,
一般定义:2s
long
startLossTime
=
2L
;
int
startLossTime
=
2
;
//清场损失时间
//清场损失时间
long
clearLossTime
=
yellow
+
allRed
-
2
;
int
clearLossTime
=
yellow
+
allRed
-
2
;
//阶段损失时间
int
phaseLossTime
=
startLossTime
+
clearLossTime
;
//阶段有效绿灯时间
//阶段有效绿灯时间
long
phaseValidGreen
=
green
+
yellow
+
allRed
-
startLossTime
-
clearLossTime
;
int
phaseValidGreen
=
green
+
yellow
+
allRed
-
phaseLossTime
;
System
.
out
.
println
(
"******duration:"
+
duration
);
System
.
out
.
println
(
"******phaseValidGreen:"
+
phaseValidGreen
);
//阶段绿信比
//阶段绿信比
double
phaseGreenRadio
=
phaseValidGreen
/
duration
;
double
phaseGreenRatio
=
Double
.
valueOf
(
phaseValidGreen
)/
duration
;
System
.
out
.
println
(
"******phaseGreenRatio:"
+
phaseGreenRatio
);
//组装阶段绿信比
//组装阶段绿信比
phase
.
setGreenRatio
(
phaseGreenRa
d
io
);
phase
.
setGreenRatio
(
phaseGreenRa
t
io
);
phase
.
setValidGreen
(
phaseValidGreen
);
phase
.
setValidGreen
(
phaseValidGreen
);
//周期绿信比= 各个阶段绿信比之和
//周期绿信比= 各个阶段绿信比之和
cycleGreenRadio
=
cycleGreenRadio
+
phaseGreenRadio
;
cycleGreenRatio
=
cycleGreenRatio
+
phaseGreenRatio
;
System
.
out
.
println
(
"******cycleGreenRatio:"
+
cycleGreenRatio
);
}
}
// 组装周期绿信比
// 组装周期绿信比
cycle
.
setGreenRa
dio
(
cycleGreenRad
io
);
cycle
.
setGreenRa
tio
(
cycleGreenRat
io
);
return
cycle
;
return
cycle
;
}
}
});
});
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/sink/GreenRadioSink.java
View file @
4db835cc
package
com
.
zhht
.
irn
.
sink
;
package
com
.
zhht
.
irn
.
sink
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.Phase
;
import
com.zhht.irn.utils.MySQLUtils
;
import
com.zhht.irn.utils.MySQLUtils
;
import
org.apache.flink.api.java.tuple.Tuple2
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.streaming.api.functions.sink.RichSinkFunction
;
import
org.apache.flink.streaming.api.functions.sink.RichSinkFunction
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.util.List
;
/**
/**
* domain traffic
* domain traffic
*/
*/
public
class
GreenRadioSink
extends
RichSinkFunction
<
Cycle
>
{
public
class
GreenRadioSink
extends
RichSinkFunction
<
Cycle
>
{
Connection
connection
;
Connection
connection
;
PreparedStatement
insertPstmt
;
PreparedStatement
insert
Cycle
Pstmt
;
PreparedStatement
updat
ePstmt
;
PreparedStatement
insertPhas
ePstmt
;
@Override
@Override
public
void
open
(
Configuration
parameters
)
throws
Exception
{
public
void
open
(
Configuration
parameters
)
throws
Exception
{
super
.
open
(
parameters
);
super
.
open
(
parameters
);
// path暂定为固定值
// path暂定为固定值
String
path
=
"F:\\work
space
\\ZHHT-IRN-BD-ANALYSIS\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties"
;
String
path
=
"F:\\work
bench
\\ZHHT-IRN-BD-ANALYSIS\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties"
;
connection
=
MySQLUtils
.
getConnection
(
path
);
connection
=
MySQLUtils
.
getConnection
(
path
);
insertPstmt
=
connection
.
prepareStatement
(
"insert into app_cycle_green_ratio(id,cross_code,green_radio) values (?,?,?)"
);
String
cycleSql
=
"insert into app_cycle_green_ratio(cycle_id,cross_code,begin_time,end_time,duration,green_ratio) values (?,?,?,?,?,?)"
;
//updatePstmt = connection.prepareStatement("update wyf_test set lxb=? where cross_code=?");
insertCyclePstmt
=
connection
.
prepareStatement
(
cycleSql
);
String
phaseSql
=
"insert into app_phase_green_ratio(cycle_id,cross_code,phase_value,begin_time,end_time,duration,green_ratio,valid_green) values (?,?,?,?,?,?,?,?)"
;
insertPhasePstmt
=
connection
.
prepareStatement
(
phaseSql
);
}
}
@Override
@Override
public
void
close
()
throws
Exception
{
public
void
close
()
throws
Exception
{
super
.
close
();
super
.
close
();
if
(
insert
Pstmt
!=
null
)
insert
Pstmt
.
close
();
if
(
insert
CyclePstmt
!=
null
)
insertCycle
Pstmt
.
close
();
if
(
updatePstmt
!=
null
)
updat
ePstmt
.
close
();
if
(
insertPhasePstmt
!=
null
)
insertPhas
ePstmt
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
}
}
...
@@ -39,11 +42,29 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
...
@@ -39,11 +42,29 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
* 1000w的数据 1000w次
* 1000w的数据 1000w次
*/
*/
@Override
@Override
public
void
invoke
(
Cycle
value
,
Context
context
)
throws
Exception
{
public
void
invoke
(
Cycle
cycle
,
Context
context
)
throws
Exception
{
System
.
out
.
println
(
"=====invoke======"
+
value
.
getId
()
+
"-->"
+
value
.
getCrossCode
());
System
.
out
.
println
(
"=====invoke======"
+
cycle
.
getId
()
+
"-->"
+
cycle
.
getCrossCode
());
insertPstmt
.
setInt
(
1
,
value
.
getId
());
insertCyclePstmt
.
setLong
(
1
,
cycle
.
getId
());
insertPstmt
.
setString
(
2
,
value
.
getCrossCode
());
insertCyclePstmt
.
setString
(
2
,
cycle
.
getCrossCode
());
insertPstmt
.
setDouble
(
3
,
value
.
getGreenRadio
());
insertCyclePstmt
.
setString
(
3
,
cycle
.
getBeginTime
());
insertPstmt
.
execute
();
insertCyclePstmt
.
setString
(
4
,
cycle
.
getEndTime
());
insertCyclePstmt
.
setInt
(
5
,
cycle
.
getDuration
());
insertCyclePstmt
.
setDouble
(
6
,
cycle
.
getGreenRatio
());
insertCyclePstmt
.
execute
();
List
<
Phase
>
phaseList
=
cycle
.
getPhaseList
();
for
(
int
i
=
0
;
i
<
phaseList
.
size
();
i
++){
Phase
phase
=
phaseList
.
get
(
i
);
insertPhasePstmt
.
setLong
(
1
,
cycle
.
getId
());
insertPhasePstmt
.
setString
(
2
,
phase
.
getCrossCode
());
insertPhasePstmt
.
setString
(
3
,
phase
.
getPhaseValue
());
insertPhasePstmt
.
setString
(
4
,
cycle
.
getBeginTime
());
insertPhasePstmt
.
setString
(
5
,
cycle
.
getEndTime
());
insertPhasePstmt
.
setInt
(
6
,
cycle
.
getDuration
());
insertPhasePstmt
.
setDouble
(
7
,
phase
.
getGreenRatio
());
insertPhasePstmt
.
setInt
(
8
,
phase
.
getValidGreen
());
insertPhasePstmt
.
addBatch
();
}
insertPhasePstmt
.
executeBatch
();
insertPhasePstmt
.
clearBatch
();
}
}
}
}
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