liyuyi@c-top.com.cn 4 年 前
コミット
993817ab0c

+ 3 - 1
BayesCombine.py

@@ -185,6 +185,7 @@ if __name__ == '__main__':
     else:
         engine = get_db_engine(config['productDB'])
 
+
     # 2、 参与定向组合的维度
     target_dim = [key for key in config['bayesDim'].keys() if config['bayesDim'][key]['isOn']]
 
@@ -204,7 +205,8 @@ if __name__ == '__main__':
         df = pd.read_sql(sql, product_engine)
         active_signatures = df[~df.signature.isnull()].signature.values
 
-        # 4.2 在素材人群报表筛选里面近一个月累计100个激活 TODO 等生产的素材人群表存在之后,修改表名,添加 days
+        # 4.2 在素材人群报表筛选里面近一个月累计100个激活
+        # TODO 等生产的素材人群表存在之后,修改表名,添加 days
         sql = """
         select signature from ctop_kuaishou_audience_daily_report_by_signature_age  
         where signature in %s

+ 10 - 5
ai_target_combine_handler.py

@@ -72,7 +72,7 @@ class AiTargetCombine(tornado.web.RequestHandler):
             self.write(json.dumps({"account_id": account_id, "message": "异步执行", "code": 1}))
             self.flush()
         except:
-            logger.error("account_id = %s, traceback is %s" % (ins.account_id, traceback.format_exc()))
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
             self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
             self.flush()
 
@@ -95,7 +95,7 @@ class GetTargetAndAssemblyParameters(object):
         self.get_database_engine()  # 获取数据库信息
         self.get_advertiser_strategy_info()  # 获取账户配置信息
         self.get_signature_and_target()  # 获取定向组合
-        self.target_combine_is_subset()  # 过滤出为账户相信子集的定向组合
+        self.target_combine_is_subset()  # 过滤出为账户配置子集的定向组合
 
     def get_database_engine(self):
         # 数据库连接引擎,依据开发环境/生产环境 进行切换
@@ -255,8 +255,13 @@ class GetTargetAndAssemblyParameters(object):
                 target_combine.update(region_dict) if 'city' in item.keys() else None
                 self.final_target_combine.append(target_combine)
             else:
-                # TODO logger
-                pass
+                logger.info("推荐定向:%s 与 账户配置信息里的定向(gender:%s, age_min: %s,age_max: %s, ages_ranges:%s,region:%s )存在冲突" %
+                            (item,
+                             self.advertiser_strategy['gender'],
+                             self.advertiser_strategy['age_min'],
+                             self.advertiser_strategy['age_max'],
+                             self.advertiser_strategy['ages_range'],
+                             self.advertiser_strategy['region']))
 
         # 从集合中随机选取N个组合
         combine_cnt = config['filterTargetCombine']['combineCnt']
@@ -495,7 +500,7 @@ class GetTargetAndAssemblyParameters(object):
         group_params_to_db['message'] = None
 
         # 6、用于组装发送请求的部分字段,需要转化为list类型
-        cols_to_list = ['app_store', 'scene_id', 'region','day_budget_schedule', 'ages_range', 'device_brand', 'business_interest',
+        cols_to_list = ['app_store', 'scene_id', 'region', 'day_budget_schedule', 'ages_range', 'device_brand', 'business_interest',
                         'fans_star', 'interest_video', 'app_interest', 'app_interest_ids', 'app_ids', 'population','district_ids',
                         'exclude_population', 'paid_audience']
         for col in cols_to_list:

+ 1 - 1
time_task/time_task_create_ad_by_target.py

@@ -60,7 +60,7 @@ account_df.drop_duplicates('account_id', keep='first', inplace=True)
 acc_list = [(item['account_id'], item['project_id']) for index, item in account_df.iterrows()]
 
 # for test
-acc_list = [(9774238, 458)] * 6
+acc_list = [(9774238, 458)] * 1
 
 # 2、 5个账户一组进行发送请求
 batch_num = 5

+ 41 - 30
utils/commonFunc.py

@@ -1,6 +1,10 @@
 from sqlalchemy import create_engine
 from urllib import parse
 import pandas as pd
+import yaml
+
+with open('../config/config.yaml', mode='r', encoding='utf-8') as f:
+    config = yaml.load(f.read(), Loader=yaml.FullLoader)
 
 
 def update_dict(x, y):
@@ -21,6 +25,7 @@ def get_db_engine(db_info):
     return engine
 
 
+
 def is_contains_region(val1, val2):
     """
     level1
