liqian 2 年之前
父節點
當前提交
453781041a
共有 2 個文件被更改,包括 24 次插入15 次删除
  1. 18 13
      ad_threshold_auto_update.py
  2. 6 2
      config.py

+ 18 - 13
ad_threshold_auto_update.py

@@ -61,12 +61,11 @@ def update_threshold(threshold_record_old, threshold_record_new):
             if threshold_old is None:
                 continue
             # 计算新的阈值
-            log_.info(f"{threshold_old}, {threshold_param_old}, {threshold_param_new}")
             threshold_new = float(threshold_old) / threshold_param_old * threshold_param_new
             log_.info(f"ad_abtest_tag = {ad_abtest_tag}, group_key = {group_key}, "
                       f"threshold_old = {threshold_old}, threshold_new = {threshold_new}")
             # 更新redis
-            # redis_helper.set_data_to_redis(key_name=key_name, value=threshold_new)
+            redis_helper.set_data_to_redis(key_name=key_name, value=threshold_new)
 
 
 def update_ad_abtest_threshold(project, table, dt, ad_abtest_abcode_config):
@@ -81,13 +80,13 @@ def update_ad_abtest_threshold(project, table, dt, ad_abtest_abcode_config):
     # 根据活跃人数变化计算新的阈值参数
     threshold_record_new = get_threshold_record_new(ad_abtest_abcode_config=ad_abtest_abcode_config,
                                                     feature_df=feature_df, threshold_record=threshold_record)
-    log_.info(f"threshold_record = {threshold_record}")
     log_.info(f"threshold_record_new = {threshold_record_new}")
     # 更新阈值
     update_threshold(threshold_record_old=threshold_record, threshold_record_new=threshold_record_new)
     # 更新阈值参数
-    # redis_helper.set_data_to_redis(key_name=config_.KEY_NAME_PREFIX_AD_THRESHOLD_RECORD,
-    #                                value=str(threshold_record_new))
+    redis_helper.set_data_to_redis(key_name=config_.KEY_NAME_PREFIX_AD_THRESHOLD_RECORD,
+                                   value=str(threshold_record_new))
+    return threshold_record, threshold_record_new
 
 
 def timer_check():
@@ -105,16 +104,22 @@ def timer_check():
         if data_count > 0:
             log_.info(f"data count = {data_count}")
             # 数据准备好,进行更新
-            update_ad_abtest_threshold(project=project, table=table, dt=dt,
-                                       ad_abtest_abcode_config=ad_abtest_abcode_config)
+            threshold_record, threshold_record_new = update_ad_abtest_threshold(
+                project=project, table=table, dt=dt, ad_abtest_abcode_config=ad_abtest_abcode_config)
+            send_msg_to_feishu(
+                webhook=config_.FEISHU_ROBOT['ad_threshold_auto_update_robot'].get('webhook'),
+                key_word=config_.FEISHU_ROBOT['ad_threshold_auto_update_robot'].get('key_word'),
+                msg_text=f"rov-offline{config_.ENV_TEXT} - 阈值更新完成!\n"
+                         f"threshold_param_old: {threshold_record}\n"
+                         f"threshold_param_new: {threshold_record_new}\n"
+            )
             log_.info(f"threshold update end!")
         elif now_min > 45:
             log_.info('threshold update data is None!')
             send_msg_to_feishu(
-                webhook=config_.FEISHU_ROBOT['server_robot'].get('webhook'),
-                key_word=config_.FEISHU_ROBOT['server_robot'].get('key_word'),
+                webhook=config_.FEISHU_ROBOT['ad_threshold_auto_update_robot'].get('webhook'),
+                key_word=config_.FEISHU_ROBOT['ad_threshold_auto_update_robot'].get('key_word'),
                 msg_text=f"rov-offline{config_.ENV_TEXT} - 阈值更新相关数据未准备好!\n"
-                         f"traceback: {traceback.format_exc()}"
             )
         else:
             # 数据没准备好,1分钟后重新检查
@@ -123,8 +128,8 @@ def timer_check():
     except Exception as e:
         log_.error(f"阈值更新失败, exception: {e}, traceback: {traceback.format_exc()}")
         send_msg_to_feishu(
-            webhook=config_.FEISHU_ROBOT['server_robot'].get('webhook'),
-            key_word=config_.FEISHU_ROBOT['server_robot'].get('key_word'),
+            webhook=config_.FEISHU_ROBOT['ad_threshold_auto_update_robot'].get('webhook'),
+            key_word=config_.FEISHU_ROBOT['ad_threshold_auto_update_robot'].get('key_word'),
             msg_text=f"rov-offline{config_.ENV_TEXT} - 阈值更新失败\n"
                      f"exception: {e}\n"
                      f"traceback: {traceback.format_exc()}"
@@ -132,4 +137,4 @@ def timer_check():
 
 
 if __name__ == '__main__':
-    timer_check()
+    timer_check()

+ 6 - 2
config.py

@@ -41,6 +41,10 @@ class BaseConfig(object):
         'feature_monitor_robot': {
             'webhook': 'https://open.feishu.cn/open-apis/bot/v2/hook/0ca66b89-5e2b-4e89-a04a-a01fda31cc89',
             'key_word': 'ROV特征监控'
+        },
+        'ad_threshold_auto_update_robot': {
+            'webhook': 'https://open.feishu.cn/open-apis/bot/v2/hook/f2494511-18b8-4fa9-8073-91a089dd4bf3',
+            'key_word': '广告模型阈值调整'
         }
     }
 
@@ -1187,8 +1191,8 @@ class ProductionConfig(BaseConfig):
 
 def set_config():
     # 获取环境变量 ROV_OFFLINE_ENV
-    # env = os.environ.get('ROV_OFFLINE_ENV')
-    env = 'dev'
+    env = os.environ.get('ROV_OFFLINE_ENV')
+    # env = 'dev'
     if env is None:
         # log_.error('ENV ERROR: is None!')
         return