cidRate.py 2.17 KB
Newer Older
1
# -*- coding: UTF-8 -*-
2
from utils import con_sql,get_yesterday_date
3 4 5 6



class CidRate(object):
7
	def __init__(self, platform, cid_type):
8 9 10 11 12
		"""
		platform : 'all';'ios';'android'
		cid_type : 'diary';'answer';'question'...
		"""
		if platform == "ios":
13
			self.platform = "='App Store'"
14
		elif platform == "android":
15
			self.platform = "!='App Store'"
16 17 18 19 20 21 22 23 24
		else:
			self.platform = " is not null"
		self.cid_type = cid_type

	def get_cid_clk_rate(self, platform):
		"""
		platform : "所有";"苹果","安卓"   #方便显示
		rtype : list
		"""
高雅喆's avatar
高雅喆 committed
25
		sql_cid = "select count(cid) from data_feed_click \
高雅喆's avatar
高雅喆 committed
26
		where stat_date = '{0}' \
27
		and device_type{1} \
28
		and cid_type='{2}'".format(get_yesterday_date(),self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform,self.cid_type)
29
		cid_clk_count = con_sql(sql_cid)[0][0]
高雅喆's avatar
高雅喆 committed
30
		sql_all = "select count(cid) from data_feed_click \
高雅喆's avatar
高雅喆 committed
31
		where stat_date = '{0}' \
32
		and device_type{1}".format(get_yesterday_date(), self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform)
33 34 35 36 37 38 39 40 41 42
		all_clk_count = con_sql(sql_all)[0][0]
		cid_clk_rate = round(cid_clk_count/all_clk_count,4)
		return [platform,cid_clk_count,all_clk_count,cid_clk_rate]


	def get_cid_imp_rate(self, platform):
		"""
		platform : "所有";"苹果","安卓"   #方便显示
		rtype : list
		"""
高雅喆's avatar
高雅喆 committed
43
		sql_cid = "select count(cid) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
44
		where stat_date = '{0}' \
45
		and device_type{1} and cid_type='{2}'".format(get_yesterday_date(),self.platform,self.cid_type)
46
		cid_imp_count = con_sql(sql_cid)[0][0]
高雅喆's avatar
高雅喆 committed
47
		sql_all = "select count(cid) from data_feed_exposure \
高雅喆's avatar
高雅喆 committed
48
		where stat_date = '{0}' \
49
		and device_type{1}".format(get_yesterday_date(), self.platform)
50 51 52 53 54 55 56
		all_imp_count = con_sql(sql_all)[0][0]
		cid_imp_rate = round(cid_imp_count/all_imp_count,4)
		return [platform,cid_imp_count,all_imp_count,cid_imp_rate]
		


def main():
高雅喆's avatar
高雅喆 committed
57 58 59 60
	answer_imp_rate_all = CidRate("all","answer").get_cid_imp_rate("所有")
	answer_imp_rate_ios = CidRate("ios","answer").get_cid_imp_rate("苹果")
	answer_imp_rate_android = CidRate("android","answer").get_cid_imp_rate("安卓")
	answer_imp_rate_result = [answer_imp_rate_all,answer_imp_rate_ios,answer_imp_rate_android]
61 62 63 64 65


if __name__ == '__main__':
	main()