浏览代码

pool manager

baichongyang 3 年之前
父节点
当前提交
74f9278c93
共有 8 个文件被更改,包括 129 次插入0 次删除
  1. 16 0
      .vscode/launch.json
  2. 0 0
      configs/config.py
  3. 4 0
      configs/config_algo.py
  4. 2 0
      configs/config_basic.py
  5. 15 0
      configs/config_redis.py
  6. 0 0
      controller/pm_pools.py
  7. 77 0
      controller/pool_manager.py
  8. 15 0
      utils/filter_utils.py

+ 16 - 0
.vscode/launch.json

@@ -0,0 +1,16 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {"name":"Python: 当前文件","type":"python","request":"launch","program":"${file}","console":"integratedTerminal"},
+        {
+            "name": "Python: 当前文件",
+            "type": "python",
+            "request": "launch",
+            "program": "${file}",
+            "console": "integratedTerminal"
+        }
+    ]
+}

+ 0 - 0
configs/config.py


+ 4 - 0
configs/config_algo.py

@@ -0,0 +1,4 @@
+DISTRIBUTE_FROM=''
+DISTRIBUTE_FROM_RECALL = ''
+DISTRIBUTE_FROM_POOL = ''
+ABTEST_CODE = ''

+ 2 - 0
configs/config_basic.py

@@ -0,0 +1,2 @@
+DISTRIBUTE_X = 10 #按X倍的曝光率去分发视频
+RECALL_VIDS_SURPLUS = 3 #按X倍的量去召回视频,进行过滤

+ 15 - 0
configs/config_redis.py

@@ -0,0 +1,15 @@
+#redis ip
+REDIS_HOST = ''
+#redis 端口
+REDIS_PORT = ''
+
+#召回池
+ROV_SERVICE_RECALL_VIDS = ''
+#测试池
+ROV_SERVICE_POOL_VIDS = ''
+#测试池视频已分发量
+ROV_SERVICE_POOL_VIDS_DISTRIBUTE_COUNTS = ''
+#测试池视频分发上限
+ROV_SERVICE_POOL_VIDS_DISTRIBUTE_LIMIT = ''
+#已分发视频(preview)
+ROV_SERVICE_MID_DISTRIBUTED = ''

+ 0 - 0
controller/pm_pools.py


+ 77 - 0
controller/pool_manager.py

@@ -0,0 +1,77 @@
+import redis
+import random
+from models.model import R
+from utils import filter_utils
+from configs import config_redis, config_algo
+
+class pool_manager:
+    def __init__(self, k, p, mid, scene,counts=10):
+        self.k = k
+        self.p = p
+        self.mid = mid
+        self.scene = scene
+        self.counts = counts
+
+    #前k个按rov分值排序,后面total-k个,按p的概率从测试池取值,1-p的概率从召回池取
+    def get_rov_data(self, k,p):
+        res_all = []
+        res_recall = self._get_data_from_cache(config_redis.ROV_SERVICE_RECALL_VIDS, self.counts, self.mid)
+        res_pool = self._get_data_from_cache(config_redis.ROV_SERVICE_POOL_VIDS, self.counts, self.mid)
+        head_recall = 0
+        head_pool = 0
+        #TODO
+        #添加score及from来源
+        i = 0
+        item = None
+        while(i<k):
+            if res_recall[head_recall]['score']>res_pool[head_pool]['score']:
+                item = res_recall[head_recall]
+                head_recall += 1
+            else:
+                item = res_pool[head_pool]
+                head_pool += 1
+            res_all.append(item)
+            i += 1
+
+        i = 0
+        while(i<self.counts-k):
+            if random.randint(1,10)<p:
+                item = res_recall[head_recall]
+                head_recall += 1
+            else:
+                item = res_pool[head_pool]
+                head_pool += 1
+            res_all.append(item)
+            i+= 1
+
+        return res_all
+
+    #获取兜底数据
+    def get_backup_data(self, vid, start, counts):
+        pass
+
+    #检查vid是否已超量分发(只对测试池有效)
+    def check_over_distribute(self, vid):
+        pass
+
+    #从缓存中key取counts个数据
+    def _get_data_from_cache(self, key, counts, mid):
+        start = 0
+        end = counts
+        res = []
+        while(len(res)<counts):
+            _res = self._sub_get_data_from_cache(self, start, end, key, counts)
+            res.extend(_res)
+            start = end
+            end = start + counts
+        #TODO
+        #数量不足用backup数据补齐
+        return res
+
+    #从缓存中key取counts个数据
+    def _sub_get_data_from_cache(self, start, end, key, counts):
+        res = R.zrange(key, start, end, withscores=True)
+        res = filter_utils.filter_res_unavailable(res, self.scene)
+        res = filter_utils.filter_mid_viewed_videos(res, self.scene, self.mid)
+        res = filter_utils.filter_mid_viewed_videos(res, self.scene, self.mid)
+        return res

+ 15 - 0
utils/filter_utils.py

@@ -0,0 +1,15 @@
+#检查视频是否不可用
+def check_res_unavailable(vids):
+    pass
+
+#移除不可用视频
+def rm_unavailable_from_db(vids):
+    pass
+
+#已看过的视频
+def check_mid_viewed_videos(mid):
+    pass
+
+#暂时分发过的视频
+def check_mid_previewed_videos(mid):
+    pass