Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
Project
Project
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
e6cc92de
Commit
e6cc92de
authored
Apr 09, 2019
by
王志伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加app使用时间
parent
0c75f2a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
63 deletions
+87
-63
temp_analysis.scala
eda/feededa/src/main/scala/com/gmei/temp_analysis.scala
+87
-63
No files found.
eda/feededa/src/main/scala/com/gmei/temp_analysis.scala
View file @
e6cc92de
...
...
@@ -558,80 +558,104 @@ object alpha_ctr {
//println(param.date)
val
partition_date
=
stat_date
.
replace
(
"-"
,
""
)
val
click_count_recommend
=
sc
.
sql
(
s
"""
|select '${stat_date}' as stat_date,count(*) as click_count_recommend
|from bl.bl_alpha_et_mg_maidianlog_inc_d
|where params['tab_name']='recommend'
|and params['page_name']='home'
|and type='on_click_feed_topic_card'
|and partition_day='${partition_date}'
"""
.
stripMargin
)
click_count_recommend
.
show
()
val
click_count_focus
=
sc
.
sql
(
s
"""
|select '${stat_date}' as stat_date,count(*) as click_count_focus
|from bl.bl_alpha_et_mg_maidianlog_inc_d
|where params['tab_name']='focus'
|and params['page_name']='home'
|and type='on_click_feed_topic_card'
|and partition_day='${partition_date}'
"""
.
stripMargin
)
click_count_focus
.
show
()
def
parse_json
(
str
:
String
)
:
Int
={
var
t
=
List
[
Map
[
String
,
Any
]]()
val
result
=
JSON
.
parseFull
(
str
)
result
match
{
case
Some
(
b
:
List
[
Map
[
String
,
Any
]])
=>
t
=
t
++
b
case
None
=>
println
(
"Parsing failed"
)
case
other
=>
println
(
"Unknown data structure: "
+
other
)
}
t
.
size
}
val
expoure_cards
=
sc
.
sql
(
// val click_count_recommend = sc.sql(
// s"""
// |select '${stat_date}' as stat_date,count(*) as click_count_recommend
// |from bl.bl_alpha_et_mg_maidianlog_inc_d
// |where params['tab_name']='recommend'
// |and params['page_name']='home'
// |and type='on_click_feed_topic_card'
// |and partition_day='${partition_date}'
// """.stripMargin
// )
// click_count_recommend.show()
//
// val click_count_focus = sc.sql(
// s"""
// |select '${stat_date}' as stat_date,count(*) as click_count_focus
// |from bl.bl_alpha_et_mg_maidianlog_inc_d
// |where params['tab_name']='focus'
// |and params['page_name']='home'
// |and type='on_click_feed_topic_card'
// |and partition_day='${partition_date}'
// """.stripMargin
// )
// click_count_focus.show()
//
//
// def parse_json(str:String): Int ={
// var t = List[Map[String, Any]]()
// val result = JSON.parseFull(str)
// result match {
// case Some(b: List[Map[String, Any]]) => t = t ++ b
// case None => println("Parsing failed")
// case other => println("Unknown data structure: " + other)
// }
// t.size
//
// }
//
// val expoure_cards=sc.sql(
// s"""
// |select params['exposure_cards'] as exposure_cards
// |from bl.bl_alpha_et_mg_maidianlog_inc_d
// |where params['tab_name'] = 'recommend'
// |and params['page_name'] = 'home'
// |and type = 'page_precise_exposure'
// |and partition_day='${partition_date}'
// """.stripMargin
// )
// val a =expoure_cards.rdd.map(row => row(0).toString).map(row=>parse_json(row)).collect().sum
// val result1=List((stat_date,a))
// val df1 = sc.createDataFrame(result1).toDF("stat_date","expoure_count_recommend")
//
// val expoure_cards2=sc.sql(
// s"""
// |select params['exposure_cards'] as exposure_cards
// |from bl.bl_alpha_et_mg_maidianlog_inc_d
// |where params['tab_name'] = 'focus'
// |and params['page_name'] = 'home'
// |and type = 'page_precise_exposure'
// |and partition_day='${partition_date}'
// """.stripMargin
// )
// val b =expoure_cards2.rdd.map(row => row(0).toString).map(row=>parse_json(row)).collect().sum
// val result2=List((stat_date,b))
// val df2 = sc.createDataFrame(result2).toDF("stat_date","expoure_count_focus")
//
//
//
// val result=click_count_recommend.join(click_count_focus,"stat_date")
// .join(df1,"stat_date")
// .join(df2,"stat_date")
//
//
//
// GmeiConfig.writeToJDBCTable(result, "alpha_ctr", SaveMode.Append)
val
device_duration_avge
=
sc
.
sql
(
s
"""
|
select params['exposure_cards'] as exposure_cards
|
SELECT '${stat_date}' as stat_date,sum(a.time_all)/count(a.device_id) as averge_time from (select device_id,sum(params['duration']) as time_all
|from bl.bl_alpha_et_mg_maidianlog_inc_d
|where params['tab_name'] = 'recommend'
|and params['page_name'] = 'home'
|and type = 'page_precise_exposure'
|where type='on_app_session_over'
|and partition_day='${partition_date}'
|GROUP BY device_id) a
"""
.
stripMargin
)
val
a
=
expoure_cards
.
rdd
.
map
(
row
=>
row
(
0
).
toString
).
map
(
row
=>
parse_json
(
row
)).
collect
().
sum
val
result1
=
List
((
stat_date
,
a
))
val
df1
=
sc
.
createDataFrame
(
result1
).
toDF
(
"stat_date"
,
"expoure_count_recommend"
)
device_duration_avge
.
show
()
val
expoure_cards2
=
sc
.
sql
(
val
duration_everytime_avge
=
sc
.
sql
(
s
"""
|
select params['exposure_cards'] as exposure_cards
|
SELECT '${stat_date}' as stat_date,sum(a.time_duration)/count(a.device_id) as averge_time from (select device_id,params['duration'] as time_duration
|from bl.bl_alpha_et_mg_maidianlog_inc_d
|where params['tab_name'] = 'focus'
|and params['page_name'] = 'home'
|and type = 'page_precise_exposure'
|and partition_day='${partition_date}'
|where type='on_app_session_over'
|and partition_day='20190404') a
"""
.
stripMargin
)
val
b
=
expoure_cards2
.
rdd
.
map
(
row
=>
row
(
0
).
toString
).
map
(
row
=>
parse_json
(
row
)).
collect
().
sum
val
result2
=
List
((
stat_date
,
b
))
val
df2
=
sc
.
createDataFrame
(
result2
).
toDF
(
"stat_date"
,
"expoure_count_focus"
)
val
result
=
click_count_recommend
.
join
(
click_count_focus
,
"stat_date"
)
.
join
(
df1
,
"stat_date"
)
.
join
(
df2
,
"stat_date"
)
GmeiConfig
.
writeToJDBCTable
(
result
,
"alpha_ctr"
,
SaveMode
.
Append
)
val
result3
=
device_duration_avge
.
join
(
duration_everytime_avge
,
"stat_date"
)
GmeiConfig
.
writeToJDBCTable
(
result3
,
"alpha_duration"
,
SaveMode
.
Append
)
}
...
...
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