Commit ffd4b6c3 authored by 张彦钊's avatar 张彦钊

Merge branch 'master' of git.wanmeizhensuo.com:ML/ffm-baseline

增加python运行环境声明
parents 25e107e8 08c5d411
import datetime
import pymysql
from utils import get_yesterday_date
#一周之前的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"))
#一周之前的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")
def get_click_zero_uid_count(platform):
......@@ -34,99 +31,99 @@ def get_click_zero_uid_count(platform):
cursor = db.cursor()
sql = "select '0-7' as label,count(distinct(device_id)) from data_feed_exposure2 \
where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and stat_date = get_yesterday_date() \
and device_id not in \
(select distinct(device_id) from data_feed_click2 \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
where stat_date = get_yesterday_date() \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {2})) \
where stat_date < {2})) \
union all \
select '7-14' as label,count(distinct(device_id)) from data_feed_exposure2 \
where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and stat_date = get_yesterday_date() \
and device_id not in \
(select distinct(device_id) from data_feed_click2 \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
where stat_date = get_yesterday_date() \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {3}) \
where stat_date < {3}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {2})) \
where stat_date < {2})) \
union all \
select '14-30' as label,count(distinct(device_id)) from data_feed_exposure2 \
where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and stat_date = get_yesterday_date() \
and device_id not in \
(select distinct(device_id) from data_feed_click2 \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
where stat_date = get_yesterday_date() \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {4}) \
where stat_date < {4}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {3})) \
where stat_date < {3})) \
union all \
select '30-60' as label,count(distinct(device_id)) from data_feed_exposure2 \
where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and stat_date = get_yesterday_date() \
and device_id not in \
(select distinct(device_id) from data_feed_click2 \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
where stat_date = get_yesterday_date() \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {5}) \
where stat_date < {5}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {4})) \
where stat_date < {4})) \
union all \
select '60-90' as label,count(distinct(device_id)) from data_feed_exposure2 \
where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and stat_date = get_yesterday_date() \
and device_id not in \
(select distinct(device_id) from data_feed_click2 \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
where stat_date = get_yesterday_date() \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {6}) \
where stat_date < {6}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {5})) \
where stat_date < {5})) \
union all \
select '90+' as label,count(distinct(device_id)) from data_feed_exposure2 \
where device_type{0} \
and from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
and stat_date = get_yesterday_date() \
and device_id not in \
(select distinct(device_id) from data_feed_click2 \
where from_unixtime(time,'%Y-%m-%d')=date_add(curdate(), interval -1 day) \
where stat_date = get_yesterday_date() \
and device_type{1}) \
and device_id in \
(select distinct(device_id) \
from data_feed_exposure2 \
where device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {6}))".format(platform,platform.replace(' ','') if platform[-2]=='e' else platform,my_tm1,my_tm2,my_tm3,my_tm4,my_tm5)
where stat_date < {6}))".format(platform,platform.replace(' ','') if platform[-2]=='e' else platform,my_date1,my_date2,my_date3,my_date4,my_date5)
cursor.execute(sql)
result = cursor.fetchall()
db.close()
......
......@@ -2,21 +2,16 @@ 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"))
#一周之前的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")
def get_register_uid_count():
......@@ -29,49 +24,49 @@ def get_register_uid_count():
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {0}) \
where stat_date < {0}) \
union all \
select '7-14' as label,count(distinct(device_id)) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {1}) \
where stat_date < {1}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {0}) \
where stat_date < {0}) \
union all \
select '14-30' as label,count(distinct(device_id)) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {2}) \
where stat_date < {2}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {1}) \
where stat_date < {1}) \
union all \
select '30-60' as label,count(distinct(device_id)) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {3}) \
where stat_date < {3}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {2}) \
where stat_date < {2}) \
union all \
select '60-90' as label,count(distinct(device_id)) \
from data_feed_exposure2 \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {4}) \
where stat_date < {4}) \
and device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {3}) \
where stat_date < {3}) \
union all \
select '90+' as label,count(distinct(device_id)) \
from data_feed_exposure2 \
where device_id in \
(select distinct(device_id) from data_feed_exposure2 \
where time < {4})".format(my_tm1,my_tm2,my_tm3,my_tm4,my_tm5)
where stat_date < {4})".format(my_date1,my_date2,my_date3,my_date4,my_date5)
cursor.execute(sql)
result = cursor.fetchall()
db.close()
......
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