Commit e795d73a authored by 宋柯's avatar 宋柯

模型上线

parent 00a38405
...@@ -51,6 +51,13 @@ def getRedisConn(): ...@@ -51,6 +51,13 @@ def getRedisConn():
# conn = redis.Redis(host="172.18.51.10", port=6379,db=0) #test # conn = redis.Redis(host="172.18.51.10", port=6379,db=0) #test
return conn return conn
def getRedisConn1():
pool = redis.ConnectionPool(host="172.16.40.133",password="ReDis!GmTx*0aN6",port=6379,db=0)
conn = redis.Redis(connection_pool=pool)
# conn = redis.Redis(host="172.16.50.145", port=6379, password="XfkMCCdWDIU%ls$h",db=0)
# conn = redis.Redis(host="172.18.51.10", port=6379,db=0) #test
return conn
def parseTags(tags,i): def parseTags(tags,i):
tags_arr = tags.split(",") tags_arr = tags.split(",")
if len(tags_arr) >= i: if len(tags_arr) >= i:
...@@ -1038,7 +1045,7 @@ def get_and_save_card_feature(itemEsFeatureDF, predictClickStaticFeatures, predi ...@@ -1038,7 +1045,7 @@ def get_and_save_card_feature(itemEsFeatureDF, predictClickStaticFeatures, predi
itemFeature = itemFeature.na.fill(fields_na_value_dict) itemFeature = itemFeature.na.fill(fields_na_value_dict)
itemFeatureDF = itemFeature.toPandas() itemFeatureDF = itemFeature.toPandas()
conn = getRedisConn() conn = getRedisConn1()
BATCH = 5000 BATCH = 5000
Key_TMP = 'strategy:model:rank:widedeep:service:feature:tmp' Key_TMP = 'strategy:model:rank:widedeep:service:feature:tmp'
def concat_service_feature(row): def concat_service_feature(row):
...@@ -1103,7 +1110,7 @@ def get_and_save_device_feature(spark, fields_na_value_dict, days = 180): ...@@ -1103,7 +1110,7 @@ def get_and_save_device_feature(spark, fields_na_value_dict, days = 180):
device_feature_df = device_feature_df.na.fill({'os': '-1'}) device_feature_df = device_feature_df.na.fill({'os': '-1'})
device_feature_df.printSchema() device_feature_df.printSchema()
device_feature_df = device_feature_df.toPandas() device_feature_df = device_feature_df.toPandas()
conn = getRedisConn() conn = getRedisConn1()
BATCH = 5000 BATCH = 5000
Key_TMP = 'strategy:model:rank:widedeep:device:feature:tmp' Key_TMP = 'strategy:model:rank:widedeep:device:feature:tmp'
conn.delete(Key_TMP) conn.delete(Key_TMP)
...@@ -1180,10 +1187,6 @@ if __name__ == '__main__': ...@@ -1180,10 +1187,6 @@ if __name__ == '__main__':
#计算 item 统计特征 #计算 item 统计特征
clickStaticFeatures, expStaticFeatures = getItemStaticFeatures(itemStatisticStartDays + trainDays + 1, startDay, endDay) clickStaticFeatures, expStaticFeatures = getItemStaticFeatures(itemStatisticStartDays + trainDays + 1, startDay, endDay)
#计算线上推理 item 统计特征
predictClickStaticFeatures, predictExpStaticFeatures = getPredictItemStaticFeatures(itemStatisticStartDays)
#user Profile Feature #user Profile Feature
userProfileFeatureDF = getUserProfileFeature(spark, addDays(-trainDays - 1, format = "%Y-%m-%d"), addDays(-1, format = "%Y-%m-%d")) userProfileFeatureDF = getUserProfileFeature(spark, addDays(-trainDays - 1, format = "%Y-%m-%d"), addDays(-1, format = "%Y-%m-%d"))
...@@ -1341,7 +1344,10 @@ if __name__ == '__main__': ...@@ -1341,7 +1344,10 @@ if __name__ == '__main__':
#存device_id -> USER_CATEGORY_os, #存device_id -> USER_CATEGORY_os,
get_and_save_device_feature(spark, fields_na_value_dict) get_and_save_device_feature(spark, fields_na_value_dict)
#存card_id -> ITEM* #计算线上推理 item 统计特征
predictClickStaticFeatures, predictExpStaticFeatures = getPredictItemStaticFeatures(itemStatisticStartDays)
# 存card_id -> ITEM*
get_and_save_card_feature(itemEsFeatureDF, predictClickStaticFeatures, predictExpStaticFeatures, fields_na_value_dict) get_and_save_card_feature(itemEsFeatureDF, predictClickStaticFeatures, predictExpStaticFeatures, fields_na_value_dict)
print("总耗时:{} mins".format((time.time() - start)/60)) print("总耗时:{} mins".format((time.time() - start)/60))
......
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