Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
app-collection
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐顺
app-collection
Commits
c462afc8
Commit
c462afc8
authored
Jan 28, 2021
by
RingEric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
事件数据处理
parent
f191e073
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
11 deletions
+42
-11
src/main/scala/qm/flink/Analysis.scala
src/main/scala/qm/flink/Analysis.scala
+42
-11
No files found.
src/main/scala/qm/flink/Analysis.scala
View file @
c462afc8
package
qm.flink
import
qm.jackson.Jackson
import
qm.model.ActionItem
import
java.util
import
scala.collection.JavaConversions._
import
scala.collection.mutable.ArrayBuffer
/**
* @ClassName: Analysis
* @Description: TODO
...
...
@@ -20,12 +21,11 @@ object Analysis {
* @param x 要处理的数据,json字符串
* @return 返回搜索结果
*/
def
analysis
(
x
:
String
)
:
Array
[
(
String
,
Any
)
]
=
{
def
analysis
(
x
:
String
)
:
Array
[
ActionItem
]
=
{
val
tuples
:
ArrayBuffer
[(
String
,
Any
)]
=
new
ArrayBuffer
[(
String
,
Any
)]()
val
collections
:
Array
[
String
]
=
x
.
split
(
"#QM#MQ#"
)
if
(
collections
.
length
<
2
)
{
return
Array
(
(
""
,
""
))
return
Array
(
ActionItem
(
""
,
""
,
""
,
""
,
""
))
}
val
head
:
String
=
collections
(
0
)
val
tail
:
String
=
collections
(
1
)
...
...
@@ -37,19 +37,50 @@ object Analysis {
Jackson
.
autoParseJson
(
head
,
headMap
)
Jackson
.
autoParseJson
(
tail
,
tailMap
)
val
keys
=
headMap
.
keySet
()
val
tails
=
tailMap
.
keySet
()
//创建时间
val
ctime
=
headMap
.
getOrDefault
(
"ctime"
,
""
).
toString
//用户的IP地址
val
ip
=
headMap
.
getOrDefault
(
"ip"
,
""
).
toString
//取出单条埋点数据的信息
val
project
=
tailMap
.
getOrDefault
(
"projects"
,
""
).
toString
//设备id
val
deviceId
=
tailMap
.
getOrDefault
(
"device_id"
,
""
).
toString
for
(
key
<-
keys
)
{
tuples
.
append
((
key
,
headMap
.
get
(
key
)
))
if
(
project
.
isEmpty
)
{
return
Array
(
ActionItem
(
ip
,
deviceId
,
""
,
""
,
ctime
))
}
for
(
tailKey
<-
tails
)
{
tuples
.
append
((
tailKey
,
tailMap
.
get
(
tailKey
)))
val
events
=
parseProjects
(
project
)
val
results
=
new
ArrayBuffer
[
ActionItem
]()
for
(
event
<-
events
)
{
results
.
append
(
ActionItem
(
ip
,
deviceId
,
event
.
_1
,
event
.
_2
,
ctime
))
}
results
.
toArray
}
def
parseProjects
(
projectStr
:
String
)
:
Array
[(
String
,
String
)]
=
{
// json数组转数组
val
projects
:
Array
[
AnyRef
]
=
Jackson
.
string2Array
(
projectStr
)
tuples
.
toArray
val
eventTuple
=
new
ArrayBuffer
[(
String
,
String
)]()
//数组不为空
if
(!
projects
.
isEmpty
)
{
val
eventMap
=
new
util
.
HashMap
[
String
,
Any
]()
for
(
project
<-
projects
)
{
Jackson
.
autoParseJson
(
project
.
toString
,
eventMap
)
val
eventName
=
eventMap
.
getOrDefault
(
"event_name"
,
""
).
toString
val
eventDataStr
=
eventMap
.
getOrDefault
(
"event_data"
,
""
).
toString
eventTuple
.
append
((
eventName
,
eventDataStr
))
}
}
eventTuple
.
toArray
}
}
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