|
@@ -379,6 +379,70 @@ def cal_score_with_back_view1(df, param):
|
|
|
return df
|
|
|
|
|
|
|
|
|
+def cal_score_with_back_rate_exponential_weighting1(df, param):
|
|
|
+ """
|
|
|
+ 计算score
|
|
|
+ :param df: 特征数据
|
|
|
+ :param param: 规则参数
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ # score计算公式: score = sharerate * backrate ^ 2 * LOG(lastonehour_return + 1) * K2
|
|
|
+ # sharerate = lastonehour_share / (lastonehour_play + 1000)
|
|
|
+ # backrate = lastonehour_return / (lastonehour_share + 10)
|
|
|
+ # ctr = lastonehour_play / (lastonehour_show + 1000), 对ctr限最大值:K2 = 0.6 if ctr > 0.6 else ctr
|
|
|
+
|
|
|
+ df = df.fillna(0)
|
|
|
+ df['share_rate'] = df['lastonehour_share'] / (df['lastonehour_play'] + 1000)
|
|
|
+ df['back_rate'] = df['lastonehour_return'] / (df['lastonehour_share'] + 10)
|
|
|
+ df['log_back'] = (df['lastonehour_return'] + 1).apply(math.log)
|
|
|
+ if param.get('view_type', None) == 'video-show':
|
|
|
+ df['ctr'] = df['lastonehour_play'] / (df['lastonehour_show'] + 1000)
|
|
|
+ elif param.get('view_type', None) == 'video-show-region':
|
|
|
+ df['ctr'] = df['lastonehour_play'] / (df['lastonehour_show_region'] + 1000)
|
|
|
+ else:
|
|
|
+ df['ctr'] = df['lastonehour_play'] / (df['lastonehour_preview'] + 1000)
|
|
|
+ df['K2'] = df['ctr'].apply(lambda x: 0.6 if x > 0.6 else x)
|
|
|
+
|
|
|
+ df['platform_return_rate'] = df['platform_return'] / df['lastonehour_return']
|
|
|
+
|
|
|
+ df['score'] = df['share_rate'] * df['back_rate'] ** 2 * df['log_back'] * df['K2']
|
|
|
+
|
|
|
+ df = df.sort_values(by=['score'], ascending=False)
|
|
|
+ return df
|
|
|
+
|
|
|
+
|
|
|
+def cal_score_with_back_rate_exponential_weighting2(df, param):
|
|
|
+ """
|
|
|
+ 计算score
|
|
|
+ :param df: 特征数据
|
|
|
+ :param param: 规则参数
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ # score计算公式: score = sharerate ^ 0.5 * backrate ^ 0.8 * LOG(lastonehour_return + 1) * K2 ^ 0.5
|
|
|
+ # sharerate = lastonehour_share / (lastonehour_play + 1000)
|
|
|
+ # backrate = lastonehour_return / (lastonehour_share + 10)
|
|
|
+ # ctr = lastonehour_play / (lastonehour_show + 1000), 对ctr限最大值:K2 = 0.6 if ctr > 0.6 else ctr
|
|
|
+
|
|
|
+ df = df.fillna(0)
|
|
|
+ df['share_rate'] = df['lastonehour_share'] / (df['lastonehour_play'] + 1000)
|
|
|
+ df['back_rate'] = df['lastonehour_return'] / (df['lastonehour_share'] + 10)
|
|
|
+ df['log_back'] = (df['lastonehour_return'] + 1).apply(math.log)
|
|
|
+ if param.get('view_type', None) == 'video-show':
|
|
|
+ df['ctr'] = df['lastonehour_play'] / (df['lastonehour_show'] + 1000)
|
|
|
+ elif param.get('view_type', None) == 'video-show-region':
|
|
|
+ df['ctr'] = df['lastonehour_play'] / (df['lastonehour_show_region'] + 1000)
|
|
|
+ else:
|
|
|
+ df['ctr'] = df['lastonehour_play'] / (df['lastonehour_preview'] + 1000)
|
|
|
+ df['K2'] = df['ctr'].apply(lambda x: 0.6 if x > 0.6 else x)
|
|
|
+
|
|
|
+ df['platform_return_rate'] = df['platform_return'] / df['lastonehour_return']
|
|
|
+
|
|
|
+ df['score'] = df['share_rate'] ** 0.5 * df['back_rate'] ** 2 * df['log_back'] * df['K2'] ** 0.5
|
|
|
+
|
|
|
+ df = df.sort_values(by=['score'], ascending=False)
|
|
|
+ return df
|
|
|
+
|
|
|
+
|
|
|
def cal_score(df, param):
|
|
|
if param.get('return_data', None) == 'share_region_return':
|
|
|
if param.get('score_func', None) == 'multiply_return_retention':
|
|
@@ -396,6 +460,10 @@ def cal_score(df, param):
|
|
|
df = cal_score_with_back_view0(df=df, param=param)
|
|
|
elif param.get('score_func', None) == 'back_view1':
|
|
|
df = cal_score_with_back_view1(df=df, param=param)
|
|
|
+ elif param.get('score_func', None) == 'back_rate_exponential_weighting1':
|
|
|
+ df = cal_score_with_back_rate_exponential_weighting1(df=df, param=param)
|
|
|
+ elif param.get('score_func', None) == 'back_rate_exponential_weighting2':
|
|
|
+ df = cal_score_with_back_rate_exponential_weighting2(df=df, param=param)
|
|
|
else:
|
|
|
df = cal_score_initial(df=df, param=param)
|
|
|
return df
|
|
@@ -1088,7 +1156,7 @@ def h_timer_check():
|
|
|
project = config_.PROJECT_REGION_APP_TYPE
|
|
|
table = config_.TABLE_REGION_APP_TYPE
|
|
|
region_code_list = [code for region, code in region_code.items()]
|
|
|
- now_date = datetime.datetime.today()
|
|
|
+ now_date = datetime.datetime.today() - datetime.timedelta(hours=1)
|
|
|
log_.info(f"now_date: {datetime.datetime.strftime(now_date, '%Y%m%d%H')}, rule_rank_h_flag: {rule_rank_h_flag}")
|
|
|
now_h = datetime.datetime.now().hour
|
|
|
now_min = datetime.datetime.now().minute
|