Commit 4a69002b authored by 高雅喆's avatar 高雅喆

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

update comment
parents a392a33a 52081b94
......@@ -100,15 +100,13 @@ def get_active_users():
device_id_df = con_sql(sql)
if device_id_df.empty:
print("当下这一分钟没有活跃用户,不需要预测")
# 为了debug supervisor,修改了下面的return参数
return 1,[1,2]
return True,None
else:
device_id_list = device_id_df[0].values.tolist()
# 对device_id 进行去重
device_id_list = list(set(device_id_list))
print("成功获取当下一分钟内活跃用户")
# 为了debug supervisor,修改了下面的return参数
return "0",device_id_list
return False,device_id_list
def fetch_user_profile(device_id):
......@@ -181,12 +179,14 @@ def predict(user_profile):
ffm_model = xl.create_ffm()
ffm_model.setTest(instance_file_path)
ffm_model.setSigmoid()
ffm_model.predict(DIRECTORY_PATH + "model_{0}-{1}_lr{2}_lambda{3}.out".format(DATA_START_DATE,
DATA_END_DATE, lr, l2_lambda),
DIRECTORY_PATH + "result/{0}_output.txt".format(user_profile['device_id']))
print("预测结束")
predict_save_to_local(user_profile, instance)
# predict_save_to_local(user_profile, instance)
def router(device_id):
user_profile, not_exist = fetch_user_profile(device_id)
......@@ -198,18 +198,23 @@ def router(device_id):
if __name__ == "__main__":
while True:
start = time.time()
get_active_users()
# empty,device_id_list = get_active_users()
# if empty==1:
# time.sleep(30)
# else:
# 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:
# if device_id in old_device_id_list:
# router(device_id)
# else:
# print("该用户不是老用户,不能预测")
empty,device_id_list = get_active_users()
if empty==True:
time.sleep(30)
else:
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:
if device_id in old_device_id_list:
# router(device_id)
user_profile, not_exist = fetch_user_profile(device_id)
if not_exist == 1:
print('Sorry, we don\'t have you.')
else:
predict(user_profile)
else:
print("该用户不是老用户,不能预测")
# end = time.time()
# time_cost = (end - start)
# print("耗时{}秒".format(time_cost))
......@@ -88,8 +88,7 @@ def predict_save_to_redis(user_profile, instance):
def router(device_id):
user_profile, not_exist = fetch_user_profile(device_id)
if not_exist==1:
if not_exist==True:
print('Sorry, we don\'t have you.')
else:
predict(user_profile)
......@@ -100,7 +99,7 @@ if __name__ == "__main__":
while True:
start = time.time()
empty,device_id_list = get_active_users()
if empty==1:
if empty==True:
time.sleep(60)
else:
old_device_id_list = pd.read_csv(DIRECTORY_PATH + "data_set_device_id.csv")["device_id"].values.tolist()
......
......@@ -14,15 +14,13 @@ def get_active_users():
device_id_df = con_sql(sql)
if device_id_df.empty:
print("当下这一分钟没有活跃用户,不需要预测")
# 为了debug supervisor,修改了下面的return参数
return 1,[1,2]
return True,None
else:
device_id_list = device_id_df[0].values.tolist()
# 对device_id 进行去重
device_id_list = list(set(device_id_list))
print("成功获取当下一分钟内活跃用户")
# 为了debug supervisor,修改了下面的return参数
return "0",device_id_list
return False,device_id_list
def fetch_user_profile(device_id):
......@@ -30,13 +28,11 @@ def fetch_user_profile(device_id):
user_profile = con_sql(sql)
if user_profile.empty:
print("没有获取到该用户对应的city_id")
# 为了debug supervisor,修改了下面的return参数
return {1:2}, 1
return None,True
else:
user_profile = user_profile.rename(columns={0:"device_id",1:"city_id"})
print("成功获取该用户对应的city_id")
user_profile_dict = {}
for i in user_profile.columns:
user_profile_dict[i] = user_profile.loc[0, i]
# 为了debug supervisor,修改了下面的return参数
return user_profile_dict, "0"
return user_profile_dict, False
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