Parcourir la source

Merge branch 'feature/zhangbo_rank' of algorithm/recommend-server into master

zhangbo il y a 1 an
Parent
commit
1c6d26bda7

+ 69 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RankModel.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.recommend.server.service.rank.strategy;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.google.common.reflect.TypeToken;
 import com.tzld.piaoquan.recommend.server.common.base.RankItem;
 import com.tzld.piaoquan.recommend.server.model.Video;
@@ -82,6 +83,34 @@ public class RankStrategy4RankModel extends RankService {
             v.setSortScore(v.getSortScore() + mergeWeightIn * v.getModelScore());
         }
         Collections.sort(videosWithModel, Comparator.comparingDouble(o -> -o.getSortScore()));
+
+        //------------------- 增加日志-------------------
+        int size = 4;
+        List<Long> oldRes = rovRecallRank.subList(0, Math.min(rovRecallRank.size(), size)).stream().map(r-> r.getVideoId()).collect(Collectors.toList());
+        List<Long> newRes = videosWithModel.subList(0, Math.min(videosWithModel.size(), size)).stream().map(r-> r.getVideoId()).collect(Collectors.toList());
+        int diffpos = 0;
+        int difftop = 0;
+        for (int i=0; i<newRes.size(); ++i){
+            if (!oldRes.get(i).equals(newRes.get(i))){
+                ++diffpos;
+            }
+            if (!oldRes.contains(newRes.get(i))){
+                ++difftop;
+            }
+        }
+        JSONObject obj = new JSONObject();
+        obj.put("name", "RankStrategy4RankModel");
+        obj.put("diffpos", diffpos);
+        obj.put("difftop", difftop);
+        obj.put("videosWithModel_size", videosWithModel.size());
+        obj.put("oldRes", oldRes.stream()
+                .map(String::valueOf)
+                .collect(Collectors.joining(",")));
+        obj.put("newRes", newRes.stream()
+                .map(String::valueOf)
+                .collect(Collectors.joining(",")));
+        log.info(obj.toString());
+
         return videosWithModel;
     }
 
@@ -114,6 +143,9 @@ public class RankStrategy4RankModel extends RankService {
                             this.CLASS_NAME, e));
                 }
             }else{
+                JSONObject obj = new JSONObject();
+                obj.put("name", "user_key_in_model_is_null");
+                log.info(obj.toString());
                 return videos;
             }
         }
@@ -179,6 +211,9 @@ public class RankStrategy4RankModel extends RankService {
         List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
                 .scoring(sceneFeatureMap, userFeatureMap, rankItems);
         log.info("mergeAndRankRovRecallNew rovRecallScore={}", JSONUtils.toJson(rovRecallScore));
+        JSONObject obj = new JSONObject();
+        obj.put("name", "user_key_in_model_is_not_null");
+        log.info(obj.toString());
         return CommonCollectionUtils.toList(rovRecallScore, i -> {
             // hard code 将排序分数 赋值给video的sortScore
             Video v = i.getVideo();
@@ -189,16 +224,47 @@ public class RankStrategy4RankModel extends RankService {
 
     private Map<String, String> getSceneFeature(RankParam param) {
         Map<String, String> sceneFeatureMap = new HashMap<>();
-        sceneFeatureMap.put("ctx_region", param.getProvince());
-        sceneFeatureMap.put("ctx_city", param.getCity());
-        Calendar calendar = Calendar.getInstance();
+        String provinceCn = param.getProvince();
+        provinceCn = provinceCn.replaceAll("省$", "");
+        sceneFeatureMap.put("ctx_region", provinceCn);
+        String city = param.getCity();
+        if ("台北市".equals(city) |
+            "高雄市".equals(city) |
+            "台中市".equals(city) |
+            "桃园市".equals(city) |
+            "新北市".equals(city) |
+            "台南市".equals(city) |
+            "基隆市".equals(city) |
+            "吉林市".equals(city) |
+            "新竹市".equals(city) |
+            "嘉义市".equals(city)
+        ){
+            ;
+        }else{
+            city = city.replaceAll("市$", "");
+        }
+        sceneFeatureMap.put("ctx_city", city);
 
+        Calendar calendar = Calendar.getInstance();
         sceneFeatureMap.put("ctx_week", (calendar.get(Calendar.DAY_OF_WEEK) + 6) % 7 + "");
         sceneFeatureMap.put("ctx_hour", new SimpleDateFormat("HH").format(calendar.getTime()));
 
         return sceneFeatureMap;
     }
 
+    public static void main(String[] args) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.YEAR, 2022);
+        calendar.set(Calendar.MONTH, 0); // January is 0
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 12);
+        calendar.set(Calendar.SECOND, 30);
+        System.out.println(new SimpleDateFormat("HH").format(calendar.getTime()));
 
+        String provinceCn = "吉林省2";
+        provinceCn = provinceCn.replaceAll("省$", "");
+        System.out.println(provinceCn);
+    }
 
 }