|
@@ -76,25 +76,43 @@ def get_creative_id_with_thompson_weight(mid, creative_id_list, gevent_pool, sor
|
|
|
gevent.joinall(tasks)
|
|
|
thompson_res_list = [t.get() for t in tasks]
|
|
|
# 获取creative_id对应cvr, 给定对应权重
|
|
|
+ # st_1 = time.time()
|
|
|
cvr_mapping = {}
|
|
|
creative_weight = {}
|
|
|
- for creative_id in creative_id_list:
|
|
|
+ key_list = [f"{config_.CREATIVE_CVR_KEY_PREFIX}{creative_id}" for creative_id in creative_id_list]
|
|
|
+ cvr_list = []
|
|
|
+ name_list = []
|
|
|
+ for i in range(len(key_list)):
|
|
|
+ if i % 20 == 0 and i != 0:
|
|
|
+ print(len(name_list))
|
|
|
+ cvr_res = redis_helper.get_batch_key(name_list=name_list)
|
|
|
+ cvr_list.extend(cvr_res)
|
|
|
+ name_list = [key_list[i]]
|
|
|
+ else:
|
|
|
+ name_list.append(key_list[i])
|
|
|
+ if len(name_list) > 0:
|
|
|
+ cvr_res = redis_helper.get_batch_key(name_list=name_list)
|
|
|
+ cvr_list.extend(cvr_res)
|
|
|
+ for i, creative_id in enumerate(creative_id_list):
|
|
|
creative_weight[creative_id] = config_.CREATIVE_WEIGHT_INITIAL
|
|
|
- cvr = redis_helper.get_data_from_redis(
|
|
|
- key_name=f"{config_.CREATIVE_CVR_KEY_PREFIX}{creative_id}")
|
|
|
+ cvr = cvr_list[i]
|
|
|
if cvr is None:
|
|
|
continue
|
|
|
try:
|
|
|
cvr_mapping[creative_id] = float(cvr)
|
|
|
except:
|
|
|
continue
|
|
|
- cvr_sorted = sorted(cvr_mapping.items(), key=lambda x: x[1], reverse=False)
|
|
|
+ # log_.info(f"st1: {(time.time() - st_1) * 1000}ms")
|
|
|
|
|
|
+ # st_2 = time.time()
|
|
|
+ cvr_sorted = sorted(cvr_mapping.items(), key=lambda x: x[1], reverse=False)
|
|
|
for i, item in enumerate(cvr_sorted):
|
|
|
creative_id = item[0]
|
|
|
creative_weight[creative_id] += (i * config_.WEIGHT_GRADIENT)
|
|
|
+ # log_.info(f"st2: {(time.time() - st_2) * 1000}ms")
|
|
|
|
|
|
# 对有cvr的creative进行加权
|
|
|
+ # st_3 = time.time()
|
|
|
thompson_weight_res_list = []
|
|
|
weight_sum = sum([weight for _, weight in creative_weight.items()])
|
|
|
for thompson_res in thompson_res_list:
|
|
@@ -106,6 +124,8 @@ def get_creative_id_with_thompson_weight(mid, creative_id_list, gevent_pool, sor
|
|
|
weight_score = score
|
|
|
thompson_weight_res = thompson_res + [creative_weight[creative_id], weight_score]
|
|
|
thompson_weight_res_list.append(thompson_weight_res)
|
|
|
+ # log_.info(f"st3: {(time.time() - st_3) * 1000}ms")
|
|
|
+
|
|
|
# 重新排序
|
|
|
thompson_res_rank = sorted(thompson_weight_res_list, key=lambda x: x[7], reverse=True)
|
|
|
rank_res = {
|