Commit 86a48c9b authored by 高雅喆's avatar 高雅喆

Merge branch 'master' of git.wanmeizhensuo.com:ML/ffm-baseline

parents 87cd5a0c 6ed04285
...@@ -615,98 +615,118 @@ object smart_rank_count { ...@@ -615,98 +615,118 @@ object smart_rank_count {
final_id.createOrReplaceTempView("final_id") final_id.createOrReplaceTempView("final_id")
// val user_city_meigou_view = sc.sql( val user_city_meigou_view = sc.sql(
// s""" s"""
// |select cl_id as device_id,city_id as device_city,params['business_id'] as meigou_id |select ov.cl_id as device_id,ov.city_id as device_city,ov.params['business_id'] as meigou_id
// |from online.tl_hdfs_maidian_view |from online.tl_hdfs_maidian_view ov left join final_id
// |where action = "page_view" |on ov.cl_id = final_id.device_id
// |and params['page_name']="welfare_detail" |where ov.action = "page_view"
// |and partition_date >='20181201' |and ov.params['page_name']="welfare_detail"
// |and city_id is not null |and ov.partition_date >='20180301'
// """.stripMargin |and ov.partition_date <'20180401'
// ) |and ov.city_id is not null
// user_city_meigou_view.createOrReplaceTempView("user_city_meigou_view") |and final_id.device_id is null
// """.stripMargin
// val meigou_city = sc.sql( )
// s""" user_city_meigou_view.createOrReplaceTempView("user_city_meigou_view")
// |select b.id as meigou_id,d.city_id as meigou_city
// |from online.tl_meigou_service_view b
// |left join online.tl_hdfs_doctor_view c on b.doctor_id=c.id
// |left join online.tl_hdfs_hospital_view d on c.hospital_id=d.id
// |where b.partition_date='20181227'
// |and c.partition_date='20181227'
// |and d.partition_date='20181227'
// """.stripMargin
// )
// meigou_city.createOrReplaceTempView("meigou_city")
//
//
// val meigou_pv_tongcheng = sc.sql(
// s"""
// |select a.device_id,a.device_city,a.meigou_id,b.meigou_city
// |from user_city_meigou_view a
// |left join meigou_city b
// |on a.meigou_id=b.meigou_id
// """.stripMargin
// )
// meigou_pv_tongcheng.createOrReplaceTempView("meigou_pv_tongcheng")
//
// val meigou_pv_count = sc.sql(
// s"""
// |select meigou_city,count(device_id) as meigou_pv,count(distinct(device_id)) as meigou_device_num
// |from meigou_pv_tongcheng
// |where device_city=meigou_city
// |group by meigou_city
// """.stripMargin
// )
// meigou_pv_count.show()
//
//
////开始计算咨询
// val zixun_meigou_view = sc.sql(
// s"""
// |select cl_id as device_id,city_id as device_city,params['service_id'] as meigou_id
// |from online.tl_hdfs_maidian_view
// |where partition_date >= '20181201'
// |and action = 'welfare_detail_click_message'
// """.stripMargin
// )
// zixun_meigou_view.createOrReplaceTempView("zixun_meigou_view")
//
// val zixun_meigou_tongcheng = sc.sql(
// s"""
// |select a.device_id,a.device_city,a.meigou_id,b.meigou_city
// |from zixun_meigou_view a
// |left join meigou_city b
// |on a.meigou_id=b.meigou_id
// """.stripMargin
// )
// zixun_meigou_tongcheng.createOrReplaceTempView("zixun_meigou_tongcheng")
//
// val zixun_pv_count = sc.sql(
// s"""
// |select meigou_city,count(device_id) as meigou_zixun,count(distinct(device_id)) as meigou_zixun_device_num
// |from zixun_meigou_tongcheng
// |where device_city=meigou_city
// |group by meigou_city
// """.stripMargin
// )
// zixun_pv_count.show()
val meigou_city = sc.sql(
s"""
|select b.id as meigou_id,d.city_id as meigou_city
|from online.tl_meigou_service_view b
|left join online.tl_hdfs_doctor_view c on b.doctor_id=c.id
|left join online.tl_hdfs_hospital_view d on c.hospital_id=d.id
|where b.partition_date='20181227'
|and c.partition_date='20181227'
|and d.partition_date='20181227'
""".stripMargin
)
meigou_city.createOrReplaceTempView("meigou_city")
val meigou_pv_tongcheng = sc.sql(
s"""
|select a.device_id,a.device_city,a.meigou_id,b.meigou_city
|from user_city_meigou_view a
|left join meigou_city b
|on a.meigou_id = b.meigou_id
""".stripMargin
)
meigou_pv_tongcheng.createOrReplaceTempView("meigou_pv_tongcheng")
val meigou_pv_count = sc.sql(
s"""
|select '2018-03' as stat_date,meigou_city,count(device_id) as meigou_pv,count(distinct(device_id)) as meigou_device_num
|from meigou_pv_tongcheng
|where device_city = meigou_city
|group by meigou_city
""".stripMargin
)
meigou_pv_count.createOrReplaceTempView("meigou_pv_count")
//开始计算咨询
val zixun_meigou_view = sc.sql(
s"""
|select ov.cl_id as device_id,ov.city_id as device_city,ov.params['service_id'] as meigou_id
|from online.tl_hdfs_maidian_view ov left join final_id
|on ov.cl_id = final_id.device_id
|where ov.partition_date >= '20180301'
|and ov.partition_date <'20180401'
|and ov.action = 'welfare_detail_click_message'
|and final_id.device_id is null
""".stripMargin
)
zixun_meigou_view.createOrReplaceTempView("zixun_meigou_view")
val zixun_meigou_tongcheng = sc.sql(
s"""
|select a.device_id,a.device_city,a.meigou_id,b.meigou_city
|from zixun_meigou_view a
|left join meigou_city b
|on a.meigou_id=b.meigou_id
""".stripMargin
)
zixun_meigou_tongcheng.createOrReplaceTempView("zixun_meigou_tongcheng")
val zixun_pv_count = sc.sql(
s"""
|select '2018-03' as stat_date,meigou_city,count(device_id) as meigou_zixun,count(distinct(device_id)) as meigou_zixun_device_num
|from zixun_meigou_tongcheng
|where device_city=meigou_city
|group by meigou_city
""".stripMargin
)
zixun_pv_count.createOrReplaceTempView("zixun_pv_count")
//开始计算每个地区每月新增设备 //开始计算每个地区每月新增设备
val device_new_count = sc.sql( val device_new_count = sc.sql(
s""" s"""
|select first_city,count(distinct(device_id)) |select first_city,count(distinct(device_id)) as new_device_month
|from online.ml_device_day_active_status |from online.ml_device_day_active_status
|where active_type != '4' |where active_type != '4'
|and partition_date >='20181201' |and partition_date >='20180301'
|and partition_date <'20180401'
|group by first_city |group by first_city
""".stripMargin """.stripMargin
) )
device_new_count.show() device_new_count.createOrReplaceTempView("device_new_count")
//将所有的数据综合一起
val all_count = sc.sql(
s"""
|select mc.stat_date,mc.meigou_city,mc.meigou_pv,mc.meigou_device_num,zc.meigou_zixun,zc.meigou_zixun_device_num,dc.new_device_month
|from meigou_pv_count mc
|left join zixun_pv_count zc on mc.meigou_city = zc.meigou_city
|left join device_new_count dc on dc.first_city=mc.meigou_city
""".stripMargin
)
all_count.show()
GmeiConfig.writeToJDBCTable(all_count, "smart_rank_count", SaveMode.Append)
......
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