getClickZeroUidDetail.py 5.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import datetime
import pymysql


#一周之前的timestamp(7)
my_date1 = datetime.date.today() - datetime.timedelta(days=7)
my_tm1 = int(my_date1.strftime("%s"))
#二周之前的timestamp(14)
my_date2 = datetime.date.today() - datetime.timedelta(days=14)
my_tm2 = int(my_date2.strftime("%s"))
#一个月之前的timestamp(30)
my_date3 = datetime.date.today() - datetime.timedelta(days=30)
my_tm3 = int(my_date3.strftime("%s"))
#两个月之前的timestamp(60)
my_date4 = datetime.date.today() - datetime.timedelta(days=60)
my_tm4 = int(my_date4.strftime("%s"))
#三个月之前的timestamp(90)
my_date5 = datetime.date.today() - datetime.timedelta(days=90)
my_tm5 = int(my_date5.strftime("%s"))


def get_click_zero_uid_count(platform):
	"""
	platform : "ios","android","all"
	rtype : dict
	"""
	if platform == "ios":
		platform = "='App Store'"
	elif platform == "android":
		platform = "!='App Store'"
	else:
		platform = " is not null"
	db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test')
	cursor = db.cursor()
高雅喆's avatar
高雅喆 committed
35
	sql = "select '0-7' as label,count(distinct(device_id)) from data_feed_exposure2 \
36 37 38
	where device_type{0} \
	and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
	and device_id not in \
高雅喆's avatar
高雅喆 committed
39
	(select distinct(device_id) from data_feed_click2 \
40 41 42 43
	where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
44
	from data_feed_exposure2 \
45
	where device_id not in \
高雅喆's avatar
高雅喆 committed
46
	(select distinct(device_id) from data_feed_exposure2 \
47 48
		where time < {2})) \
	union all \
高雅喆's avatar
高雅喆 committed
49
	select '7-14' as label,count(distinct(device_id)) from data_feed_exposure2 \
50 51 52
	where device_type{0} \
	and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
	and device_id not in \
高雅喆's avatar
高雅喆 committed
53
	(select distinct(device_id) from data_feed_click2 \
54 55 56 57
	where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
58
	from data_feed_exposure2 \
59
	where device_id not in \
高雅喆's avatar
高雅喆 committed
60
	(select distinct(device_id) from data_feed_exposure2 \
61 62
		where time < {3}) \
	and device_id in \
高雅喆's avatar
高雅喆 committed
63
	(select distinct(device_id) from data_feed_exposure2 \
64 65
		where time < {2})) \
	union all \
高雅喆's avatar
高雅喆 committed
66
	select '14-30' as label,count(distinct(device_id)) from data_feed_exposure2 \
67 68 69
	where device_type{0} \
	and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
	and device_id not in \
高雅喆's avatar
高雅喆 committed
70
	(select distinct(device_id) from data_feed_click2 \
71 72 73 74
	where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
75
	from data_feed_exposure2 \
76
	where device_id not in \
高雅喆's avatar
高雅喆 committed
77
	(select distinct(device_id) from data_feed_exposure2 \
78 79
		where time < {4}) \
	and device_id in \
高雅喆's avatar
高雅喆 committed
80
	(select distinct(device_id) from data_feed_exposure2 \
81 82
		where time < {3})) \
	union all \
高雅喆's avatar
高雅喆 committed
83
	select '30-60' as label,count(distinct(device_id)) from data_feed_exposure2 \
84 85 86
	where device_type{0} \
	and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
	and device_id not in \
高雅喆's avatar
高雅喆 committed
87
	(select distinct(device_id) from data_feed_click2 \
88 89 90 91
	where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
92
	from data_feed_exposure2 \
93
	where device_id not in \
高雅喆's avatar
高雅喆 committed
94
	(select distinct(device_id) from data_feed_exposure2 \
95 96
		where time < {5}) \
	and device_id in \
高雅喆's avatar
高雅喆 committed
97
	(select distinct(device_id) from data_feed_exposure2 \
98 99
		where time < {4})) \
	union all \
高雅喆's avatar
高雅喆 committed
100
	select '60-90' as label,count(distinct(device_id)) from data_feed_exposure2 \
101 102 103
	where device_type{0} \
	and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
	and device_id not in \
高雅喆's avatar
高雅喆 committed
104
	(select distinct(device_id) from data_feed_click2 \
105 106 107 108
	where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
109
	from data_feed_exposure2 \
110
	where device_id not in \
高雅喆's avatar
高雅喆 committed
111
	(select distinct(device_id) from data_feed_exposure2 \
112 113
		where time < {6}) \
	and device_id in \
高雅喆's avatar
高雅喆 committed
114
	(select distinct(device_id) from data_feed_exposure2 \
115 116
		where time < {5})) \
	union all \
高雅喆's avatar
高雅喆 committed
117
	select '90+' as label,count(distinct(device_id)) from data_feed_exposure2 \
118 119 120
	where device_type{0} \
	and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
	and device_id not in \
高雅喆's avatar
高雅喆 committed
121
	(select distinct(device_id) from data_feed_click2 \
122 123 124 125
	where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
126
	from data_feed_exposure2 \
127
	where device_id in \
高雅喆's avatar
高雅喆 committed
128
	(select distinct(device_id) from data_feed_exposure2 \
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
		where time < {6}))".format(platform,platform.replace(' ','') if platform[-2]=='e' else platform,my_tm1,my_tm2,my_tm3,my_tm4,my_tm5)
	cursor.execute(sql)
	result = cursor.fetchall()
	db.close()
	dct = {}
	for i in result:
		dct[i[0]] = i[1]
	return dct

	
if __name__ == '__main__':
	no_click_uid_detail_all = get_click_zero_uid_count("all")
	no_click_uid_detail_ios = get_click_zero_uid_count("ios")
	no_click_uid_detail_android = get_click_zero_uid_count("android")