Commit 644d1782 authored by 高雅喆's avatar 高雅喆

add getClickZeroUidRateDetail.py and getDiaryImpRate.py

parent ad1aeb83
...@@ -21,82 +21,109 @@ my_tm5 = int(my_date5.strftime("%s")) ...@@ -21,82 +21,109 @@ my_tm5 = int(my_date5.strftime("%s"))
def get_rate_detail(platform): def get_rate_detail(platform):
if platform == "ios": if platform == "ios":
self.platform = "='App Store'" platform = "='App Store'"
elif platform == "android": elif platform == "android":
self.platform = "!='App Store'" platform = "!='App Store'"
else: else:
self.platform = " is not null" platform = " is not null"
db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test') db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test')
cursor = db.cursor() cursor = db.cursor()
sql_tmp = "create temporary table if not exists tmp_table as \ sql = "select count(distinct(device_id)) from data_feed_exposure \
(select distinct(device_id) from data_feed_exposure \
where device_type{0} \ where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \ and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_id not in \ and device_id not in \
(select distinct(device_id) from data_feed_click \ (select distinct(device_id) from data_feed_click \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \ where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_type{1}))".format(platform,platform.replace(' ','') if platform[-2]=='e' else platform) and device_type{1}) \
sql_last = "select count(distinct(device_id)) from tmp_table\ and device_id in \
where device_id in \
(select distinct(device_id) \ (select distinct(device_id) \
from data_feed_exposure \ from data_feed_exposure \
where device_id not in \ where device_id not in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {0})) \ where time < {2})) \
union \ union \
select count(distinct(device_id)) from tmp_table\ select count(distinct(device_id)) from data_feed_exposure \
where device_id in \ where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_id not in \
(select distinct(device_id) from data_feed_click \
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) \ (select distinct(device_id) \
from data_feed_exposure \ from data_feed_exposure \
where device_id not in \ where device_id not in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {1}) \ where time < {3}) \
and device_id in \ and device_id in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {0})) \ where time < {2})) \
union \ union \
select count(distinct(device_id)) from tmp_table\ select count(distinct(device_id)) from data_feed_exposure \
where device_id in \ where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_id not in \
(select distinct(device_id) from data_feed_click \
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) \ (select distinct(device_id) \
from data_feed_exposure \ from data_feed_exposure \
where device_id not in \ where device_id not in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {2}) \ where time < {4}) \
and device_id in \ and device_id in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {1})) \ where time < {3})) \
union \ union \
select count(distinct(device_id)) from tmp_table\ select count(distinct(device_id)) from data_feed_exposure \
where device_id in \ where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_id not in \
(select distinct(device_id) from data_feed_click \
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) \ (select distinct(device_id) \
from data_feed_exposure \ from data_feed_exposure \
where device_id not in \ where device_id not in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {3}) \ where time < {5}) \
and device_id in \ and device_id in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {2})) \ where time < {4})) \
union \ union \
select count(distinct(device_id)) from tmp_table\ select count(distinct(device_id)) from data_feed_exposure \
where device_id in \ where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_id not in \
(select distinct(device_id) from data_feed_click \
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) \ (select distinct(device_id) \
from data_feed_exposure \ from data_feed_exposure \
where device_id not in \ where device_id not in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {4}) \ where time < {6}) \
and device_id in \ and device_id in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {3})) \ where time < {5})) \
union \ union \
select count(distinct(device_id)) from tmp_table\ select count(distinct(device_id)) from data_feed_exposure \
where device_id in \ where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and device_id not in \
(select distinct(device_id) from data_feed_click \
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) \ (select distinct(device_id) \
from data_feed_exposure \ from data_feed_exposure \
where device_id in \ where device_id in \
(select distinct(device_id) from data_feed_exposure \ (select distinct(device_id) from data_feed_exposure \
where time < {4}))".format(my_tm1,my_tm2,my_tm3,my_tm4,my_tm5) 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_tmp) cursor.execute(sql)
cursor.execute(sql_last)
result = cursor.fetchall() result = cursor.fetchall()
db.close() db.close()
return result return result
......
# -*- coding: UTF-8 -*-
import pymysql
def con_sql(sql):
# 从数据库的表里获取数据
db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test')
cursor = db.cursor()
cursor.execute(sql)
result = cursor.fetchall()
db.close()
return result
#1 获取所有平台的日记曝光占比
def get_all_diary_imp_rate():
sql = "select count(cid) from data_feed_exposure where cid_type='diary' and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day)"
diary_imp_count = con_sql(sql)
diary_imp_count = diary_imp_count[0][0]
sql = "select count(cid) from data_feed_exposure where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day)"
all_imp_count = con_sql(sql)
all_imp_count = all_imp_count[0][0]
all_diary_imp_rate = diary_imp_count / all_imp_count
return ["所有",diary_imp_count,all_imp_count,round(all_diary_imp_rate,4)]
#2 获取ios平台的日记曝光占比
def get_ios_diary_imp_rate():
sql = "select count(cid) from data_feed_exposure where cid_type='diary' and device_type='App Store' and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day)"
diary_imp_count = con_sql(sql)
diary_imp_count = diary_imp_count[0][0]
sql = "select count(cid) from data_feed_exposure where device_type='App Store' and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day)"
all_imp_count = con_sql(sql)
all_imp_count = all_imp_count[0][0]
ios_diary_imp_rate = diary_imp_count / all_imp_count
return ["苹果",diary_imp_count,all_imp_count,round(ios_diary_imp_rate,4)]
#3 获取安卓平台的日记曝光占比
def get_android_diary_imp_rate():
sql = "select count(cid) from data_feed_exposure where cid_type='diary' and device_type!='App Store' and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day)"
diary_imp_count = con_sql(sql)
diary_imp_count = diary_imp_count[0][0]
sql = "select count(cid) from data_feed_exposure where device_type!='App Store' and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day)"
all_imp_count = con_sql(sql)
all_imp_count = all_imp_count[0][0]
android_diary_imp_rate = diary_imp_count / all_imp_count
return ["安卓",diary_imp_count,all_imp_count,round(android_diary_imp_rate,4)]
if __name__ == "__main__":
all_diary_imp_rate = get_all_diary_imp_rate()
ios_diary_imp_rate = get_ios_diary_imp_rate()
android_diary_imp_rate = get_android_diary_imp_rate()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment