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
0867941d
Commit
0867941d
authored
Dec 14, 2022
by
吴延飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
按秒计算排队长度时,用停车状态为停止的车辆数来计算排队长度
parent
8435a187
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
62 deletions
+3
-62
CalDirectionSecondMetricFunction.java
.../zhht/irn/functions/CalDirectionSecondMetricFunction.java
+2
-15
CalLaneMetricProcessFunction2.java
...com/zhht/irn/functions/CalLaneMetricProcessFunction2.java
+0
-47
TravelMetricSink.java
...ing/src/main/java/com/zhht/irn/sink/TravelMetricSink.java
+1
-0
No files found.
realtime/hologram-streaming/src/main/java/com/zhht/irn/functions/CalDirectionSecondMetricFunction.java
View file @
0867941d
package
com
.
zhht
.
irn
.
functions
;
package
com
.
zhht
.
irn
.
functions
;
import
com.zhht.irn.consts.Constant
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.TravelEvent
;
import
com.zhht.irn.entity.TravelEvent
;
import
com.zhht.irn.entity.metric.DirectionEvalSecondMetric
;
import
com.zhht.irn.entity.metric.DirectionEvalSecondMetric
;
...
@@ -66,7 +65,7 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
...
@@ -66,7 +65,7 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
});
});
// 计算
两个指标,一个 “发生到达,未进入的车辆数”,
一个“发生到达数”,粒度计算到车道级
// 计算一个“发生到达数”,粒度计算到车道级
for
(
Map
.
Entry
<
String
,
List
<
TravelEvent
>>
entry
:
lineMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
TravelEvent
>>
entry
:
lineMap
.
entrySet
())
{
List
<
TravelEvent
>
travelEventList
=
entry
.
getValue
();
List
<
TravelEvent
>
travelEventList
=
entry
.
getValue
();
...
@@ -89,11 +88,9 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
...
@@ -89,11 +88,9 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
if
(
e
.
getEventType
()
==
EventType
.
STOP
)
{
if
(
e
.
getEventType
()
==
EventType
.
STOP
)
{
recordStopStatusMap
.
put
(
e
.
getRecordId
(),
true
);
recordStopStatusMap
.
put
(
e
.
getRecordId
(),
true
);
globalRecordStopStatusMap
.
put
(
e
.
getRecordId
(),
true
);
globalRecordStopStatusMap
.
put
(
e
.
getRecordId
(),
true
);
System
.
out
.
println
(
"you che 停了"
+
e
.
getRecordId
());
}
else
if
(
e
.
getEventType
()
==
EventType
.
STARTUP
)
{
}
else
if
(
e
.
getEventType
()
==
EventType
.
STARTUP
)
{
recordStopStatusMap
.
put
(
e
.
getRecordId
(),
false
);
recordStopStatusMap
.
put
(
e
.
getRecordId
(),
false
);
globalRecordStopStatusMap
.
put
(
e
.
getRecordId
(),
false
);
globalRecordStopStatusMap
.
put
(
e
.
getRecordId
(),
false
);
System
.
out
.
println
(
"you che 启动了"
+
e
.
getRecordId
());
}
}
}
}
...
@@ -106,22 +103,13 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
...
@@ -106,22 +103,13 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
}
}
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
List
<
TravelEvent
>
lineArrivedAndInCrossList
=
travelEventList
.
stream
().
filter
(
record
->
{
return
record
.
getEventType
()
==
EventType
.
INCROSS
&&
recordIdSet
.
contains
(
record
.
getRecordId
());
}).
collect
(
Collectors
.
toList
());
Set
<
String
>
arrivedRecordIdSet
=
new
HashSet
<>();
Set
<
String
>
arrivedRecordIdSet
=
new
HashSet
<>();
Set
<
String
>
arrivedAndInCrossRecordIdSet
=
new
HashSet
<>();
for
(
TravelEvent
travel:
lineArrivedList
)
{
for
(
TravelEvent
travel:
lineArrivedList
)
{
arrivedRecordIdSet
.
add
(
travel
.
getRecordId
());
arrivedRecordIdSet
.
add
(
travel
.
getRecordId
());
}
}
for
(
TravelEvent
travel:
lineArrivedAndInCrossList
)
{
arrivedAndInCrossRecordIdSet
.
add
(
travel
.
getRecordId
());
}
int
lineArrivedCount
=
arrivedRecordIdSet
.
size
();
int
lineArrivedCount
=
arrivedRecordIdSet
.
size
();
int
lineArrivedAndInCrossCount
=
arrivedAndInCrossRecordIdSet
.
size
();
int
stopFlagCount
=
0
;
int
stopFlagCount
=
0
;
int
stopCount
=
0
;
int
stopCount
=
0
;
...
@@ -138,7 +126,7 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
...
@@ -138,7 +126,7 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
metric
.
setCurrentSecond
(
start
);
metric
.
setCurrentSecond
(
start
);
metric
.
setCycleOrder
(
cycle
.
getCycleOrder
());
metric
.
setCycleOrder
(
cycle
.
getCycleOrder
());
metric
.
setAccArrivedFlow
(
lineArrivedCount
);
metric
.
setAccArrivedFlow
(
lineArrivedCount
);
metric
.
setAccQueueLength
(
lineArrivedCount
-
lineArrivedAndInCross
Count
);
metric
.
setAccQueueLength
(
stopFlag
Count
);
metric
.
setStopFlagCount
(
stopFlagCount
);
metric
.
setStopFlagCount
(
stopFlagCount
);
metric
.
setAccStopCount
(
stopCount
);
metric
.
setAccStopCount
(
stopCount
);
collector
.
collect
(
metric
);
collector
.
collect
(
metric
);
...
@@ -149,7 +137,6 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
...
@@ -149,7 +137,6 @@ public class CalDirectionSecondMetricFunction extends KeyedCoProcessFunction<Str
// 将本周期结束后还处于停车状态的车辆放到listState中
// 将本周期结束后还处于停车状态的车辆放到listState中
listState
.
clear
();
listState
.
clear
();
for
(
Map
.
Entry
<
String
,
Boolean
>
en
:
globalRecordStopStatusMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Boolean
>
en
:
globalRecordStopStatusMap
.
entrySet
())
{
System
.
out
.
println
(
"当前周期的不同记录数:"
+
globalRecordStopStatusMap
.
size
());
if
(
en
.
getValue
()
==
true
)
{
if
(
en
.
getValue
()
==
true
)
{
System
.
out
.
println
(
"stay stop status car record id:"
+
en
.
getKey
());
System
.
out
.
println
(
"stay stop status car record id:"
+
en
.
getKey
());
listState
.
add
(
en
.
getKey
());
listState
.
add
(
en
.
getKey
());
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/functions/CalLaneMetricProcessFunction2.java
deleted
100644 → 0
View file @
8435a187
package
com
.
zhht
.
irn
.
functions
;
import
com.zhht.irn.entity.Cycle
;
import
com.zhht.irn.entity.TravelEvent
;
import
org.apache.flink.api.common.state.MapState
;
import
org.apache.flink.api.common.state.MapStateDescriptor
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.streaming.api.functions.KeyedProcessFunction
;
import
org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction
;
import
org.apache.flink.util.Collector
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 计算车道级指标的函数
*
*/
public
class
CalLaneMetricProcessFunction2
extends
KeyedCoProcessFunction
<
String
,
Cycle
,
TravelEvent
,
Object
>
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CalLaneMetricProcessFunction2
.
class
);
// state 管理当前周期中存储的旅行事件
private
MapState
<
String
,
List
<
TravelEvent
>>
cycleTravel
;
@Override
public
void
open
(
Configuration
parameters
)
throws
Exception
{
super
.
open
(
parameters
);
cycleTravel
=
getRuntimeContext
().
getMapState
(
new
MapStateDescriptor
(
"cycleTravel"
,
String
.
class
,
Object
.
class
));
}
@Override
public
void
processElement1
(
Cycle
cycle
,
KeyedCoProcessFunction
<
String
,
Cycle
,
TravelEvent
,
Object
>.
Context
ctx
,
Collector
<
Object
>
out
)
throws
Exception
{
logger
.
info
(
"进来个周期数据了:"
+
cycle
.
toString
());
// 在此进行指标计算
}
@Override
public
void
processElement2
(
TravelEvent
event
,
KeyedCoProcessFunction
<
String
,
Cycle
,
TravelEvent
,
Object
>.
Context
ctx
,
Collector
<
Object
>
out
)
throws
Exception
{
logger
.
info
(
"进来个事件数据了:"
+
event
.
toString
());
if
(
cycleTravel
.
get
(
event
.
getCrossId
())
==
null
)
{
cycleTravel
.
put
(
event
.
getCrossId
(),
new
ArrayList
<>());
}
cycleTravel
.
get
(
event
.
getCrossId
()).
add
(
event
);
}
}
realtime/hologram-streaming/src/main/java/com/zhht/irn/sink/TravelMetricSink.java
View file @
0867941d
...
@@ -37,6 +37,7 @@ public class TravelMetricSink extends RichSinkFunction<Travel> {
...
@@ -37,6 +37,7 @@ public class TravelMetricSink extends RichSinkFunction<Travel> {
}
}
@Override
@Override
public
void
close
()
throws
Exception
{
public
void
close
()
throws
Exception
{
System
.
out
.
println
(
"执行close方法了"
);
super
.
close
();
super
.
close
();
if
(
insertPstmt
!=
null
)
insertPstmt
.
close
();
if
(
insertPstmt
!=
null
)
insertPstmt
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
...
...
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