Browse Source

homepage recommend

丁云鹏 1 year ago
parent
commit
f951ddf50a

+ 6 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallService.java

@@ -1,11 +1,17 @@
 package com.tzld.piaoquan.recommend.server.service.recall;
 
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import org.springframework.stereotype.Service;
 
+import java.util.Map;
+
 /**
  * @author dyp
  */
 @Service
 public class RecallService {
 
+    @ApolloJsonValue("city_code")
+    private Map<String, String> cityCode;
+
 }

+ 18 - 23
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractRecallStrategy.java

@@ -16,17 +16,13 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ZSetOperations;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 /**
  * @author dyp
  */
-public abstract class AbstractRegionRecallStrategy implements RecallStrategy {
+public abstract class AbstractRecallStrategy implements RecallStrategy {
     @Autowired
     protected RedisTemplate<String, String> redisTemplate;
 
@@ -80,6 +76,7 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy {
         // 召回
         int getSize = param.getSize() * 5;
         int freq = 0;
+        String lastVideoId = "";
         List<RecallResult.RecallData> results = new ArrayList<>();
         while (results.size() < param.getSize()) {
             freq += 1;
@@ -92,13 +89,13 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy {
                 break;
             }
             idx += getSize;
-            Map<Long, Double> videoMap = data.stream()
-                    .filter(t -> NumberUtils.isDigits(t.getValue()))
-                    .collect(Collectors.toMap(
-                            t -> Long.getLong(t.getValue()),
-                            t -> t.getScore(),
-                            (a, b) -> b
-                    ));
+
+            Map<Long, Double> videoMap = new HashMap<>();
+            for (ZSetOperations.TypedTuple<String> t : data) {
+                lastVideoId = t.getValue();
+                videoMap.put(NumberUtils.toLong(t.getValue(), 0), t.getScore());
+            }
+
             FilterParam filterParam = new FilterParam();
             filterParam.setVideoIds(Lists.newArrayList(videoMap.keySet()));
             FilterResult filterResult = filterService.filter(filterParam);
@@ -115,16 +112,14 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy {
         }
 
 
-//        pool_recall_result.sort(key=lambda x: x.get('rovScore', 0), reverse=True)
-//
-//        # if len(recall_data) > 0 and len(pool_recall_result) == 0 \
-//        #         and self.ab_code == config_.AB_CODE['region_rank_by_h'].get('abtest_112') and self.mid:
-//
-//        if len(recall_data) > 0 and len(pool_recall_result) == 0 and self.mid:
-//            # 召回数据不为空 & 过滤后结果为空 & 位于实验组 & mid不为空时,更新召回获取的末位视频id记录到定位的key中
-//                last_video_key = f'{last_video_key_prefix}{self.app_type}:{self.mid}'
-//        self.redis_helper.set_data_to_redis(key_name=last_video_key, value=recall_data[-1][0],
-//                expire_time=expire_time)
+        Collections.sort(results, (o1, o2) -> (int) (o2.getRovScore() - o1.getRovScore()));
+
+        if (StringUtils.isNotBlank(lastVideoId)
+                && CollectionUtils.isNotEmpty(results)
+                && StringUtils.isNotBlank(param.getMid())) {
+            // 召回数据不为空 & 过滤后结果为空 &  mid不为空时,更新召回获取的末位视频id记录到定位的key中
+            redisTemplate.opsForValue().set(lastVideoKey, lastVideoId, 2, TimeUnit.HOURS);
+        }
 
         RecallResult result = new RecallResult();
         result.setRecallData(results.subList(0, results.size() < param.getSize() ? results.size() : param.getSize()));

+ 38 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup224HRecallStrategy.java

@@ -0,0 +1,38 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * 分地域24h
+ *
+ * @author dyp
+ */
+@Service
+public class Dup224HRecallStrategy extends AbstractRecallStrategy {
+    //record_key_prefix = config_.RECORD_KEY_NAME_PREFIX_LAST_VIDEO_REGION_DUP2_24H
+    //            # 视频列表
+    //            pool_key_prefix = config_.RECALL_KEY_NAME_PREFIX_DUP2_REGION_24H_H
+    //            # mid对应上一次视频记录
+    //            last_video_key_prefix = config_.LAST_VIDEO_FROM_REGION_DUP2_24H_PREFIX
+    //            push_from = config_.PUSH_FROM['rov_recall_24h']
+    @Override
+    protected String recordKey(RecallParam param) {
+        return String.format("recall:last:record:region:dup2:24h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String poolKey(RecallParam param, String now_dt, int h) {
+        return String.format("recall:item:score:region:dup2:24h:%s:%s:%s:%s:%s", param.getProvinceCode(), param.getDataKey(), param.getRuleKey(), now_dt, h);
+    }
+
+    @Override
+    protected String lastVideoKey(RecallParam param) {
+        return String.format("recall:last:item:region:dup2:24h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String pushFrom() {
+        return "recall_pool_24h";
+    }
+}

+ 38 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup248HRecallStrategy.java

@@ -0,0 +1,38 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * 分地域24h
+ *
+ * @author dyp
+ */
+@Service
+public class Dup248HRecallStrategy extends AbstractRecallStrategy {
+    //  record_key_prefix = config_.RECORD_KEY_NAME_PREFIX_LAST_VIDEO_REGION_DUP2_48H
+    //            # 视频列表
+    //            pool_key_prefix = config_.RECALL_KEY_NAME_PREFIX_DUP2_REGION_48H_H
+    //            # mid对应上一次视频记录
+    //            last_video_key_prefix = config_.LAST_VIDEO_FROM_REGION_DUP2_48H_PREFIX
+    //            push_from = config_.PUSH_FROM['rov_recall_48h']
+    @Override
+    protected String recordKey(RecallParam param) {
+        return String.format("recall:last:record:region:dup2:48h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String poolKey(RecallParam param, String now_dt, int h) {
+        return String.format("recall:item:score:region:dup2:48h:%s:%s:%s:%s:%s", param.getProvinceCode(), param.getDataKey(), param.getRuleKey(), now_dt, h);
+    }
+
+    @Override
+    protected String lastVideoKey(RecallParam param) {
+        return String.format("recall:last:item:region:dup2:48h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String pushFrom() {
+        return "recall_pool_48h";
+    }
+}

+ 36 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup324HRecallStrategy.java

@@ -0,0 +1,36 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * 分地域24h
+ *
+ * @author dyp
+ */
+@Service
+public class Dup324HRecallStrategy extends AbstractRecallStrategy {
+    //record_key_prefix = config_.RECORD_KEY_NAME_PREFIX_LAST_VIDEO_REGION_DUP3_24H
+    //            pool_key_prefix = config_.RECALL_KEY_NAME_PREFIX_DUP3_REGION_24H_H
+    //            last_video_key_prefix = config_.LAST_VIDEO_FROM_REGION_DUP3_24H_PREFIX
+    //            push_from = config_.PUSH_FROM['rov_recall_24h_dup']
+    @Override
+    protected String recordKey(RecallParam param) {
+        return String.format("recall:last:record:region:dup3:24h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String poolKey(RecallParam param, String now_dt, int h) {
+        return String.format("recall:item:score:region:dup3:24h:%s:%s:%s:%s:%s", param.getProvinceCode(), param.getDataKey(), param.getRuleKey(), now_dt, h);
+    }
+
+    @Override
+    protected String lastVideoKey(RecallParam param) {
+        return String.format("recall:last:item:region:dup3:24h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String pushFrom() {
+        return "rov_recall_24h_dup";
+    }
+}

+ 36 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup348HRecallStrategy.java

@@ -0,0 +1,36 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * 分地域24h
+ *
+ * @author dyp
+ */
+@Service
+public class Dup348HRecallStrategy extends AbstractRecallStrategy {
+    //  record_key_prefix = config_.RECORD_KEY_NAME_PREFIX_LAST_VIDEO_REGION_DUP3_48H
+    //            pool_key_prefix = config_.RECALL_KEY_NAME_PREFIX_DUP3_REGION_48H_H
+    //            last_video_key_prefix = config_.LAST_VIDEO_FROM_REGION_DUP3_48H_PREFIX
+    //            push_from = config_.PUSH_FROM['rov_recall_48h_dup']
+    @Override
+    protected String recordKey(RecallParam param) {
+        return String.format("recall:last:record:region:dup3:48h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String poolKey(RecallParam param, String now_dt, int h) {
+        return String.format("recall:item:score:region:dup3:48h:%s:%s:%s:%s:%s", param.getProvinceCode(), param.getDataKey(), param.getRuleKey(), now_dt, h);
+    }
+
+    @Override
+    protected String lastVideoKey(RecallParam param) {
+        return String.format("recall:last:item:region:dup3:48h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String pushFrom() {
+        return "rov_recall_48h_dup";
+    }
+}

+ 38 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Region24HRecallStrategy.java

@@ -0,0 +1,38 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * 分地域24h
+ *
+ * @author dyp
+ */
+@Service
+public class Region24HRecallStrategy extends AbstractRecallStrategy {
+    //record_key_prefix = config_.RECORD_KEY_NAME_PREFIX_LAST_VIDEO_REGION_DUP1_24H
+//            # 视频列表
+//            pool_key_prefix = config_.RECALL_KEY_NAME_PREFIX_DUP1_REGION_24H_H
+//            # mid对应上一次视频记录
+//            last_video_key_prefix = config_.LAST_VIDEO_FROM_REGION_DUP1_24H_PREFIX
+//            push_from = config_.PUSH_FROM['rov_recall_region_24h']
+    @Override
+    protected String recordKey(RecallParam param) {
+        return String.format("recall:last:record:region:dup1:24h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String poolKey(RecallParam param, String now_dt, int h) {
+        return String.format("recall:item:score:region:dup1:region24h:%s:%s:%s:%s:%s", param.getProvinceCode(), param.getDataKey(), param.getRuleKey(), now_dt, h);
+    }
+
+    @Override
+    protected String lastVideoKey(RecallParam param) {
+        return String.format("recall:last:item:region:dup1:24h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String pushFrom() {
+        return "recall_pool_region_24h";
+    }
+}

+ 32 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionHRecallStrategy.java

@@ -0,0 +1,32 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * 分地域
+ * @author dyp
+ */
+@Service
+public class RegionHRecallStrategy extends AbstractRecallStrategy {
+
+    @Override
+    protected String recordKey(RecallParam param) {
+        return String.format("recall:last:record:region:h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String poolKey(RecallParam param, String now_dt, int h) {
+        return String.format("recall:item:score:region:h:%s:%s:%s:%s:%s", param.getProvinceCode(), param.getDataKey(), param.getRuleKey(), now_dt, h);
+    }
+
+    @Override
+    protected String lastVideoKey(RecallParam param) {
+        return String.format("recall:last:item:region:h:%s:%s", param.getAppType(), param.getMid());
+    }
+
+    @Override
+    protected String pushFrom() {
+        return "recall_pool_region_h";
+    }
+}