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
0e8073be
Commit
0e8073be
authored
Oct 31, 2022
by
余根龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改字段名称
parent
7bc29bf4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
49 deletions
+45
-49
Cycle.java
...am-streaming/src/main/java/com/zhht/irn/entity/Cycle.java
+15
-16
Stage.java
...am-streaming/src/main/java/com/zhht/irn/entity/Stage.java
+1
-1
FlinkKafka2MysqlApp.java
.../src/main/java/com/zhht/irn/flow/FlinkKafka2MysqlApp.java
+5
-8
GreenRadioJob.java
...eaming/src/main/java/com/zhht/irn/flow/GreenRadioJob.java
+16
-16
GreenRadioSink.java
...aming/src/main/java/com/zhht/irn/sink/GreenRadioSink.java
+8
-8
No files found.
realtime/hologram-streaming/src/main/java/com/zhht/irn/entity/Cycle.java
View file @
0e8073be
package
com
.
zhht
.
irn
.
entity
;
package
com
.
zhht
.
irn
.
entity
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -16,10 +15,10 @@ public class Cycle {
...
@@ -16,10 +15,10 @@ public class Cycle {
private
String
crossCode
;
private
String
crossCode
;
// 周期开始时间
// 周期开始时间
private
String
beginTime
;
private
String
begin
Date
Time
;
// 周期结束时间
// 周期结束时间
private
String
endTime
;
private
String
end
Date
Time
;
private
int
duration
;
private
int
duration
;
...
@@ -29,7 +28,7 @@ public class Cycle {
...
@@ -29,7 +28,7 @@ public class Cycle {
private
Double
greenRatio
;
private
Double
greenRatio
;
// 周期内相位列表(依次执行)
// 周期内相位列表(依次执行)
private
List
<
Phase
>
phas
eList
;
private
List
<
Stage
>
stag
eList
;
public
Long
getId
()
{
public
Long
getId
()
{
return
id
;
return
id
;
...
@@ -47,20 +46,20 @@ public class Cycle {
...
@@ -47,20 +46,20 @@ public class Cycle {
this
.
crossCode
=
crossCode
;
this
.
crossCode
=
crossCode
;
}
}
public
String
getBeginTime
()
{
public
String
getBegin
Date
Time
()
{
return
beginTime
;
return
begin
Date
Time
;
}
}
public
void
setBegin
Time
(
String
begin
Time
)
{
public
void
setBegin
DateTime
(
String
beginDate
Time
)
{
this
.
begin
Time
=
begin
Time
;
this
.
begin
DateTime
=
beginDate
Time
;
}
}
public
String
getEndTime
()
{
public
String
getEnd
Date
Time
()
{
return
endTime
;
return
end
Date
Time
;
}
}
public
void
setEnd
Time
(
String
end
Time
)
{
public
void
setEnd
DateTime
(
String
endDate
Time
)
{
this
.
end
Time
=
end
Time
;
this
.
end
DateTime
=
endDate
Time
;
}
}
public
int
getDuration
()
{
public
int
getDuration
()
{
...
@@ -79,12 +78,12 @@ public class Cycle {
...
@@ -79,12 +78,12 @@ public class Cycle {
this
.
cycleOrder
=
cycleOrder
;
this
.
cycleOrder
=
cycleOrder
;
}
}
public
List
<
Phase
>
getPhas
eList
()
{
public
List
<
Stage
>
getStag
eList
()
{
return
phas
eList
;
return
stag
eList
;
}
}
public
void
set
PhaseList
(
List
<
Phase
>
phas
eList
)
{
public
void
set
StageList
(
List
<
Stage
>
stag
eList
)
{
this
.
phaseList
=
phas
eList
;
this
.
stageList
=
stag
eList
;
}
}
public
Double
getGreenRatio
()
{
public
Double
getGreenRatio
()
{
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/entity/
Phas
e.java
→
realtime/hologram-streaming/src/main/java/com/zhht/irn/entity/
Stag
e.java
View file @
0e8073be
...
@@ -5,7 +5,7 @@ import java.util.Date;
...
@@ -5,7 +5,7 @@ import java.util.Date;
/**
/**
* 相位实体类
* 相位实体类
*/
*/
public
class
Phas
e
{
public
class
Stag
e
{
//周期ID
//周期ID
private
Long
cycleId
;
private
Long
cycleId
;
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/flow/FlinkKafka2MysqlApp.java
View file @
0e8073be
package
com
.
zhht
.
irn
.
flow
;
package
com
.
zhht
.
irn
.
flow
;
import
com.alibaba.fastjson
2
.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.
Phas
e
;
import
com.zhht.irn.entity.
Stag
e
;
import
com.zhht.irn.sink.LXBSink
;
import
com.zhht.irn.sink.LXBSink
;
import
com.zhht.irn.utils.FlinkUtils
;
import
org.apache.flink.api.common.functions.MapFunction
;
import
org.apache.flink.api.common.functions.MapFunction
;
import
org.apache.flink.api.common.serialization.SimpleStringSchema
;
import
org.apache.flink.api.java.tuple.Tuple2
;
import
org.apache.flink.api.java.tuple.Tuple2
;
import
org.apache.flink.streaming.api.datastream.DataStream
;
import
org.apache.flink.streaming.api.datastream.DataStream
;
import
org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
;
import
org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
;
import
javax.xml.crypto.Data
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -42,8 +39,8 @@ public class FlinkKafka2MysqlApp {
...
@@ -42,8 +39,8 @@ public class FlinkKafka2MysqlApp {
//绿信比 = 每个相位的绿灯时长累加 - 启动损失时间 - 清场损失时间
//绿信比 = 每个相位的绿灯时长累加 - 启动损失时间 - 清场损失时间
Cycle
cycle
=
JSON
.
parseObject
(
s
,
Cycle
.
class
);
Cycle
cycle
=
JSON
.
parseObject
(
s
,
Cycle
.
class
);
Long
allValidGreen
=
0L
;
Long
allValidGreen
=
0L
;
List
<
Phase
>
phaseList
=
cycle
.
getPhas
eList
();
List
<
Stage
>
phaseList
=
cycle
.
getStag
eList
();
for
(
Phas
e
phase
:
phaseList
)
{
for
(
Stag
e
phase
:
phaseList
)
{
// 绿灯时间
// 绿灯时间
long
green
=
phase
.
getGreen
();
long
green
=
phase
.
getGreen
();
// 黄灯时间
// 黄灯时间
...
@@ -60,7 +57,7 @@ public class FlinkKafka2MysqlApp {
...
@@ -60,7 +57,7 @@ public class FlinkKafka2MysqlApp {
}
}
// 绿信比
// 绿信比
Double
lxb
=
allValidGreen
.
doubleValue
()
/
cycle
.
getDuration
()
.
doubleValue
()
;
Double
lxb
=
allValidGreen
.
doubleValue
()
/
cycle
.
getDuration
();
return
Tuple2
.
of
(
cycle
.
getCrossCode
(),
lxb
);
return
Tuple2
.
of
(
cycle
.
getCrossCode
(),
lxb
);
}
}
});
});
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/flow/GreenRadioJob.java
View file @
0e8073be
...
@@ -2,7 +2,7 @@ package com.zhht.irn.flow;
...
@@ -2,7 +2,7 @@ package com.zhht.irn.flow;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.
Phas
e
;
import
com.zhht.irn.entity.
Stag
e
;
import
com.zhht.irn.sink.GreenRadioSink
;
import
com.zhht.irn.sink.GreenRadioSink
;
import
org.apache.flink.api.common.functions.MapFunction
;
import
org.apache.flink.api.common.functions.MapFunction
;
import
org.apache.flink.streaming.api.datastream.DataStream
;
import
org.apache.flink.streaming.api.datastream.DataStream
;
...
@@ -20,14 +20,14 @@ public class GreenRadioJob {
...
@@ -20,14 +20,14 @@ public class GreenRadioJob {
// DataStream<String> stream = FlinkUtils.createKafkaStreamV2(args, SimpleStringSchema.class);
// DataStream<String> stream = FlinkUtils.createKafkaStreamV2(args, SimpleStringSchema.class);
// 目前假设从Kafka接入的数据为json格式的字符串
// 目前假设从Kafka接入的数据为json格式的字符串
// Cycle Topic 的消息格式如下:
// Cycle Topic 的消息格式如下:
// {"
Id":"","CrossCode":"","BeginTime":"","EndTime":"","Duration":"","CycleOrder":"
",
// {"
id":"1","crossCode":"0001","beginDateTime":"2020-08-02 08:00:00","endDateTime":"2020-08-02 08:05:00","duration":"300","cycleOrder":"1
",
//
"detail":[{"PhaseValue":"101","BeginTime":"","EndTime":"","Duration":"","Green":"","Yellow":"","AllRed":""},
//
"stageList":[
//
{"PhaseValue":"102","BeginTime":"","EndTime":"","Duration":"","Green":"","Yellow":"","AllRed":"
"},
//
{"phaseValue":"101","beginDateTime":"2020-08-02 08:00:00","endDateTime":"2020-08-02 08:01:00","duration":"60","green":"30","yellow":"3","allRed":"0","phaseOrder":"1
"},
//
{"PhaseValue":"103","BeginTime":"","EndTime":"","Duration":"","Green":"","Yellow":"","AllRed":""},
//
{"phaseValue":"102","beginDateTime":"2020-08-02 08:00:00","endDateTime":"2020-08-02 08:05:00","duration":"240","green":"120","yellow":"3","allRed":"0","phaseOrder":"2"}
//
{"PhaseValue":"104","BeginTime":"","EndTime":"","Duration":"","Green":"","Yellow":"","AllRed":""}
]
// ]
//}
// 造一条数据
// 造一条数据
DataStream
<
String
>
stream
=
env
.
fromElements
(
"{\"id\":\"1\",\"crossCode\":\"0001\",\"begin
Time\":\"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\":\"102\",\"beginTime\":\"2020-08-02 08:00:00\",\"end
Time\":\"2020-08-02 08:05:00\",\"duration\":\"240\",\"green\":\"120\",\"yellow\":\"3\",\"allRed\":\"0\"}]}"
);
DataStream
<
String
>
stream
=
env
.
fromElements
(
"{\"id\":\"1\",\"crossCode\":\"0001\",\"begin
DateTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:05:00\",\"duration\":\"300\",\"cycleOrder\":\"1\",\"stageList\":[{\"phaseValue\":\"101\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"beginDateTime\":\"2020-08-02 08:01:00\",\"duration\":\"60\",\"green\":\"30\",\"yellow\":\"3\",\"allRed\":\"0\"},{\"phaseValue\":\"102\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"beginDate
Time\":\"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
{
...
@@ -42,16 +42,16 @@ public class GreenRadioJob {
...
@@ -42,16 +42,16 @@ public class GreenRadioJob {
int
duration
=
cycle
.
getDuration
();
int
duration
=
cycle
.
getDuration
();
String
crossCode
=
cycle
.
getCrossCode
();
String
crossCode
=
cycle
.
getCrossCode
();
double
cycleGreenRatio
=
0
;
double
cycleGreenRatio
=
0
;
List
<
Phase
>
phaseList
=
cycle
.
getPhas
eList
();
List
<
Stage
>
stageList
=
cycle
.
getStag
eList
();
for
(
Phase
phase
:
phas
eList
)
{
for
(
Stage
stage
:
stag
eList
)
{
//相位号
//相位号
String
phaseValue
=
phas
e
.
getPhaseValue
();
String
phaseValue
=
stag
e
.
getPhaseValue
();
// 绿灯时间
// 绿灯时间
int
green
=
phas
e
.
getGreen
();
int
green
=
stag
e
.
getGreen
();
// 黄灯时间
// 黄灯时间
int
yellow
=
phas
e
.
getYellow
();
int
yellow
=
stag
e
.
getYellow
();
// 全红时间
// 全红时间
int
allRed
=
phas
e
.
getAllRed
();
int
allRed
=
stag
e
.
getAllRed
();
// 启动损失时间,一般定义:2s
// 启动损失时间,一般定义:2s
int
startLossTime
=
2
;
int
startLossTime
=
2
;
//清场损失时间
//清场损失时间
...
@@ -67,8 +67,8 @@ public class GreenRadioJob {
...
@@ -67,8 +67,8 @@ public class GreenRadioJob {
double
phaseGreenRatio
=
Double
.
valueOf
(
phaseValidGreen
)/
duration
;
double
phaseGreenRatio
=
Double
.
valueOf
(
phaseValidGreen
)/
duration
;
System
.
out
.
println
(
"******phaseGreenRatio:"
+
phaseGreenRatio
);
System
.
out
.
println
(
"******phaseGreenRatio:"
+
phaseGreenRatio
);
//组装阶段绿信比
//组装阶段绿信比
phas
e
.
setGreenRatio
(
phaseGreenRatio
);
stag
e
.
setGreenRatio
(
phaseGreenRatio
);
phas
e
.
setValidGreen
(
phaseValidGreen
);
stag
e
.
setValidGreen
(
phaseValidGreen
);
//周期绿信比= 各个阶段绿信比之和
//周期绿信比= 各个阶段绿信比之和
cycleGreenRatio
=
cycleGreenRatio
+
phaseGreenRatio
;
cycleGreenRatio
=
cycleGreenRatio
+
phaseGreenRatio
;
System
.
out
.
println
(
"******cycleGreenRatio:"
+
cycleGreenRatio
);
System
.
out
.
println
(
"******cycleGreenRatio:"
+
cycleGreenRatio
);
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/sink/GreenRadioSink.java
View file @
0e8073be
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.
Phas
e
;
import
com.zhht.irn.entity.
Stag
e
;
import
com.zhht.irn.utils.MySQLUtils
;
import
com.zhht.irn.utils.MySQLUtils
;
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
;
...
@@ -46,19 +46,19 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
...
@@ -46,19 +46,19 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
System
.
out
.
println
(
"=====invoke======"
+
cycle
.
getId
()
+
"-->"
+
cycle
.
getCrossCode
());
System
.
out
.
println
(
"=====invoke======"
+
cycle
.
getId
()
+
"-->"
+
cycle
.
getCrossCode
());
insertCyclePstmt
.
setLong
(
1
,
cycle
.
getId
());
insertCyclePstmt
.
setLong
(
1
,
cycle
.
getId
());
insertCyclePstmt
.
setString
(
2
,
cycle
.
getCrossCode
());
insertCyclePstmt
.
setString
(
2
,
cycle
.
getCrossCode
());
insertCyclePstmt
.
setString
(
3
,
cycle
.
getBeginTime
());
insertCyclePstmt
.
setString
(
3
,
cycle
.
getBegin
Date
Time
());
insertCyclePstmt
.
setString
(
4
,
cycle
.
getEndTime
());
insertCyclePstmt
.
setString
(
4
,
cycle
.
getEnd
Date
Time
());
insertCyclePstmt
.
setInt
(
5
,
cycle
.
getDuration
());
insertCyclePstmt
.
setInt
(
5
,
cycle
.
getDuration
());
insertCyclePstmt
.
setDouble
(
6
,
cycle
.
getGreenRatio
());
insertCyclePstmt
.
setDouble
(
6
,
cycle
.
getGreenRatio
());
insertCyclePstmt
.
execute
();
insertCyclePstmt
.
execute
();
List
<
Phase
>
phaseList
=
cycle
.
getPhas
eList
();
List
<
Stage
>
stageList
=
cycle
.
getStag
eList
();
for
(
int
i
=
0
;
i
<
phas
eList
.
size
();
i
++){
for
(
int
i
=
0
;
i
<
stag
eList
.
size
();
i
++){
Phase
phase
=
phas
eList
.
get
(
i
);
Stage
phase
=
stag
eList
.
get
(
i
);
insertPhasePstmt
.
setLong
(
1
,
cycle
.
getId
());
insertPhasePstmt
.
setLong
(
1
,
cycle
.
getId
());
insertPhasePstmt
.
setString
(
2
,
phase
.
getCrossCode
());
insertPhasePstmt
.
setString
(
2
,
phase
.
getCrossCode
());
insertPhasePstmt
.
setString
(
3
,
phase
.
getPhaseValue
());
insertPhasePstmt
.
setString
(
3
,
phase
.
getPhaseValue
());
insertPhasePstmt
.
setString
(
4
,
cycle
.
getBeginTime
());
insertPhasePstmt
.
setString
(
4
,
cycle
.
getBegin
Date
Time
());
insertPhasePstmt
.
setString
(
5
,
cycle
.
getEndTime
());
insertPhasePstmt
.
setString
(
5
,
cycle
.
getEnd
Date
Time
());
insertPhasePstmt
.
setInt
(
6
,
cycle
.
getDuration
());
insertPhasePstmt
.
setInt
(
6
,
cycle
.
getDuration
());
insertPhasePstmt
.
setDouble
(
7
,
phase
.
getGreenRatio
());
insertPhasePstmt
.
setDouble
(
7
,
phase
.
getGreenRatio
());
insertPhasePstmt
.
setInt
(
8
,
phase
.
getValidGreen
());
insertPhasePstmt
.
setInt
(
8
,
phase
.
getValidGreen
());
...
...
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