getClickZeroUidDetail.py 4.5 KB
Newer Older
1 2
import datetime
import pymysql
高雅喆's avatar
高雅喆 committed
3
from utils import get_yesterday_date
4 5


高雅喆's avatar
高雅喆 committed
6 7 8 9 10 11 12 13 14 15 16

#一周之前的date(7)
my_date1 = (datetime.date.today() - datetime.timedelta(days=7)).strftime("%Y-%m-%d")
#二周之前的date(14)
my_date2 = (datetime.date.today() - datetime.timedelta(days=14)).strftime("%Y-%m-%d")
#一个月之前的date(30)
my_date3 = (datetime.date.today() - datetime.timedelta(days=30)).strftime("%Y-%m-%d")
#两个月之前的date(60)
my_date4 = (datetime.date.today() - datetime.timedelta(days=60)).strftime("%Y-%m-%d")
#三个月之前的date(90)
my_date5 = (datetime.date.today() - datetime.timedelta(days=90)).strftime("%Y-%m-%d")
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31


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
32
	sql = "select '0-7' as label,count(distinct(device_id)) from data_feed_exposure \
33
	where device_type{0} \
高雅喆's avatar
高雅喆 committed
34
	and stat_date = '{7}' \
35
	and device_id not in \
高雅喆's avatar
高雅喆 committed
36
	(select distinct(device_id) from data_feed_click \
高雅喆's avatar
高雅喆 committed
37
	where stat_date = '{7}' \
38 39 40
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
41
	from data_feed_exposure \
42
	where device_id not in \
高雅喆's avatar
高雅喆 committed
43
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
44
		where stat_date < {2})) \
45
	union all \
高雅喆's avatar
高雅喆 committed
46
	select '7-14' as label,count(distinct(device_id)) from data_feed_exposure \
47
	where device_type{0} \
高雅喆's avatar
高雅喆 committed
48
	and stat_date = '{7}' \
49
	and device_id not in \
高雅喆's avatar
高雅喆 committed
50
	(select distinct(device_id) from data_feed_click \
高雅喆's avatar
高雅喆 committed
51
	where stat_date = '{7}' \
52 53 54
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
55
	from data_feed_exposure \
56
	where device_id not in \
高雅喆's avatar
高雅喆 committed
57
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
58
		where stat_date < {3}) \
59
	and device_id in \
高雅喆's avatar
高雅喆 committed
60
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
61
		where stat_date < {2})) \
62
	union all \
高雅喆's avatar
高雅喆 committed
63
	select '14-30' as label,count(distinct(device_id)) from data_feed_exposure \
64
	where device_type{0} \
高雅喆's avatar
高雅喆 committed
65
	and stat_date = '{7}' \
66
	and device_id not in \
高雅喆's avatar
高雅喆 committed
67
	(select distinct(device_id) from data_feed_click \
高雅喆's avatar
高雅喆 committed
68
	where stat_date = '{7}' \
69 70 71
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
72
	from data_feed_exposure \
73
	where device_id not in \
高雅喆's avatar
高雅喆 committed
74
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
75
		where stat_date < {4}) \
76
	and device_id in \
高雅喆's avatar
高雅喆 committed
77
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
78
		where stat_date < {3})) \
79
	union all \
高雅喆's avatar
高雅喆 committed
80
	select '30-60' as label,count(distinct(device_id)) from data_feed_exposure \
81
	where device_type{0} \
高雅喆's avatar
高雅喆 committed
82
	and stat_date = '{7}' \
83
	and device_id not in \
高雅喆's avatar
高雅喆 committed
84
	(select distinct(device_id) from data_feed_click \
高雅喆's avatar
高雅喆 committed
85
	where stat_date = '{7}' \
86 87 88
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
89
	from data_feed_exposure \
90
	where device_id not in \
高雅喆's avatar
高雅喆 committed
91
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
92
		where stat_date < {5}) \
93
	and device_id in \
高雅喆's avatar
高雅喆 committed
94
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
95
		where stat_date < {4})) \
96
	union all \
高雅喆's avatar
高雅喆 committed
97
	select '60-90' as label,count(distinct(device_id)) from data_feed_exposure \
98
	where device_type{0} \
高雅喆's avatar
高雅喆 committed
99
	and stat_date = '{7}' \
100
	and device_id not in \
高雅喆's avatar
高雅喆 committed
101
	(select distinct(device_id) from data_feed_click \
高雅喆's avatar
高雅喆 committed
102
	where stat_date = '{7}' \
103 104 105
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
106
	from data_feed_exposure \
107
	where device_id not in \
高雅喆's avatar
高雅喆 committed
108
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
109
		where stat_date < {6}) \
110
	and device_id in \
高雅喆's avatar
高雅喆 committed
111
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
112
		where stat_date < {5})) \
113
	union all \
高雅喆's avatar
高雅喆 committed
114
	select '90+' as label,count(distinct(device_id)) from data_feed_exposure \
115
	where device_type{0} \
高雅喆's avatar
高雅喆 committed
116
	and stat_date = '{7}' \
117
	and device_id not in \
高雅喆's avatar
高雅喆 committed
118
	(select distinct(device_id) from data_feed_click \
高雅喆's avatar
高雅喆 committed
119
	where stat_date = '{7}' \
120 121 122
		and device_type{1}) \
	and device_id in \
	(select distinct(device_id) \
高雅喆's avatar
高雅喆 committed
123
	from data_feed_exposure \
124
	where device_id in \
高雅喆's avatar
高雅喆 committed
125
	(select distinct(device_id) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
126
		where stat_date < {6}))".format(platform,platform.replace(' ','') if platform[-2]=='e' else platform,my_date1,my_date2,my_date3,my_date4,my_date5,get_yesterday_date())
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
	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")