|
@@ -22,7 +22,7 @@ from utils import update_video_w_h_rate
|
|
|
from user2new import user2new
|
|
|
from params_helper import Params
|
|
|
from manager_op import get_video_list, search_video
|
|
|
-from ad_recommend import ad_recommend_predict
|
|
|
+from ad_recommend import ad_recommend_predict, ad_recommend_predict_with_roi
|
|
|
# from werkzeug.middleware.profiler import ProfilerMiddleware
|
|
|
# from geventwebsocket.handler import WebSocketHandler
|
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
@@ -32,6 +32,8 @@ level_weight = {'1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1}
|
|
|
flow_pool_abtest_config = {'control_group': [7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
|
|
'experimental_flow_set_level': [],
|
|
|
'experimental_flow_set_level_score': []}
|
|
|
+ad_arpu = 0
|
|
|
+ad_roi_param = 0
|
|
|
|
|
|
|
|
|
def update_flow_pool_config():
|
|
@@ -46,20 +48,37 @@ def update_flow_pool_config():
|
|
|
level_weight_initial = redis_helper.get_data_from_redis(key_name=config_.FLOWPOOL_LEVEL_WEIGHT_KEY_NAME)
|
|
|
if level_weight_initial is not None:
|
|
|
level_weight = json.loads(level_weight_initial)
|
|
|
- # log_.info({
|
|
|
- # "now_date": datetime.datetime.strftime(datetime.datetime.today(), '%Y%m%d %H:%M:%S'),
|
|
|
- # "level_weight": level_weight
|
|
|
- # })
|
|
|
- # print(level_weight)
|
|
|
+
|
|
|
global flow_pool_abtest_config
|
|
|
flow_pool_abtest_config = redis_helper.get_data_from_redis(key_name=config_.FLOWPOOL_ABTEST_KEY_NAME)
|
|
|
if flow_pool_abtest_config is not None:
|
|
|
flow_pool_abtest_config = json.loads(flow_pool_abtest_config)
|
|
|
|
|
|
|
|
|
+def update_ad_roi_predict_params():
|
|
|
+ """
|
|
|
+ 定时更新广告预测相关预设配置到内存变量中
|
|
|
+ 1. arpu: 上一周期arpu值
|
|
|
+ 2. roi_param: 计算roi使用参数
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
+ redis_helper = RedisHelper()
|
|
|
+ global ad_arpu
|
|
|
+ ad_arpu_initial = redis_helper.get_data_from_redis(key_name=config_.KEY_NAME_AD_ARPU)
|
|
|
+ if ad_arpu_initial is not None:
|
|
|
+ ad_arpu = float(ad_arpu_initial)
|
|
|
+
|
|
|
+ global ad_roi_param
|
|
|
+ ad_roi_param_initial = redis_helper.get_data_from_redis(key_name=config_.KEY_NAME_AD_ROI_PARAM)
|
|
|
+ if ad_roi_param_initial is not None:
|
|
|
+ ad_roi_param = float(ad_roi_param_initial)
|
|
|
+
|
|
|
+
|
|
|
sched = BackgroundScheduler(daemon=True, timezone='Asia/Shanghai') # 指定时区
|
|
|
sched.add_job(func=update_flow_pool_config, trigger="interval", seconds=10*60) # 间隔10min后启动
|
|
|
+sched.add_job(func=update_ad_roi_predict_params, trigger="interval", seconds=10*60) # 间隔10min后启动
|
|
|
update_flow_pool_config()
|
|
|
+update_ad_roi_predict_params()
|
|
|
sched.start()
|
|
|
|
|
|
app = Flask(__name__)
|
|
@@ -441,6 +460,52 @@ def ad_predict():
|
|
|
return json.dumps(result)
|
|
|
|
|
|
|
|
|
+# 广告推荐新策略
|
|
|
+@app.route('/applet/ad/roi/predict', methods=['GET', 'POST'])
|
|
|
+def ad_roi_predict():
|
|
|
+ start_time = time.time()
|
|
|
+ try:
|
|
|
+ request_data = json.loads(request.get_data())
|
|
|
+ mid = request_data.get('mid')
|
|
|
+ video_id = request_data.get('videoId')
|
|
|
+ app_type = request_data.get('appType')
|
|
|
+ ads = request_data.get('ads')
|
|
|
+ predict_result = ad_recommend_predict_with_roi(app_type=app_type,
|
|
|
+ mid=mid,
|
|
|
+ video_id=video_id,
|
|
|
+ ads=ads,
|
|
|
+ arpu=ad_arpu,
|
|
|
+ roi_param=ad_roi_param)
|
|
|
+ if predict_result is None:
|
|
|
+ result = {'code': -1, 'message': 'fail'}
|
|
|
+ else:
|
|
|
+ result = {
|
|
|
+ 'code': 200,
|
|
|
+ 'message': 'success',
|
|
|
+ 'data': {
|
|
|
+ 'adId': predict_result.get('ad_id'),
|
|
|
+ 'adRes': predict_result.get('ad_predict')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log_message = {
|
|
|
+ 'requestUri': '/applet/ad/roi/predict',
|
|
|
+ 'request_data': request_data,
|
|
|
+ 'logTimestamp': int(time.time() * 1000),
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'video_id': video_id,
|
|
|
+ 'predict_result': predict_result,
|
|
|
+ 'result': result,
|
|
|
+ 'executeTime': (time.time() - start_time) * 1000
|
|
|
+ }
|
|
|
+ log_.info(log_message)
|
|
|
+ return json.dumps(result)
|
|
|
+ except Exception as e:
|
|
|
+ log_.error(traceback.format_exc())
|
|
|
+ result = {'code': -1, 'message': 'fail'}
|
|
|
+ return json.dumps(result)
|
|
|
+
|
|
|
+
|
|
|
# app热榜
|
|
|
@app.route('/app/video/hot_list', methods=['GET', 'POST'])
|
|
|
def app_video_hot_list():
|