|
@@ -62,10 +62,10 @@ class BayesFeatures(object):
|
|
|
sum(activation) activation
|
|
|
from %s
|
|
|
where signature = '%s'
|
|
|
- -- and datediff(now(),stat_date)<=30
|
|
|
+ and datediff(now(),stat_date)<=30
|
|
|
group by signature, %s
|
|
|
''' % (self.file_name, self.table, self.signature, self.file_name)
|
|
|
- df = pd.read_sql(sql, engine)
|
|
|
+ df = pd.read_sql(sql, product_engine)
|
|
|
|
|
|
if self.target_type == 'action_ratio':
|
|
|
# 计算行为率(bclick/aclick)的组合特征值
|
|
@@ -83,7 +83,7 @@ class BayesFeatures(object):
|
|
|
get_city_sql = """
|
|
|
select city_name from ctop_kuaishou_city_level where city_level = '%s'
|
|
|
""" % city_level
|
|
|
- city_df = pd.read_sql(get_city_sql, engine)
|
|
|
+ city_df = pd.read_sql(get_city_sql, product_engine)
|
|
|
city_lst.extend(city_df['city_name'].values)
|
|
|
pos_pct = df[df[self.file_name].isin(city_lst)].bclick.sum() / df.bclick.sum()
|
|
|
neg_pct = df[df[self.file_name].isin(city_lst)].unbclick.sum() / df.unbclick.sum()
|
|
@@ -107,7 +107,7 @@ class BayesFeatures(object):
|
|
|
get_city_sql = """
|
|
|
select city_name from ctop_kuaishou_city_level where city_level = '%s'
|
|
|
""" % city_level
|
|
|
- city_df = pd.read_sql(get_city_sql, engine)
|
|
|
+ city_df = pd.read_sql(get_city_sql, product_engine)
|
|
|
city_lst.extend(city_df['city_name'].values)
|
|
|
pos_pct = df[df[self.file_name].isin(city_lst)].activation.sum() / df.activation.sum()
|
|
|
neg_pct = df[df[self.file_name].isin(city_lst)].unactivation.sum() / df.unactivation.sum()
|
|
@@ -140,9 +140,9 @@ class BayesCombine(object):
|
|
|
get_sample_and_pct_sql = """
|
|
|
select sum(aclick) aclick, sum(bclick) bclick, sum(activation) activation from %s where
|
|
|
signature = '%s'
|
|
|
- -- and datediff(now(),stat_date)<=30
|
|
|
- """ % (config['bayesDim']['age']['table'],self.signature)
|
|
|
- sample_pct_df = pd.read_sql(get_sample_and_pct_sql, engine)
|
|
|
+ and datediff(now(),stat_date)<=30
|
|
|
+ """ % (config['bayesDim']['age']['table'], self.signature)
|
|
|
+ sample_pct_df = pd.read_sql(get_sample_and_pct_sql, product_engine)
|
|
|
if self.target_type == 'action_ratio':
|
|
|
self.sig_pos_pct = sample_pct_df['bclick'].sum() / sample_pct_df['aclick'].sum()
|
|
|
self.sig_neg_pct = 1 - self.sig_pos_pct
|
|
@@ -176,7 +176,7 @@ class BayesCombine(object):
|
|
|
# 获取该项目下在投的账号
|
|
|
get_acc_sql = """select account_id from ctop_user_allocation where project_id = %s and account_status=0 limit 1""" % \
|
|
|
self.project_id
|
|
|
- account_df = pd.read_sql(get_acc_sql, engine)
|
|
|
+ account_df = pd.read_sql(get_acc_sql, product_engine)
|
|
|
account_id = account_df['account_id'].values[0]
|
|
|
request_data = {'region': city_code_transform(out_dict.get('city')),
|
|
|
'ages_range': age_code_transform(out_dict.get('age')),
|
|
@@ -213,13 +213,14 @@ if __name__ == '__main__':
|
|
|
else:
|
|
|
engine = get_db_engine(config['productDB'])
|
|
|
|
|
|
+ product_engine = get_db_engine(config['productDB'])
|
|
|
+
|
|
|
# 2、 参与定向组合的维度
|
|
|
target_dim = [key for key in config['bayesDim'].keys() if config['bayesDim'][key]['isOn']]
|
|
|
|
|
|
# 4、计算贝叶斯组合入库
|
|
|
for project_id in config['projectId']:
|
|
|
# 4.1 获取指定项目下当前活跃的素材信息, 如近3天内累计激活个数达到50个(开发环境或者生产环境,这部分都读取生产数据库)
|
|
|
- product_engine = get_db_engine(config['productDB'])
|
|
|
sql = '''
|
|
|
select signature from ctop_kuaishou_report_daily_material
|
|
|
where account_id in (select account_id from ctop_user_allocation where project_id = %s)
|
|
@@ -233,19 +234,20 @@ if __name__ == '__main__':
|
|
|
active_signatures = df[~df.signature.isnull()].signature.values
|
|
|
|
|
|
# 4.2 在素材人群报表筛选里面近一个月累计100个激活
|
|
|
- # TODO 等生产的素材人群表存在之后,修改表名,添加 days
|
|
|
sql = """
|
|
|
- select signature from ctop_kuaishou_audience_daily_report_by_signature_age
|
|
|
+ select signature from ctop_kuaishou_audience_report_daily_age_material
|
|
|
where signature in %s
|
|
|
+ and datediff(now(),stat_date) <= %s
|
|
|
group by signature
|
|
|
having sum(activation) >= %s
|
|
|
""" % (tuple(active_signatures),
|
|
|
+ config['getBaysCombineMaterialFilterRule']['days'],
|
|
|
config['getBaysCombineMaterialFilterRule']['activation'])
|
|
|
- df = pd.read_sql(sql, engine)
|
|
|
+ df = pd.read_sql(sql, product_engine)
|
|
|
signature_lst = df['signature'].values
|
|
|
|
|
|
- # TODO 这行代码用于测试
|
|
|
- signature_lst = ['0070efb7557b2a04cf3d4a6f243c3cd8', '03b93728f0d82ea7865c3c7cf632bc1b']
|
|
|
+ # 这行代码用于测试
|
|
|
+ # signature_lst = ['0070efb7557b2a04cf3d4a6f243c3cd8', '03b93728f0d82ea7865c3c7cf632bc1b']
|
|
|
|
|
|
# 4.2 计算指定素材的贝叶斯特征
|
|
|
for sig in signature_lst:
|