(select device_id from online.ml_device_day_active_status where partition_date = '{today_str}' and active_type in (1,2)) t2
LEFT JOIN
(
select distinct device_id
from ml.ml_d_ct_dv_devicespam_d --去除机构刷单设备,即作弊设备(浏览和曝光事件去除)
WHERE partition_day='{today_str}'
union all
select distinct device_id
from dim.dim_device_user_staff --去除内网用户
)spam_pv
on spam_pv.device_id=t2.device_id
LEFT JOIN
(
SELECT partition_date,device_id
FROM
(--找出user_id当天活跃的第一个设备id
SELECT user_id,partition_date,
if(size(device_list) > 0, device_list [ 0 ], '') AS device_id
FROM online.ml_user_updates
WHERE partition_date='{today_str}'
)t1
JOIN
( --医生账号
SELECT distinct user_id
FROM online.tl_hdfs_doctor_view
WHERE partition_date = '{today_str}'
--马甲账号/模特用户
UNION ALL
SELECT user_id
FROM ml.ml_c_ct_ui_user_dimen_d
WHERE partition_day = '{today_str}'
AND (is_puppet = 'true' or is_classifyuser = 'true')
UNION ALL
--公司内网覆盖用户
select distinct user_id
from dim.dim_device_user_staff
UNION ALL
--登陆过医生设备
SELECT distinct t1.user_id
FROM
FROM
(
(
SELECT partition_date,
SELECT user_id, v.device_id as device_id
cl_id,
FROM online.ml_user_history_detail
case when params['card_content_type'] in ('qa','answer') then 'qa'
LATERAL VIEW EXPLODE(device_history_list) v AS device_id
when params['card_content_type'] in ('special_pool') then 'special' else params['card_content_type'] end as card_content_type,
WHERE partition_date = '{today_str}'
CASE when params['transaction_type'] in ('fmctr','samecity_fmctr') then array('fmctr','合计')
) t1
when params['transaction_type'] in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
JOIN
WHEN (params['transaction_type'] like '%ctr' and params['transaction_type'] not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计')
(
when params['transaction_type'] in ('high_quality_ctr') then array('high_quality_ctr','合计')
SELECT device_id
WHEN params['transaction_type'] like '%cvr' THEN array('cvr预估','合计')
FROM online.ml_device_history_detail
WHEN params['transaction_type'] in ('-1','smr') THEN array('smr','合计')
WHERE partition_date = '{today_str}'
when params['transaction_type'] in ('pgc','hotspot') then array('热点卡片')
AND is_login_doctor = '1'
when params['transaction_type'] in ('newdata') then array('保量卡片')
) t2
when params['transaction_type'] in ('hotspot_feed') then array('hotspot_feed','合计')
ON t1.device_id = t2.device_id
when params['transaction_type'] in ('aistragegy') then array('新用户AI帖优先','合计')
)t2
when params['transaction_type'] in ('excestragegy') then array('新用户精华帖优先','合计')
on t1.user_id=t2.user_id
when params['transaction_type'] in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
group by partition_date,device_id
when params['transaction_type'] in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
)dev
when params['transaction_type'] like 'deeplink%' then array('deeplink策略','合计')
AND (params['transaction_type'] in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO')
sql_res=new_urser_device_id_df.collect()
or params['transaction_type'] like '%ctr' or params['transaction_type'] like '%cvr' or params['transaction_type'] like 'deeplink%')
res_dict={}
AND params['card_content_type'] in ('qa','diary','user_post','answer','special_pool')
portrait_dict={
GROUP BY partition_date,
"first_demands":{},
cl_id,
"second_demands":{},
case when params['card_content_type'] in ('qa','answer') then 'qa'
"first_solutions":{},
when params['card_content_type'] in ('special_pool') then 'special' else params['card_content_type'] end,
"second_solutions":{},
CASE when params['transaction_type'] in ('fmctr','samecity_fmctr') then array('fmctr','合计')
"first_positions":{},
when params['transaction_type'] in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
"second_positions":{},
WHEN (params['transaction_type'] like '%ctr' and params['transaction_type'] not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计')
"projects":{},
when params['transaction_type'] in ('high_quality_ctr') then array('high_quality_ctr','合计')
'anecdote_tags':{}
WHEN params['transaction_type'] like '%cvr' THEN array('cvr预估','合计')
}
WHEN params['transaction_type'] in ('-1','smr') THEN array('smr','合计')
no_portrait_device_id_list=[]
when params['transaction_type'] in ('pgc','hotspot') then array('热点卡片')
print("-------------------------------")
when params['transaction_type'] in ('newdata') then array('保量卡片')
count_not_has_portratit=0
when params['transaction_type'] in ('hotspot_feed') then array('hotspot_feed','合计')
when params['transaction_type'] in ('aistragegy') then array('新用户AI帖优先','合计')
forcount_user_count,resinenumerate(sql_res):
when params['transaction_type'] in ('excestragegy') then array('新用户精华帖优先','合计')
# print(count, res)
when params['transaction_type'] in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
when params['transaction_type'] in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
when params['transaction_type'] like 'deeplink%' then array('deeplink策略','合计') end,
# print(count_user_count, res, portratit_res)
params['card_id'],
temp_count=0
app_session_id
fordemandinportratit_res:
)a
ifportratit_res[demand]:
LATERAL VIEW explode (a.recommend_type) v as recommend_type
try:
group by partition_date,card_content_type,cl_id,v.recommend_type,card_id having session_pv0 >0
fortaginportratit_res[demand][0:3]:
iftaginportrait_dict[demand]:
UNION
portrait_dict[demand][tag]+=1
SELECT partition_date,
else:
cl_id,
portrait_dict[demand][tag]=1
count(distinct card_id) as session_pv0
exceptExceptionase:
FROM
print("error ",e)
(SELECT partition_date,
cl_id,
temp_count+=1
case when card_content_type in ('qa','answer') then 'qa'
ifnottemp_count:
when card_content_type in ('special_pool') then 'special' else card_content_type end as card_content_type,
count_not_has_portratit+=1
CASE when transaction_type in ('fmctr','samecity_fmctr') then array('fmctr','合计')
no_portrait_device_id_list.append(res.device_id)
when transaction_type in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
WHEN (transaction_type like '%ctr' and transaction_type not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr') ) THEN array('ctr预估','合计')
print(portrait_dict)
when transaction_type in ('high_quality_ctr') then array('high_quality_ctr','合计')
print(count_user_count+1,count_not_has_portratit)
WHEN transaction_type like '%cvr' THEN array('cvr预估','合计')
print("-------------------------------")
WHEN transaction_type in ('-1','smr') THEN array('smr','合计')
when transaction_type in ('pgc','hotspot') then array('热点卡片')
when transaction_type in ('newdata') then array('保量卡片')
forprotratit_typeinportrait_dict["projects"]:
when transaction_type in ('hotspot_feed') then array('hotspot_feed','合计')
partition_date=today_str
when transaction_type in ('aistragegy') then array('新用户AI帖优先','合计')
AND (transaction_type in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO')
db.commit()
or transaction_type like '%ctr' or transaction_type like '%cvr' or transaction_type like 'deeplink%')
print(res)
AND card_content_type in ('qa','diary','user_post','answer','special_pool')
group by partition_date,
# cursor.executemany()
case when card_content_type in ('qa','answer') then 'qa'
db.close()
when card_content_type in ('special_pool') then 'special' else card_content_type end,
cl_id,
CASE when transaction_type in ('fmctr','samecity_fmctr') then array('fmctr','合计')
when transaction_type in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
WHEN (transaction_type like '%ctr' and transaction_type not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计')
when transaction_type in ('high_quality_ctr') then array('high_quality_ctr','合计')
WHEN transaction_type like '%cvr' THEN array('cvr预估','合计')
WHEN transaction_type in ('-1','smr') THEN array('smr','合计')
when transaction_type in ('pgc','hotspot') then array('热点卡片')
when transaction_type in ('newdata') then array('保量卡片')
when transaction_type in ('hotspot_feed') then array('hotspot_feed','合计')
when transaction_type in ('aistragegy') then array('新用户AI帖优先','合计')
when transaction_type in ('excestragegy') then array('新用户精华帖优先','合计')
when transaction_type in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
when transaction_type in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
when transaction_type like 'deeplink%' then array('deeplink策略','合计') end,
card_id,
app_session_id
)a
LATERAL VIEW explode (a.recommend_type) v as recommend_type
group by partition_date,cl_id having session_pv0 >= 4