yangxiaohui 1 year ago
parent
commit
b0cded78c5
2 changed files with 22 additions and 2 deletions
  1. 8 2
      ad_recommend.py
  2. 14 0
      lr_model.py

+ 8 - 2
ad_recommend.py

@@ -313,17 +313,23 @@ def predict_mid_video_res_with_model(now_date, mid, video_id, abtest_param, abte
     item_score = redis_helper.get_data_from_redis(key_name=item_key_name)
 
     if user_score is None:
-        if use_mean:
+        if use_mean is not None and use_mean > 0:
             user_score = redis_helper.get_data_from_redis(key_name=user_key_name_mean)
         else:
             user_score = 0.0
 
     if item_score is None:
-        if use_mean:
+        if use_mean is not None and use_mean > 0:
             item_score = redis_helper.get_data_from_redis(key_name=item_key_name_mean)
         else:
             item_score = 0.0
 
+    if user_score is None:
+        user_score = 0.0
+
+    if item_score is None:
+        item_score = 0.0
+
     offline_score = user_score + item_score
 
     online_features = {

+ 14 - 0
lr_model.py

@@ -1,6 +1,8 @@
 #coding utf-8
 import json
 import math
+import time
+
 def load_json(filename):
     with open(filename, 'r') as fin:
         json_data = json.load(fin)
@@ -22,3 +24,15 @@ def get_final_score(online_features, offline_score):
     final_score = sigmoid(final_score)
     return final_score, online_score
 
+if __name__ == '__main__':
+    app_type = 0
+    online_features = {
+        'ctx_apptype': str(app_type),
+        'ctx_week': time.strftime('%w', time.localtime()),
+        'ctx_hour':  time.strftime('%H', time.localtime()),
+    }
+    print(get_final_score(online_features, -1.0))
+    print(get_final_score(online_features, 0.0))
+    print(get_final_score({}, 0.0))
+
+