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

add print for test

parent fca10857
...@@ -11,13 +11,10 @@ from utils import * ...@@ -11,13 +11,10 @@ from utils import *
def feature_en(user_profile): def feature_en(user_profile):
file_name = DIRECTORY_PATH + "diaryTestSet/{0}DiaryTop3000.csv".format(user_profile['city_id']) file_name = DIRECTORY_PATH + "diaryTestSet/{0}DiaryTop3000.csv".format(user_profile['city_id'])
data = pd.read_csv(file_name) data = pd.read_csv(file_name)
data["device_id"] = user_profile['device_id'] data["device_id"] = user_profile['device_id']
now = datetime.now() now = datetime.now()
data["hour"] = now.hour data["hour"] = now.hour
data["minute"] = now.minute data["minute"] = now.minute
data.loc[data["hour"] == 0, ["hour"]] = 24 data.loc[data["hour"] == 0, ["hour"]] = 24
data.loc[data["minute"] == 0, ["minute"]] = 60 data.loc[data["minute"] == 0, ["minute"]] = 60
data["hour"] = data["hour"].astype("category") data["hour"] = data["hour"].astype("category")
...@@ -50,12 +47,14 @@ def predict(user_profile): ...@@ -50,12 +47,14 @@ def predict(user_profile):
ffm_model = xl.create_ffm() ffm_model = xl.create_ffm()
ffm_model.setTest(instance_file_path) ffm_model.setTest(instance_file_path)
ffm_model.setSigmoid() ffm_model.setSigmoid()
#日志保存路径,如果不加这个参数,日志默认保存在/temp路径下,不符合规范 #日志保存路径,如果不加这个参数,日志默认保存在/temp路径下,不符合规范
param = {"log": "/data2/models/result"} param = {"log": "/data2/models/result"}
ffm_model.predict(param,DIRECTORY_PATH + "model.out", ffm_model.predict(param,DIRECTORY_PATH + "model.out",
DIRECTORY_PATH + "result/{0}_output.txt".format(user_profile['device_id'])) DIRECTORY_PATH + "result/{0}_output.txt".format(user_profile['device_id']))
print("预测结束") print("预测结束")
predict_save_to_local(user_profile, instance) predict_save_to_local(user_profile, instance)
#TODO 没有提供生产环境的redis地址,所以这个函数先不运行 #TODO 没有提供生产环境的redis地址,所以这个函数先不运行
# predict_save_to_redis(user_profile, instance) # predict_save_to_redis(user_profile, instance)
...@@ -85,7 +84,7 @@ def predict_save_to_redis(user_profile, instance): ...@@ -85,7 +84,7 @@ def predict_save_to_redis(user_profile, instance):
def router(device_id): def router(device_id):
user_profile, not_exist = fetch_user_profile(device_id) user_profile, not_exist = fetch_user_profile(device_id)
if not_exist==True: if not_exist:
print('Sorry, we don\'t have you.') print('Sorry, we don\'t have you.')
else: else:
predict(user_profile) predict(user_profile)
...@@ -94,20 +93,20 @@ def router(device_id): ...@@ -94,20 +93,20 @@ def router(device_id):
if __name__ == "__main__": if __name__ == "__main__":
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同 # TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while True: while True:
start = time.time()
empty,device_id_list = get_active_users() empty,device_id_list = get_active_users()
if empty==True: if empty:
time.sleep(60) time.sleep(60)
else: else:
old_device_id_list = pd.read_csv(DIRECTORY_PATH + "data_set_device_id.csv")["device_id"].values.tolist() old_device_id_list = pd.read_csv(DIRECTORY_PATH + "data_set_device_id.csv")["device_id"].values.tolist()
for device_id in device_id_list: for device_id in device_id_list:
if device_id in old_device_id_list: if device_id in old_device_id_list:
start = time.time()
router(device_id) router(device_id)
end = time.time()
print("该用户预测耗时{}秒".format(end - start))
else: else:
print("该用户不是老用户,不能预测") print("该用户不是老用户,不能预测")
end = time.time()
time_cost = (end - start)
print("耗时{}秒".format(time_cost))
from utils import con_sql from utils import con_sql
from datetime import datetime from datetime import datetime
......
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