Browse Source

update scoreModel

gufengshou1 1 year ago
parent
commit
fbd53b8ed6

+ 16 - 16
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/ScoreThresholdPredictModel.java

@@ -104,27 +104,23 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
         double offlineScore ;
         //处理空值逻辑
         double threshold=(double)configMap.getOrDefault("threshold",0);
-        if(!StringUtils.isBlank(userScore)&&!StringUtils.isBlank(itemScore)){
-
-        }else if(StringUtils.isBlank(userScore)&&StringUtils.isBlank(itemScore)){
+        if(StringUtils.isBlank(userScore)&&StringUtils.isBlank(itemScore)){
             itemScore="0";
-            threshold=(double)configMap.getOrDefault("item_threshold", 0);
+            userScore="0";
+            threshold=(double)configMap.getOrDefault("miss_threshold", 0);
 
-        }else {
+        }else if(StringUtils.isBlank(userScore)||StringUtils.isBlank(itemScore)){
             boolean isUserScoreBlank=StringUtils.isBlank(userScore);
-            userScore
+            userScore=isUserScoreBlank?"0":userScore;
+            itemScore=isUserScoreBlank?itemScore:"0";
+            threshold=isUserScoreBlank?
+                    (double)configMap.getOrDefault("item_threshold", 0):
+                    (double)configMap.getOrDefault("user_threshold", 0);
+            hitStrategy=isUserScoreBlank?"item":"user";
         }
-        if(!StringUtils.isBlank(itemScore)){
-            userScore="0";
-            threshold=(double)configMap.getOrDefault("user_threshold", 0);
-            result.put("hit_strategy","error");
-        }
-        offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
-
+        //获取计算参数
         SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
         SimpleDateFormat weekDayFormat = new SimpleDateFormat("u");
-
-
         Map<String, String> onlineFeatures = new HashMap<>();
         onlineFeatures.put("ctx_apptype", modelParam.getAppType().toString());
         onlineFeatures.put("ctx_week", weekDayFormat.format(modelParam.getDate()));
@@ -139,7 +135,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                 rankScore = Double.parseDouble(rankScoreStr);
             }
         }
-
+        offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
         double onlineScore=getOlineScore(onlineFeatures);
         double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0);
         double finalScore =getFinalScore(onlineScore,offlineScore);
@@ -159,10 +155,14 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
         result.put("user_score", userScore);
         result.put("item_score", itemScore);
         result.put("final_score", finalScore);
+        result.put("merge_score", mergeScore);
+        result.put("rank_score", rankScore);
+        result.put("rank_score_bias", rankScoreBias);
         result.put("online_score", onlineScore);
         result.put("threshold", threshold);
         result.put("ad_predict", adPredict);
         result.put("online_features", onlineFeatures);
+        result.put("hit_strategy",hitStrategy);
         return result;
     }