Browse Source

update ad_threshold_auto_update.py

liqian 2 years ago
parent
commit
ad7d4342d1
1 changed files with 12 additions and 4 deletions
  1. 12 4
      ad_threshold_auto_update.py

+ 12 - 4
ad_threshold_auto_update.py

@@ -178,11 +178,19 @@ def update_threshold(threshold_record_old, threshold_record_new):
                         continue
                     # 计算新的阈值
                     if group_key == 'mean_group':
-                        threshold_new = \
-                            float(threshold_old) / threshold_param_old['mean_group'] * threshold_param_new['mean_group']
+                        if threshold_param_old['mean_group'] == 0:
+                            threshold_new = \
+                                float(threshold_old) / 10**(-5) * threshold_param_new['mean_group']
+                        else:
+                            threshold_new = \
+                                float(threshold_old) / threshold_param_old['mean_group'] * threshold_param_new['mean_group']
                     else:
-                        threshold_new = \
-                            float(threshold_old) / threshold_param_old['group'] * threshold_param_new['group']
+                        if threshold_param_old['group'] == 0:
+                            threshold_new = \
+                                float(threshold_old) / 10**(-5) * threshold_param_new['group']
+                        else:
+                            threshold_new = \
+                                float(threshold_old) / threshold_param_old['group'] * threshold_param_new['group']
 
                     # 更新redis
                     redis_helper.set_data_to_redis(key_name=key_name, value=threshold_new, expire_time=2 * 24 * 3600)