|
@@ -14,7 +14,7 @@ curr_path = os.path.abspath(os.path.dirname(__file__))
|
|
project_root_path = curr_path[:curr_path.find("ai_target") + len("ai_target")]
|
|
project_root_path = curr_path[:curr_path.find("ai_target") + len("ai_target")]
|
|
sys.path.append(project_root_path)
|
|
sys.path.append(project_root_path)
|
|
|
|
|
|
-from config.url_and_db import estimate_people_number_url, headers, jeecg_db, jeecg_product_db, application_product_db
|
|
|
|
|
|
+from config.url_and_db import estimate_people_number_url, headers, jeecg_db, jeecg_product_db, application_product_db,application_inner_db
|
|
from utils.BaseClass import NpEncoder
|
|
from utils.BaseClass import NpEncoder
|
|
from utils.commonFunc import age_code_transform, gender_code_transform
|
|
from utils.commonFunc import age_code_transform, gender_code_transform
|
|
|
|
|
|
@@ -30,7 +30,8 @@ class GetSingleDimFeatures(object):
|
|
计算素材单维度滑窗组合转化占比情况
|
|
计算素材单维度滑窗组合转化占比情况
|
|
"""
|
|
"""
|
|
|
|
|
|
- def __init__(self, signature, dim, dim_config):
|
|
|
|
|
|
+ def __init__(self, signature, dim, dim_config, project_id):
|
|
|
|
+ self.project_id = project_id
|
|
self.signature = signature
|
|
self.signature = signature
|
|
self.dim = dim
|
|
self.dim = dim
|
|
self.dim_config = dim_config
|
|
self.dim_config = dim_config
|
|
@@ -60,8 +61,9 @@ class GetSingleDimFeatures(object):
|
|
def get_features(self):
|
|
def get_features(self):
|
|
# 1、获取素材在指定维度下的人群数据
|
|
# 1、获取素材在指定维度下的人群数据
|
|
get_audience_sql = f"select signature, {self.filed_name}, sum(activation) activation " \
|
|
get_audience_sql = f"select signature, {self.filed_name}, sum(activation) activation " \
|
|
- f"from {self.table} where signature = '{self.signature}' group by signature, {self.filed_name}"
|
|
|
|
- audience_df = pd.read_sql(get_audience_sql, jeecg_product_db)
|
|
|
|
|
|
+ f"from {self.table} where signature = '{self.signature}' and project_id = {self.project_id} " \
|
|
|
|
+ f"group by signature, {self.filed_name}"
|
|
|
|
+ audience_df = pd.read_sql(get_audience_sql, application_inner_db)
|
|
for combine in self.window_combine:
|
|
for combine in self.window_combine:
|
|
if combine != ['不限']:
|
|
if combine != ['不限']:
|
|
self.features['|'.join(combine)] = round(audience_df[audience_df[self.filed_name].isin(combine)].activation.sum() / \
|
|
self.features['|'.join(combine)] = round(audience_df[audience_df[self.filed_name].isin(combine)].activation.sum() / \
|
|
@@ -142,20 +144,24 @@ if __name__ == '__main__':
|
|
logger.info(f"开始获取项目{project_id}的当前活跃素材")
|
|
logger.info(f"开始获取项目{project_id}的当前活跃素材")
|
|
# 4.1 获取指定项目下当前活跃的素材信息
|
|
# 4.1 获取指定项目下当前活跃的素材信息
|
|
# 如近60天内累计激活个数达到100个(开发环境或者生产环境,这部分都读取生产数据库)
|
|
# 如近60天内累计激活个数达到100个(开发环境或者生产环境,这部分都读取生产数据库)
|
|
- start_date = datetime.datetime.now().date() + datetime.timedelta(days=-config['activeMaterialFilterRule']['days'])
|
|
|
|
|
|
+ days = config['activeMaterialFilterRule']['days']
|
|
|
|
+ activation_sum = config['activeMaterialFilterRule']['activation']
|
|
|
|
+ pay_first_pct = config['activeMaterialFilterRule']['event_pay_first_day_pct']
|
|
sql = f"select signature from kuaishou_material_video_report_daily_dw where project_id = {project_id} " \
|
|
sql = f"select signature from kuaishou_material_video_report_daily_dw where project_id = {project_id} " \
|
|
- f"and stat_date >= {start_date.year * 10000 + start_date.month * 100 + start_date.day} group by signature " \
|
|
|
|
- f"having sum(activation) >= {config['activeMaterialFilterRule']['activation']} " \
|
|
|
|
- f"and sum(event_pay_first_day) / sum(activation) >= {config['activeMaterialFilterRule']['event_pay_first_day_pct']}"
|
|
|
|
- df = pd.read_sql(sql, application_product_db)
|
|
|
|
|
|
+ f"and stat_date >= date_format(date_sub(now(), interval {days} DAY),'%%Y%%m%%d') group by signature " \
|
|
|
|
+ f"having sum(activation) >= {activation_sum} " \
|
|
|
|
+ f"and sum(event_pay_first_day) / sum(activation) >= {pay_first_pct}"
|
|
|
|
+
|
|
|
|
+ df = pd.read_sql(sql, application_inner_db)
|
|
active_signatures = list(df[~df.signature.isnull()].signature.values)
|
|
active_signatures = list(df[~df.signature.isnull()].signature.values)
|
|
active_signatures = active_signatures * 2 if len(active_signatures) == 1 else active_signatures
|
|
active_signatures = active_signatures * 2 if len(active_signatures) == 1 else active_signatures
|
|
|
|
|
|
# 4.2 在素材人群报表筛选里面累计100个激活
|
|
# 4.2 在素材人群报表筛选里面累计100个激活
|
|
logger.info(f"开始获取项目{project_id}的活跃素材的人群分析报表")
|
|
logger.info(f"开始获取项目{project_id}的活跃素材的人群分析报表")
|
|
- sql = f"select signature from ctop_kuaishou_audience_report_daily_age_material where signature in {tuple(active_signatures)} " \
|
|
|
|
|
|
+ sql = f"select signature from kuaishou_unit_audience_age_report_daily_d where signature in {tuple(active_signatures)} " \
|
|
|
|
+ f"and project_id = {project_id} " \
|
|
f"group by signature having sum(activation) >= {config['getBaysCombineMaterialFilterRule']['activation']}"
|
|
f"group by signature having sum(activation) >= {config['getBaysCombineMaterialFilterRule']['activation']}"
|
|
- df = pd.read_sql(sql, jeecg_product_db)
|
|
|
|
|
|
+ df = pd.read_sql(sql, application_inner_db)
|
|
signature_lst = df['signature'].values
|
|
signature_lst = df['signature'].values
|
|
|
|
|
|
# 这行代码用于测试
|
|
# 这行代码用于测试
|
|
@@ -166,7 +172,7 @@ if __name__ == '__main__':
|
|
try:
|
|
try:
|
|
feature_lst = []
|
|
feature_lst = []
|
|
for dimension in target_dim:
|
|
for dimension in target_dim:
|
|
- get_single_fea_ins = GetSingleDimFeatures(sig, dimension, config['bayesDim'][dimension])
|
|
|
|
|
|
+ get_single_fea_ins = GetSingleDimFeatures(sig, dimension, config['bayesDim'][dimension], project_id)
|
|
# 计算滑窗组合
|
|
# 计算滑窗组合
|
|
get_single_fea_ins.get_window_combine()
|
|
get_single_fea_ins.get_window_combine()
|
|
get_single_fea_ins.get_features()
|
|
get_single_fea_ins.get_features()
|