ndays : 1;2;3;4.. #The number of days from the current time
platform : 'all';'ios';'android'
rtype : list
"""
ifplatform=="ios":
platform="='App Store'"
elifplatform=="android":
platform="!='App Store'"
else:
platform=" is not null"
sql_clk="select count(device_id) from data_feed_click \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -{0} day) \
and device_type{1}".format(ndays,platform.replace(' ',''))
clk_count=con_sql(sql_clk)[0][0]
sql_imp="select count(device_id) from data_feed_exposure \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -{0} day) \
and device_id in \
(select device_id from data_feed_click \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -{1} day) \
and device_type{2}) \
and device_type{3}".format(ndays,ndays,platform.replace(' ',''),platform)
imp_count=con_sql(sql_imp)[0][0]
clk_rate=round(clk_count/imp_count,4)
ifplatform=="='App Store'":
platform="苹果"
elifplatform=="!='App Store'":
platform="安卓"
else:
platform="所有"
return[platform,clk_count,imp_count,clk_rate]
#获取 {点击次数 : 独立用户数}
defget_click_times_to_count_uid_df():
"""
rtype : pandas.DataFrame
"""
sql="select device_id,count(cid_type) click_times from data_feed_click where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) group by device_id order by click_times desc"