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
a1a9ccb3
Commit
a1a9ccb3
authored
Nov 24, 2022
by
余根龙
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
85160c76
0a1eab4b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
46 deletions
+112
-46
Travel.java
...m-streaming/src/main/java/com/zhht/irn/entity/Travel.java
+10
-11
TravelInfoJob.java
...reaming/src/main/java/com/zhht/irn/job/TravelInfoJob.java
+1
-6
TravelMetricSink.java
...ing/src/main/java/com/zhht/irn/sink/TravelMetricSink.java
+51
-29
DorisUtils.java
...treaming/src/main/java/com/zhht/irn/utils/DorisUtils.java
+50
-0
No files found.
realtime/hologram-streaming/src/main/java/com/zhht/irn/entity/Travel.java
View file @
a1a9ccb3
...
@@ -32,8 +32,8 @@ public class Travel {
...
@@ -32,8 +32,8 @@ public class Travel {
// 旅行结束时间
// 旅行结束时间
private
String
travelEndTime
;
private
String
travelEndTime
;
//
旅行时长= 旅行结束 - 旅行开始 (毫秒)
//
流向
private
long
travelDura
tion
;
private
String
flowDirec
tion
;
// 车辆ID
// 车辆ID
private
Long
carId
;
private
Long
carId
;
...
@@ -105,7 +105,7 @@ public class Travel {
...
@@ -105,7 +105,7 @@ public class Travel {
private
String
lastTime
;
private
String
lastTime
;
// 旅行时长,驶离时刻 - 到达时刻, 单位秒
// 旅行时长,驶离时刻 - 到达时刻, 单位秒
private
int
crossingTime
;
private
double
crossingTime
;
// 旅行时点位集合
// 旅行时点位集合
private
List
<
Location
>
locations
;
private
List
<
Location
>
locations
;
...
@@ -360,11 +360,11 @@ public class Travel {
...
@@ -360,11 +360,11 @@ public class Travel {
this
.
lastTime
=
lastTime
;
this
.
lastTime
=
lastTime
;
}
}
public
int
getCrossingTime
()
{
public
double
getCrossingTime
()
{
return
crossingTime
;
return
crossingTime
;
}
}
public
void
setCrossingTime
(
int
crossingTime
)
{
public
void
setCrossingTime
(
double
crossingTime
)
{
this
.
crossingTime
=
crossingTime
;
this
.
crossingTime
=
crossingTime
;
}
}
...
@@ -424,12 +424,12 @@ public class Travel {
...
@@ -424,12 +424,12 @@ public class Travel {
this
.
maxSpeed
=
maxSpeed
;
this
.
maxSpeed
=
maxSpeed
;
}
}
public
long
getTravelDura
tion
()
{
public
String
getFlowDirec
tion
()
{
return
travelDura
tion
;
return
flowDirec
tion
;
}
}
public
void
set
TravelDuration
(
long
travelDura
tion
)
{
public
void
set
FlowDirection
(
String
flowDirec
tion
)
{
this
.
travelDuration
=
travelDura
tion
;
this
.
flowDirection
=
flowDirec
tion
;
}
}
@Override
@Override
...
@@ -441,7 +441,7 @@ public class Travel {
...
@@ -441,7 +441,7 @@ public class Travel {
", recordTime='"
+
recordTime
+
'\''
+
", recordTime='"
+
recordTime
+
'\''
+
", travelBeginTime='"
+
travelBeginTime
+
'\''
+
", travelBeginTime='"
+
travelBeginTime
+
'\''
+
", travelEndTime='"
+
travelEndTime
+
'\''
+
", travelEndTime='"
+
travelEndTime
+
'\''
+
",
travelDuration='"
+
travelDura
tion
+
'\''
+
",
flowDirection='"
+
flowDirec
tion
+
'\''
+
", carId="
+
carId
+
", carId="
+
carId
+
", carColor='"
+
carColor
+
'\''
+
", carColor='"
+
carColor
+
'\''
+
", plate='"
+
plate
+
'\''
+
", plate='"
+
plate
+
'\''
+
...
@@ -466,7 +466,6 @@ public class Travel {
...
@@ -466,7 +466,6 @@ public class Travel {
", lastSpeed="
+
lastSpeed
+
", lastSpeed="
+
lastSpeed
+
", lastTime='"
+
lastTime
+
'\''
+
", lastTime='"
+
lastTime
+
'\''
+
", crossingTime="
+
crossingTime
+
", crossingTime="
+
crossingTime
+
", locations="
+
locations
+
", remark='"
+
remark
+
'\''
+
", remark='"
+
remark
+
'\''
+
", stopCount="
+
stopCount
+
", stopCount="
+
stopCount
+
", stopTime="
+
stopTime
+
", stopTime="
+
stopTime
+
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/job/TravelInfoJob.java
View file @
a1a9ccb3
...
@@ -31,7 +31,7 @@ public class TravelInfoJob {
...
@@ -31,7 +31,7 @@ public class TravelInfoJob {
// 通过kafka配置文件,获取String类型的实时数据流
// 通过kafka配置文件,获取String类型的实时数据流
DataStream
<
String
>
rawStringStream
=
FlinkUtils
.
createKafkaStream
(
args
,
env
);
DataStream
<
String
>
rawStringStream
=
FlinkUtils
.
createKafkaStream
(
args
,
env
);
// DataStream<String> rawStringStream = env.readTextFile("./data/2022-11-23--11/.part-820a21c1-f4fa-485e-a3ed-b65e15fefdfa-0.inprogress.59c1cbee-8597-4dd7-a2fc-12c8df8db83d");
// 接入数据的第一时间,要进行本地文件备份,以便后续问题排查
// 接入数据的第一时间,要进行本地文件备份,以便后续问题排查
rawStringStream
.
sinkTo
(
FileUtils
.
getFileSink
(
"./data/"
));
rawStringStream
.
sinkTo
(
FileUtils
.
getFileSink
(
"./data/"
));
...
@@ -46,15 +46,11 @@ public class TravelInfoJob {
...
@@ -46,15 +46,11 @@ public class TravelInfoJob {
String
travelStart
=
travel
.
getTravelBeginTime
();
String
travelStart
=
travel
.
getTravelBeginTime
();
String
travelEnd
=
travel
.
getTravelEndTime
();
String
travelEnd
=
travel
.
getTravelEndTime
();
long
duration
=
-
1L
;
// 如果旅行记录没有完整的开始、结束时刻,则无法计算最高、最低、平均速度
// 如果旅行记录没有完整的开始、结束时刻,则无法计算最高、最低、平均速度
if
(
isNotEmpty
(
travelStart
)
&&
isNotEmpty
(
travelEnd
))
{
if
(
isNotEmpty
(
travelStart
)
&&
isNotEmpty
(
travelEnd
))
{
long
longTravelStart
=
Long
.
parseLong
(
travelStart
);
long
longTravelStart
=
Long
.
parseLong
(
travelStart
);
long
longTravelEnd
=
Long
.
parseLong
(
travelEnd
);
long
longTravelEnd
=
Long
.
parseLong
(
travelEnd
);
duration
=
longTravelEnd
-
longTravelStart
;
List
<
Location
>
locations
=
travel
.
getLocations
();
List
<
Location
>
locations
=
travel
.
getLocations
();
for
(
int
i
=
0
;
i
<
locations
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
locations
.
size
();
i
++)
{
...
@@ -121,7 +117,6 @@ public class TravelInfoJob {
...
@@ -121,7 +117,6 @@ public class TravelInfoJob {
}
}
travel
.
setMaxSpeed
(
maxSpeed
);
travel
.
setMaxSpeed
(
maxSpeed
);
travel
.
setMinSpeed
(
minSpeed
);
travel
.
setMinSpeed
(
minSpeed
);
travel
.
setTravelDuration
(
duration
);
logger
.
info
(
"完成旅行信息的指标计算,当前旅行车辆旅行ID{}的实时指标为, 最高速度:{}, 最低速度:{}, 平均速度:{}, 停车次数: {},"
+
logger
.
info
(
"完成旅行信息的指标计算,当前旅行车辆旅行ID{}的实时指标为, 最高速度:{}, 最低速度:{}, 平均速度:{}, 停车次数: {},"
+
"停车总时长:{}"
,
travel
.
getRecordId
(),
maxSpeed
,
minSpeed
,
travel
.
getAvgSpeed
(),
stopCount
,
stopTime
);
"停车总时长:{}"
,
travel
.
getRecordId
(),
maxSpeed
,
minSpeed
,
travel
.
getAvgSpeed
(),
stopCount
,
stopTime
);
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/sink/TravelMetricSink.java
View file @
a1a9ccb3
package
com
.
zhht
.
irn
.
sink
;
package
com
.
zhht
.
irn
.
sink
;
import
com.zhht.irn.entity.Travel
;
import
com.zhht.irn.entity.Travel
;
import
com.zhht.irn.utils.DateUtils
;
import
com.zhht.irn.utils.DorisUtils
;
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
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
static
com
.
zhht
.
irn
.
utils
.
DateUtils
.
longToString
;
import
static
com
.
zhht
.
irn
.
utils
.
DateUtils
.
longToString
;
...
@@ -22,15 +23,16 @@ public class TravelMetricSink extends RichSinkFunction<Travel> {
...
@@ -22,15 +23,16 @@ public class TravelMetricSink extends RichSinkFunction<Travel> {
@Override
@Override
public
void
open
(
Configuration
parameters
)
throws
Exception
{
public
void
open
(
Configuration
parameters
)
throws
Exception
{
super
.
open
(
parameters
);
super
.
open
(
parameters
);
connection
=
MySQL
Utils
.
getConnection
();
connection
=
Doris
Utils
.
getConnection
();
//目前值考虑插入,不考虑更新
//目前值考虑插入,不考虑更新
String
insertSql
=
""
+
String
insertSql
=
""
+
"insert into app_travel_metric"
+
"insert into app_travel_metric"
+
"(incross_line_id, car_id, cross_id, plate, record_id, capture_time, lost_time, arrived_time, incross_time, "
+
"(record_id, cross_id, record_time, travel_begin_time, travel_end_time, flow_direction, car_id, car_color, plate, plate_color, car_type, "
+
"outcross_time, away_time, stop_count, stop_time, avg_speed, min_speed, max_speed, update_time, travel_begin_time,"
+
"first_lane_id, first_time, first_speed, arrived_lane_id, arrived_time, arrived_speed, incross_lane_id, incross_time, incross_speed, "
+
" travel_end_time, arrived_line_id, outcross_line_id, away_line_id, duration)"
+
"outcross_lane_id, outcross_time, outcross_speed, away_lane_id, away_time, away_speed, last_lane_id, last_time, last_speed, duration, min_speed, "
+
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
;
"max_speed, avg_speed, stop_count, stop_time, statistic_time)"
+
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
;
insertPstmt
=
connection
.
prepareStatement
(
insertSql
);
insertPstmt
=
connection
.
prepareStatement
(
insertSql
);
}
}
@Override
@Override
...
@@ -43,29 +45,49 @@ public class TravelMetricSink extends RichSinkFunction<Travel> {
...
@@ -43,29 +45,49 @@ public class TravelMetricSink extends RichSinkFunction<Travel> {
@Override
@Override
public
void
invoke
(
Travel
travel
,
Context
context
)
throws
Exception
{
public
void
invoke
(
Travel
travel
,
Context
context
)
throws
Exception
{
System
.
out
.
println
(
"=====insert travel ======"
+
travel
);
System
.
out
.
println
(
"=====insert travel ======"
+
travel
);
insertPstmt
.
setString
(
1
,
travel
.
getInCrossLineId
());
insertPstmt
.
setString
(
1
,
travel
.
getRecordId
());
insertPstmt
.
setLong
(
2
,
travel
.
getCarId
());
insertPstmt
.
setString
(
2
,
travel
.
getCrossId
());
insertPstmt
.
setString
(
3
,
travel
.
getCrossId
());
insertPstmt
.
setDate
(
3
,
new
Date
(
Long
.
parseLong
(
travel
.
getRecordTime
())));
insertPstmt
.
setString
(
4
,
travel
.
getPlate
());
insertPstmt
.
setString
(
4
,
longToString
(
travel
.
getTravelBeginTime
(),
timeFormat
));
insertPstmt
.
setString
(
5
,
travel
.
getRecordId
());
insertPstmt
.
setString
(
5
,
longToString
(
travel
.
getTravelEndTime
(),
timeFormat
));
insertPstmt
.
setString
(
6
,
longToString
(
travel
.
getFirstTime
(),
timeFormat
));
insertPstmt
.
setString
(
6
,
travel
.
getFlowDirection
());
insertPstmt
.
setString
(
7
,
longToString
(
travel
.
getLastTime
(),
timeFormat
));
insertPstmt
.
setLong
(
7
,
travel
.
getCarId
());
insertPstmt
.
setString
(
8
,
longToString
(
travel
.
getArrivedTime
(),
timeFormat
));
insertPstmt
.
setString
(
8
,
travel
.
getCarColor
());
insertPstmt
.
setString
(
9
,
longToString
(
travel
.
getInCrossTime
(),
timeFormat
));
insertPstmt
.
setString
(
9
,
travel
.
getPlate
());
insertPstmt
.
setString
(
10
,
longToString
(
travel
.
getOutCrossTime
(),
timeFormat
));
insertPstmt
.
setString
(
10
,
travel
.
getPlateColor
());
insertPstmt
.
setString
(
11
,
longToString
(
travel
.
getAwayTime
(),
timeFormat
));
insertPstmt
.
setString
(
11
,
travel
.
getCarType
());
insertPstmt
.
setInt
(
12
,
travel
.
getStopCount
());
insertPstmt
.
setDouble
(
13
,
travel
.
getStopTime
());
insertPstmt
.
setString
(
12
,
travel
.
getFirstLineId
());
insertPstmt
.
setDouble
(
14
,
travel
.
getAvgSpeed
());
insertPstmt
.
setString
(
13
,
longToString
(
travel
.
getFirstTime
(),
timeFormat
));
insertPstmt
.
setDouble
(
15
,
travel
.
getMinSpeed
());
insertPstmt
.
setDouble
(
14
,
travel
.
getFirstSpeed
());
insertPstmt
.
setDouble
(
16
,
travel
.
getMaxSpeed
());
insertPstmt
.
setString
(
17
,
DateUtils
.
getTodayTime
());
insertPstmt
.
setString
(
15
,
travel
.
getArrivedLineId
());
insertPstmt
.
setString
(
18
,
longToString
(
travel
.
getTravelBeginTime
(),
timeFormat
));
insertPstmt
.
setString
(
16
,
longToString
(
travel
.
getArrivedTime
(),
timeFormat
));
insertPstmt
.
setString
(
19
,
longToString
(
travel
.
getTravelEndTime
(),
timeFormat
));
insertPstmt
.
setDouble
(
17
,
travel
.
getArrivedSpeed
());
insertPstmt
.
setString
(
20
,
travel
.
getArrivedLineId
());
insertPstmt
.
setString
(
18
,
travel
.
getInCrossLineId
());
insertPstmt
.
setString
(
19
,
longToString
(
travel
.
getInCrossTime
(),
timeFormat
));
insertPstmt
.
setDouble
(
20
,
travel
.
getInSpeed
());
insertPstmt
.
setString
(
21
,
travel
.
getOutCrossLineId
());
insertPstmt
.
setString
(
21
,
travel
.
getOutCrossLineId
());
insertPstmt
.
setString
(
22
,
travel
.
getAwayLineId
());
insertPstmt
.
setString
(
22
,
longToString
(
travel
.
getOutCrossTime
(),
timeFormat
));
insertPstmt
.
setLong
(
23
,
travel
.
getTravelDuration
());
insertPstmt
.
setDouble
(
23
,
travel
.
getOutSpeed
());
insertPstmt
.
setString
(
24
,
travel
.
getAwayLineId
());
insertPstmt
.
setString
(
25
,
longToString
(
travel
.
getAwayTime
(),
timeFormat
));
insertPstmt
.
setDouble
(
26
,
travel
.
getAwaySpeed
());
insertPstmt
.
setString
(
27
,
travel
.
getLastLineId
());
insertPstmt
.
setString
(
28
,
longToString
(
travel
.
getLastTime
(),
timeFormat
));
insertPstmt
.
setDouble
(
29
,
travel
.
getLastSpeed
());
insertPstmt
.
setDouble
(
30
,
travel
.
getCrossingTime
());
insertPstmt
.
setDouble
(
31
,
travel
.
getMinSpeed
());
insertPstmt
.
setDouble
(
32
,
travel
.
getMaxSpeed
());
insertPstmt
.
setDouble
(
33
,
travel
.
getAvgSpeed
());
insertPstmt
.
setInt
(
34
,
travel
.
getStopCount
());
insertPstmt
.
setDouble
(
35
,
travel
.
getStopTime
());
insertPstmt
.
setString
(
36
,
longToString
(
System
.
currentTimeMillis
(),
timeFormat
));
insertPstmt
.
execute
();
insertPstmt
.
execute
();
}
}
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/utils/DorisUtils.java
0 → 100644
View file @
a1a9ccb3
package
com
.
zhht
.
irn
.
utils
;
import
org.apache.flink.api.java.utils.ParameterTool
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
public
class
DorisUtils
{
public
static
Connection
getConnection
()
throws
Exception
{
String
propertyPath
=
".\\realtime\\hologram-streaming\\src\\main\\resources\\doris.properties"
;
return
getConnection
(
propertyPath
);
}
public
static
Connection
getConnection
(
String
propertyPath
)
throws
Exception
{
ParameterTool
tool
=
ParameterTool
.
fromPropertiesFile
(
propertyPath
);
// 根据路径的配置文件获取MySQL链接参数
String
driver
=
tool
.
getRequired
(
"driver"
);
String
username
=
tool
.
getRequired
(
"username"
);
String
password
=
tool
.
getRequired
(
"password"
);
String
host
=
tool
.
getRequired
(
"host"
);
String
port
=
tool
.
getRequired
(
"port"
);
String
database
=
tool
.
get
(
"database"
,
"default"
);
String
jdbcUrl
=
String
.
format
(
"jdbc:mysql://%s:%s/%s"
,
host
,
port
,
database
);
Class
.
forName
(
driver
);
return
DriverManager
.
getConnection
(
jdbcUrl
,
username
,
password
);
}
public
static
void
close
(
Connection
connection
,
PreparedStatement
pstmt
)
{
if
(
null
!=
pstmt
)
{
try
{
pstmt
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
if
(
null
!=
connection
)
{
try
{
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
}
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