Commit 734506ff authored by 王志伟's avatar 王志伟

新统计指标

parent 271a6100
......@@ -46,63 +46,102 @@ object testt {
ti.tidbMapTable(dbName = "jerry_prod", tableName = "blacklist")
ti.tidbMapTable(dbName = "jerry_prod", tableName = "data_feed_exposure")
val stat_date = GmeiConfig.getMinusNDate(1)
val partition_date = stat_date.replace("-","")
//机构id
// val agency_id = sc.sql(
// s"""
// |SELECT DISTINCT(cl_id) as device_id
// |FROM online.ml_hospital_spam_pv_day
// |WHERE partition_date >= '20180402'
// |AND partition_date <= '20181203'
// |AND pv_ratio >= 0.95
// |UNION ALL
// |SELECT DISTINCT(cl_id) as device_id
// |FROM online.ml_hospital_spam_pv_month
// |WHERE partition_date >= '20171101'
// |AND partition_date <= '20181203'
// |AND pv_ratio >= 0.95
// """.stripMargin
// )
//// agency_id.show()
// agency_id.createOrReplaceTempView("agency_id")
val a = Array("answer_detail","article_detail","diary_detail","home_page","question_detail","search_content","search_diary")
for (i <- 0 until a.length){
val diary_pv = sc.sql(
s"""
|select partition_date,count(cl_id)
|from online.ml_community_exposure_detail
|where business_type ='diary'
|and partition_date >='20181120'
|and event='${a(i)}'
|GROUP BY partition_date
|order by partition_date
""".stripMargin
)
println("该来源的数据为:"+ a(i))
diary_pv.show()
}
// val diary_pv = sc.sql(
// s"""
// |select partition_date,count(cl_id)
// |from online.tl_hdfs_maidian_view
// |where action ='on_click_diary_card'
// |and params["page_name"]="home"
// |and params["tab_name"]="精选"
// |and partition_date >='20181120'
// |GROUP BY partition_date
// |order by partition_date
// """.stripMargin
// )
// diary_pv.show()
// GmeiConfig.writeToJDBCTable(view_count, "avg", SaveMode.Overwrite)
val agency_id = sc.sql(
s"""
|SELECT DISTINCT(cl_id) as device_id
|FROM online.ml_hospital_spam_pv_day
|WHERE partition_date >= '20180402'
|AND partition_date <= '20181203'
|AND pv_ratio >= 0.95
|UNION ALL
|SELECT DISTINCT(cl_id) as device_id
|FROM online.ml_hospital_spam_pv_month
|WHERE partition_date >= '20171101'
|AND partition_date <= '20181203'
|AND pv_ratio >= 0.95
""".stripMargin
)
// agency_id.show()
agency_id.createOrReplaceTempView("agency_id")
//日记本转化美购
//1.日记本到美购转化数
val diary_meigou_count = sc.sql(
s"""
|select '${stat_date}' as stat_date, count(page_name) as diary_meigou_count
|from online.bl_hdfs_page_view_updates ou left join agency_id
|on ou.cl_id = agency_id.device_id
|where ou.partition_date = '${partition_date}'
|and ou.page_name='welfare_detail'
|and ou.referrer='diary_detail'
|and agency_id.device_id is not null
|and ou.cl_id not in (select device_id from blacklist)
""".stripMargin
)
//2.日记本点击数
val diary_clk = sc.sql(
s"""
|select '${stat_date}' as stat_date,count(cl_id) as diary_clk
|from online.tl_hdfs_maidian_view ov left join agency_id
|on ov.cl_id = agency_id.device_id
|where ov.action = 'on_click_diary_card'
|and ov.cl_id != "NULL"
|and ov.partition_date='${partition_date}'
|and agency_id.device_id is not null
|and ov.cl_id not in (select device_id from blacklist)
""".stripMargin
)
//3.日记本曝光数
val diary_expoure=sc.sql(
s"""
|select '${stat_date}' as stat_date,count(cl_id) as diary_expoure
|from online.ml_community_exposure_detail od left join agency_id
|on od.cl_id = agency_id.device_id
|where od.business_type = "diary"
|and od.cl_id != "NULL"
|and od.partition_date='${partition_date}'
|and agency_id.device_id is not null
|and od.cl_id not in (select device_id from blacklist)
""".stripMargin
)
//4.搜索次数统计
val search_count = sc.sql(
s"""
|select '${stat_date}' as stat_date,count(params['query']) as search_num
|from online.tl_hdfs_maidian_view ov left join agency_id
|on ov.cl_id = agency_id.device_id
|where (ov.action = 'do_search' or ov.action = 'search_result_click_search')
|and ov.partition_date ='${partition_date}'
|and agency_id.device_id is not null
|and ov.cl_id not in (select device_id from blacklist)
""".stripMargin
)
//5.登录人数
val log_num = sc.sql(
s"""
|select '${stat_date}' as stat_date,count(distinct(device_id)) as log_num
|from data_feed_exposure oe left join agency_id
|on oe.device_id = agency_id.device_id
|and oe.stat_date ='${stat_date}'
|and agency_id.device_id is not null
|and oe.device_id not in (select device_id from blacklist)
""".stripMargin
)
val result = diary_meigou_count.join(diary_clk,"stat_date")
.join(diary_expoure,"stat_date")
.join(search_count,"stat_date")
.join(log_num,"stat_date")
GmeiConfig.writeToJDBCTable(result, "diary_meigou_crv", SaveMode.Overwrite)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment