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"))
def get_rate_detail(platform):
if platform == "ios":
self.platform = "='App Store'"
platform = "='App Store'"
elif platform == "android":
self.platform = "!='App Store'"
platform = "!='App Store'"
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')
cursor = db.cursor()
sql_tmp = "create temporary table if not exists tmp_table as \
(select distinct(device_id) from data_feed_exposure \
sql = "select count(distinct(device_id)) from data_feed_exposure \
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}))".format(platform,platform.replace(' ','') if platform[-2]=='e' else platform)
sql_last = "select count(distinct(device_id)) from tmp_table\
where device_id in \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure \
where device_id not in \
(select distinct(device_id) from data_feed_exposure \
where time < {0})) \
where time < {2})) \
union \
select count(distinct(device_id)) from tmp_table\
where device_id in \
select count(distinct(device_id)) from data_feed_exposure \
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) \
from data_feed_exposure \
where device_id not in \
(select distinct(device_id) from data_feed_exposure \
where time < {1}) \
where time < {3}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure \
where time < {0})) \
where time < {2})) \
union \
select count(distinct(device_id)) from tmp_table\
where device_id in \
select count(distinct(device_id)) from data_feed_exposure \
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) \
from data_feed_exposure \
where device_id not in \
(select distinct(device_id) from data_feed_exposure \
where time < {2}) \
where time < {4}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure \
where time < {1})) \
where time < {3})) \
union \
select count(distinct(device_id)) from tmp_table\
where device_id in \
select count(distinct(device_id)) from data_feed_exposure \
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) \
from data_feed_exposure \
where device_id not in \
(select distinct(device_id) from data_feed_exposure \
where time < {3}) \
where time < {5}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure \
where time < {2})) \
where time < {4})) \
union \
select count(distinct(device_id)) from tmp_table\
where device_id in \
select count(distinct(device_id)) from data_feed_exposure \
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) \
from data_feed_exposure \
where device_id not in \
(select distinct(device_id) from data_feed_exposure \
where time < {4}) \
where time < {6}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure \
where time < {3})) \
where time < {5})) \
union \
select count(distinct(device_id)) from tmp_table\
where device_id in \
select count(distinct(device_id)) from data_feed_exposure \
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) \
from data_feed_exposure \
where device_id in \
(select distinct(device_id) from data_feed_exposure \
where time < {4}))".format(my_tm1,my_tm2,my_tm3,my_tm4,my_tm5)
cursor.execute(sql_tmp)
cursor.execute(sql_last)
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()
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