Commit 9faccb11 authored by 张彦钊's avatar 张彦钊

add prints for test

parent 588e7f4c
from utils import con_sql from utils import con_sql
import datetime import datetime
import time
def fetch_data(start_date, end_date): def fetch_data(start_date, end_date):
...@@ -25,7 +27,10 @@ def fetch_data(start_date, end_date): ...@@ -25,7 +27,10 @@ def fetch_data(start_date, end_date):
# 获取曝光表里的数据 # 获取曝光表里的数据
sql = "select cid,device_id,time,stat_date from data_feed_exposure " \ sql = "select cid,device_id,time,stat_date from data_feed_exposure " \
"where stat_date >= '{0}' and stat_date <= '{1}'".format(start_date, end_date) "where stat_date >= '{0}' and stat_date <= '{1}'".format(start_date, end_date)
start = time.time()
exposure = con_sql(sql) exposure = con_sql(sql)
end = time.time()
print("获取曝光表耗时{}分".format((end-start)/60))
exposure = exposure.rename(columns={0: "cid", 1: "device_id", 2: "time_date", 3: "stat_date"}) exposure = exposure.rename(columns={0: "cid", 1: "device_id", 2: "time_date", 3: "stat_date"})
print("成功获取曝光表里的数据") print("成功获取曝光表里的数据")
# 从time特征中抽取hour # 从time特征中抽取hour
......
...@@ -16,7 +16,7 @@ def get_date(): ...@@ -16,7 +16,7 @@ def get_date():
month = now.month month = now.month
day = now.day day = now.day
date = datetime(year,month,day) date = datetime(year,month,day)
data_start_date = (date - timedelta(days=36)).strftime("%Y-%m-%d") data_start_date = (date - timedelta(days=31)).strftime("%Y-%m-%d")
data_end_date = (date - timedelta(days=1)).strftime("%Y-%m-%d") data_end_date = (date - timedelta(days=1)).strftime("%Y-%m-%d")
validation_date = (date - timedelta(days=2)).strftime("%Y-%m-%d") validation_date = (date - timedelta(days=2)).strftime("%Y-%m-%d")
# 验证集和测试集的日期必须相差一天,否则切割数据集时会报错 # 验证集和测试集的日期必须相差一天,否则切割数据集时会报错
...@@ -41,7 +41,9 @@ def con_sql(sql): ...@@ -41,7 +41,9 @@ def con_sql(sql):
cursor = db.cursor() cursor = db.cursor()
cursor.execute(sql) cursor.execute(sql)
result = cursor.fetchall() result = cursor.fetchall()
print("成功从数据库获取数据")
df = pd.DataFrame(list(result)).dropna() df = pd.DataFrame(list(result)).dropna()
print("成功将数据转化成DataFrame")
db.close() db.close()
return df return df
......
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