@@ -31,24 +36,25 @@ def is_contains_region(val1, val2):
     :param val2: 从账户配置信息表里读取的地区信息, 如 '[]', None, '[14,15,21,22,23,31,32]'
     :return:
     """
-    if val1 == '不限' or val1 is None:
-        if val2 is None or val2 == '[]':
-            return True, {'region': None}
-        else:
-            return False, -1
+    # 如果val1为空,表示该字段没有参与定向组合运算,就直接取客户投放策略里面的值
+    if val1 is None:
+        return True, {'region': val2}
+
+    sql = """
+                select t1.city_name, t2.level, t2.region_id, t2.parent from ctop_kuaishou_city_level t1
+                left join ctop_kuaishou_region_list_parent t2
+                on t1.city_name = t2.name
+                where t1.city_level in %s
+                """ % (tuple(val1.split('|')),)
+    city_df = pd.read_sql(sql, get_db_engine(config['productDB']))
+
+    if not val2 or val2 == '不限' or val2 == '[]':
+        return True, {'region': list(city_df['region_id'].values)}
     else:
-        if val2 is None or val2 == '[]':
+        if val1 == '不限':
             return False, -1
         else:
             val = []
-            sql = """
-            select t1.city_name, t2.level, t2.region_id, t2.parent from ctop_kuaishou_city_level t1
-            left join ctop_kuaishou_region_list_parent t2
-            on t1.city_name = t2.name
-            where t1.city_level in %s
-            """ % (tuple(val1.split('|')),)
-            city_df = pd.read_sql(sql, None)
-
             # level1
             if set(city_df[city_df.level == 1].region_id.values).issubset(set(eval(val2))):
                 val.extend(city_df[city_df.level == 1].region_id.values)
@@ -129,24 +135,29 @@ def is_contains_age(val1, val2_min, val2_max, val2_range):
     与age不能同时传;【18:表示18-23岁】;【24:表示24-30岁】;【31:表示31-40岁】;【41:表示41-49岁】;【50:表示50-100岁】
     :return:
     """
+    # 如果val1为空,表示该字段没有参与定向组合运算,就直接取客户投放策略里面的值
+    if val1 is None:
+        return True, {'age_min': val2_min, 'age_max': val2_max, 'ages_range': val2_range}
+
     age_dict = {'18-23岁': 18, '24-30岁': 24, '31-40岁': 31, '41-49岁': 41, '50+岁': 50, '50-100岁': 50}
-    if val1 == '不限' or not val1:
-        if (not val2_min) and (not val2_max) and (not val2_range or val2_range == '不限'):
-            return True, {'ages_range': None}
-        else:
-            return False, -1
+
+    if (not val2_min) and (not val2_max) and (not val2_range or val2_range == '不限'):
+        return True, {'ages_range': val1}
     else:
-        age1 = [age_dict[item] for item in val1.split('|')]
-        if (val2_min is None and val2_max is None) and val2_range:
-            if set(age1).issubset(set(eval(val2_range))):
-                return True, {'ages_range': age1}
-            else:
-                return False, -1
-        if (val2_min and val2_max) and (not val2_range):
-            if age1[0] >= val2_min and age1[-1] <= val2_max:
-                return True, {'age_min': age1[0], 'age_max': age1[-1]}
-            else:
-                return False, -1
+        if val1 == '不限':
+            return False, -1
+        else:
+            age1 = [age_dict[item] for item in val1.split('|')]
+            if (val2_min is None and val2_max is None) and val2_range:
+                if set(age1).issubset(set(eval(val2_range))):
+                    return True, {'ages_range': age1}
+                else:
+                    return False, -1
+            if (val2_min and val2_max) and (not val2_range):
+                if age1[0] >= val2_min and age1[-1] <= val2_max:
+                    return True, {'age_min': age1[0], 'age_max': age1[-1]}
+                else:
+                    return False, -1
 
 
 def is_contains_business_interest(val1, val2):