|
@@ -81,25 +81,30 @@ def predict_ad_group_video():
|
|
|
video_df = pd.DataFrame(data=video_data, columns=['videoid', 'video_ad_share_rate'])
|
|
|
video_df = video_df[video_df['videoid'] != -1]
|
|
|
log_.info(f"video_df count = {len(video_df)}")
|
|
|
+
|
|
|
predict_df = video_df
|
|
|
- threshold_data = {}
|
|
|
all_group_data = []
|
|
|
for index, item in group_df.iterrows():
|
|
|
predict_df[item['group']] = predict_df['video_ad_share_rate'] * item['group_ad_share_rate']
|
|
|
- # 获取分组对应的均值作为阈值
|
|
|
- threshold_data[item['group']] = predict_df[item['group']].mean() / 48 * 25
|
|
|
all_group_data.extend(predict_df[item['group']].tolist())
|
|
|
- threshold_data['mean_group'] = np.mean(all_group_data) / 48 * 25
|
|
|
- log_.info(f"threshold_data = {threshold_data}")
|
|
|
- # 将阈值写入redis
|
|
|
- for key, val in threshold_data.items():
|
|
|
- key_name = f"{config_.KEY_NAME_PREFIX_AD_THRESHOLD}{key}"
|
|
|
- redis_helper.set_data_to_redis(key_name=key_name, value=val, expire_time=2 * 24 * 3600)
|
|
|
+
|
|
|
+ # 计算对应的阈值
|
|
|
+ for app_type in config_.AD_APP_TYPE_LIST:
|
|
|
+ ad_threshold_mapping = config_.AD_THRESHOLD_MAPPING.get(app_type)
|
|
|
+ threshold_data = {}
|
|
|
+ for _, item in group_df.iterrows():
|
|
|
+ # 获取分组对应的均值作为阈值
|
|
|
+ threshold_data[item['group']] = predict_df[item['group']].mean() * ad_threshold_mapping['group']
|
|
|
+ threshold_data['mean_group'] = np.mean(all_group_data) * ad_threshold_mapping['mean_group']
|
|
|
+ log_.info(f"app_type = {app_type}, threshold_data = {threshold_data}")
|
|
|
+ # 将阈值写入redis
|
|
|
+ for key, val in threshold_data.items():
|
|
|
+ key_name = f"{config_.KEY_NAME_PREFIX_AD_THRESHOLD}{app_type}:{key}"
|
|
|
+ redis_helper.set_data_to_redis(key_name=key_name, value=val, expire_time=2 * 24 * 3600)
|
|
|
|
|
|
predict_df.to_csv('./data/ad_user_video_predict.csv')
|
|
|
- return predict_df
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- predict_df = predict_ad_group_video()
|
|
|
+ predict_ad_group_video()
|
|
|
|