|  | @@ -176,7 +176,7 @@ def cal_score_initial_20240223(df, param):
 | 
	
		
			
				|  |  |      df = df.sort_values(by=['score'], ascending=False)
 | 
	
		
			
				|  |  |      return df
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def cal_score_initial(df, param):
 | 
	
		
			
				|  |  | +def cal_score_initial(df, param, now_h):
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |      计算score
 | 
	
		
			
				|  |  |      :param df: 特征数据
 | 
	
	
		
			
				|  | @@ -190,13 +190,23 @@ def cal_score_initial(df, param):
 | 
	
		
			
				|  |  |      # score = sharerate * backrate * LOG(lastonehour_return+1) * K2
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      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)
 | 
	
		
			
				|  |  | +    # zhangbo
 | 
	
		
			
				|  |  | +    if now_h in [1,2,3,4]:
 | 
	
		
			
				|  |  | +        df['log_back'] = (df['lastonehour_allreturn'] + 1).apply(math.log)
 | 
	
		
			
				|  |  | +        df['share_rate'] = (df['lastonehour_share'] + 1) / (df['lastonehour_play'] + 1000)
 | 
	
		
			
				|  |  | +        df['back_rate'] = (df['lastonehour_return'] + 1) / (df['lastonehour_share'] + 10)
 | 
	
		
			
				|  |  | +    else:
 | 
	
		
			
				|  |  | +        df['log_back'] = (df['lastonehour_return'] + 1).apply(math.log)
 | 
	
		
			
				|  |  | +        df['share_rate'] = df['lastonehour_share'] / (df['lastonehour_play'] + 1000)
 | 
	
		
			
				|  |  | +        df['back_rate'] = df['lastonehour_return'] / (df['lastonehour_share'] + 10)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      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)
 | 
	
		
			
				|  |  | +        if now_h in [1, 2, 3, 4]:
 | 
	
		
			
				|  |  | +            df['ctr'] = (df['lastonehour_play'] + 1) / (df['lastonehour_show_region'] + 1000)
 | 
	
		
			
				|  |  | +        else:
 | 
	
		
			
				|  |  | +            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)
 | 
	
	
		
			
				|  | @@ -524,7 +534,7 @@ def cal_score_with_back_rate_by_rank_weighting(df, param):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def cal_score(df, param):
 | 
	
		
			
				|  |  | +def cal_score(df, param, now_h):
 | 
	
		
			
				|  |  |      if param.get('return_data', None) == 'share_region_return':
 | 
	
		
			
				|  |  |          if param.get('score_func', None) == 'multiply_return_retention':
 | 
	
		
			
				|  |  |              df = cal_score_multiply_return_retention_with_new_return(df=df, param=param)
 | 
	
	
		
			
				|  | @@ -550,7 +560,7 @@ def cal_score(df, param):
 | 
	
		
			
				|  |  |          elif param.get('score_func', None) == '20240223':
 | 
	
		
			
				|  |  |              df = cal_score_initial_20240223(df=df, param=param)
 | 
	
		
			
				|  |  |          else:
 | 
	
		
			
				|  |  | -            df = cal_score_initial(df=df, param=param)
 | 
	
		
			
				|  |  | +            df = cal_score_initial(df=df, param=param, now_h=now_h)
 | 
	
		
			
				|  |  |      return df
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -642,10 +652,17 @@ def video_rank(df, now_date, now_h, rule_key, param, region, data_key, rule_rank
 | 
	
		
			
				|  |  |      platform_return_rate = param.get('platform_return_rate', 0)
 | 
	
		
			
				|  |  |      # h_recall_df = df[(df['lastonehour_return'] >= return_count) & (df['score'] >= score_value)
 | 
	
		
			
				|  |  |      #                  & (df['platform_return_rate'] >= platform_return_rate)]
 | 
	
		
			
				|  |  | -    h_recall_df = df[
 | 
	
		
			
				|  |  | -        (df['lastonehour_return'] >= return_count) &
 | 
	
		
			
				|  |  | -        (df['score'] >= score_value) &
 | 
	
		
			
				|  |  | -        (df['platform_return_rate'] >= platform_return_rate)
 | 
	
		
			
				|  |  | +    # zhangbo
 | 
	
		
			
				|  |  | +    if now_h in [1, 2, 3, 4]:
 | 
	
		
			
				|  |  | +        h_recall_df = df[
 | 
	
		
			
				|  |  | +            (df['lastonehour_return'] > 0) |
 | 
	
		
			
				|  |  | +            (df['lastonehour_allreturn'] > 1)
 | 
	
		
			
				|  |  | +        ]
 | 
	
		
			
				|  |  | +    else:
 | 
	
		
			
				|  |  | +        h_recall_df = df[
 | 
	
		
			
				|  |  | +            (df['lastonehour_return'] >= return_count) &
 | 
	
		
			
				|  |  | +            (df['score'] >= score_value) &
 | 
	
		
			
				|  |  | +            (df['platform_return_rate'] >= platform_return_rate)
 | 
	
		
			
				|  |  |          ]
 | 
	
		
			
				|  |  |      if "lastonehour_allreturn" in param.keys():
 | 
	
		
			
				|  |  |          log_.info("采用 lastonehour_allreturn 过滤")
 | 
	
	
		
			
				|  | @@ -763,7 +780,7 @@ def process_with_region(region, df_merged, data_key, rule_key, rule_param, now_d
 | 
	
		
			
				|  |  |      log_.info(f"多协程的region = {region} 开始执行")
 | 
	
		
			
				|  |  |      region_df = df_merged[df_merged['code'] == region]
 | 
	
		
			
				|  |  |      log_.info(f'该区域region = {region}, 下有多少数据量 = {len(region_df)}')
 | 
	
		
			
				|  |  | -    score_df = cal_score(df=region_df, param=rule_param)
 | 
	
		
			
				|  |  | +    score_df = cal_score(df=region_df, param=rule_param, now_h=now_h)
 | 
	
		
			
				|  |  |      video_rank(df=score_df, now_date=now_date, now_h=now_h, rule_key=rule_key, param=rule_param,
 | 
	
		
			
				|  |  |                 region=region, data_key=data_key, rule_rank_h_flag=rule_rank_h_flag,
 | 
	
		
			
				|  |  |                 add_videos_with_pre_h=add_videos_with_pre_h, hour_count=hour_count)
 | 
	
	
		
			
				|  | @@ -861,7 +878,7 @@ def process_with_param(param, data_params_item, rule_params_item, region_code_li
 | 
	
		
			
				|  |  |          for apptype, weight in data_param.items():
 | 
	
		
			
				|  |  |              df = feature_df[feature_df['apptype'] == apptype]
 | 
	
		
			
				|  |  |              # 计算score
 | 
	
		
			
				|  |  | -            score_df = cal_score(df=df, param=rule_param)
 | 
	
		
			
				|  |  | +            score_df = cal_score(df=df, param=rule_param, now_h=now_h)
 | 
	
		
			
				|  |  |              score_df['score'] = score_df['score'] * weight
 | 
	
		
			
				|  |  |              score_df_list.append(score_df)
 | 
	
		
			
				|  |  |          # 分数合并
 |