
import datetime
import traceback
from threading import Timer
from my_utils import RedisHelper, data_check, get_feature_data, send_msg_to_feishu
from my_config import set_config
from log import Log
config_, _ = set_config()
log_ = Log()
redis_helper = RedisHelper()

if __name__ == '__main__':
    model_key = 'ad_out_v1'
    configs = {
        '173-u': {
            'threshold': 0.28,
            'item_threshold': 0.45,
            'user_threshold': 0.334571,
            'miss_threshold': 0.0,
            'use_backup': 'false'
        },
        '173-v': {
            'threshold': 0.273169,
            'item_threshold': 0.45,
            'user_threshold': 0.334571,
            'miss_threshold': 0.0,
            'use_backup': 'false'
        },
        '243-i': {
            'threshold': 0.273169,
            'item_threshold': 0.45,
            'user_threshold': 0.334571,
            'miss_threshold': 0.0,
            'use_backup': 'false'
        },
    }
    # abtest_id = '173'
    # abtest_config_tag_list = ['u', 'v']
    expire_time = 30 * 24 * 3600
    for abtest_key, abtest_config in configs.items():
        print(abtest_key)
        abtest_id, abtest_config_tag = abtest_key.split('-')
        config_key_prefix = f"{config_.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG}{model_key}:{abtest_id}:{abtest_config_tag}"
        for k, v in abtest_config.items():
            k_key = f"{config_key_prefix}:{k}"
            k_value = redis_helper.get_data_from_redis(key_name=k_key)
            print(k_key, k_value, type(k_value))
            redis_helper.set_data_to_redis(k_key, v, expire_time)

