|
@@ -1,24 +1,34 @@
|
|
|
import json
|
|
|
import random
|
|
|
+import time
|
|
|
+
|
|
|
import gevent
|
|
|
from db_helper import RedisHelper
|
|
|
from config import set_config
|
|
|
+from log import Log
|
|
|
from gevent import monkey, pool
|
|
|
monkey.patch_all()
|
|
|
|
|
|
config_ = set_config()
|
|
|
+log_ = Log()
|
|
|
redis_helper = RedisHelper()
|
|
|
|
|
|
|
|
|
def thompson_process(creative_id):
|
|
|
# 获取creative_id对应的Thompson参数
|
|
|
+ st_time1 = time.time()
|
|
|
thompson_param = redis_helper.get_data_from_redis(key_name=f"{config_.THOMPSON_PARAM_KEY_PREFIX}{creative_id}")
|
|
|
+ get_redis_time = int(time.time() - st_time1)
|
|
|
+ thompson_time = {}
|
|
|
if thompson_param is None or thompson_param == '':
|
|
|
# 参数不存在,随机生成[0, 1)之间的浮点数
|
|
|
+ st_time2 = time.time()
|
|
|
score = random.random()
|
|
|
+ thompson_time['random'] = int(time.time() - st_time2)
|
|
|
random_flag = 'random'
|
|
|
else:
|
|
|
# 参数存在
|
|
|
+ st_time3 = time.time()
|
|
|
param_alpha, param_beta = json.loads(thompson_param.strip())
|
|
|
param_alpha, param_beta = int(param_alpha), int(param_beta)
|
|
|
if param_alpha + param_beta >= 100:
|
|
@@ -29,7 +39,9 @@ def thompson_process(creative_id):
|
|
|
# ad_idea_id 曝光数 < 100,随机生成[0, 1)之间的浮点数
|
|
|
score = random.random()
|
|
|
random_flag = 'random'
|
|
|
+ thompson_time['beta'] = int(time.time() - st_time3)
|
|
|
thompson_res = [creative_id, score, thompson_param, random_flag]
|
|
|
+ log_.info(f"get_redis_time: {get_redis_time}, thompson_time: {thompson_time}")
|
|
|
return thompson_res
|
|
|
|
|
|
|