def update_campaign(shop_id, campaign_id, tapi = None, record_flag = True, opter = 1, opter_name = '', **para): if not tapi: tapi = get_tapi(shop_id = shop_id) result_list, msg_list, record_list = Campaign.update_campaign_inner(shop_id = int(shop_id), campaign_id = campaign_id, tapi = tapi, opter = opter, opter_name = opter_name, **para) if record_list and record_flag: rcd_list = [UploadRecord(**record) for record in record_list] UploadRecord.objects.insert(rcd_list) return result_list, msg_list
def check_case_3(): # 无点击, 连续3天有展现,点击为零 csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', '3_day_impr', '3_day_click'] local_camp_list = Campaign.objects(Q(online_status = 'online')).order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(Q(online_status = 'online') & Q(campaign_id = local_camp.campaign_id)).sum_reports(rpt_days = 3) # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: print 'camp_id=%s adg_id=%s qr.impr=%s qr.click=%s' % (local_camp.campaign_id, local_adg.adgroup_id, local_adg.qr.impressions, local_adg.qr.click) if local_adg.qr.impressions > 0 and local_adg.qr.click == 0: csv_data_list.append([ local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, local_adg.qr.impressions, local_adg.qr.click]) export_to_file('(check_case_3)', csv_title, csv_data_list)
def check_case_2(): # 质量得分低, 平均质量得分小于6.5,小于5分的词大于40% csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', 'kw_avg', 'kw_rate'] local_camp_list = Campaign.objects(Q(online_status = 'online')).order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(Q(online_status = 'online') & Q(campaign_id = local_camp.campaign_id)) # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: avg = get_avg_qscore(local_adg.adgroup_id) rate = get_qscore_rate(local_adg.adgroup_id) print 'camp_id=%s adg_id=%s avg=%s rate=%s' % (local_camp.campaign_id, local_adg.adgroup_id, avg, rate) if avg and rate and avg < 6.5 and rate > 0.4: csv_data_list.append([ local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, avg, rate]) export_to_file('(check_case_2)', csv_title, csv_data_list)
def check_case_1(): # 词少, 关键词少于100个 csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', 'kw_count'] local_camp_list = Campaign.objects(online_status = 'online').order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(online_status = 'online', campaign_id = local_camp.campaign_id).order_by('adgroup_id') # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: local_kw_list = Keyword.objects.only('word').filter(adgroup_id = local_adg.adgroup_id) kw_count = len(local_kw_list) print 'camp_id=%s adg_id=%s kw_count=%s' % (local_camp.campaign_id, local_adg.adgroup_id, kw_count) if kw_count < 100: csv_data_list.append([local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, kw_count]) export_to_file('(check_case_1)', csv_title, csv_data_list)
def check_case_7(): # 点击转化率低, 点击转化率低于市场点击率的100% csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', 'kw_count', '7_day_conv', 'cat_avg_conv'] local_camp_list = Campaign.objects(Q(online_status = 'online')).order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(Q(online_status = 'online') & Q(campaign_id = local_camp.campaign_id)).sum_reports(rpt_days = 7) # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: item = local_adg.item cat_data = local_adg.cat_data conv = local_adg.qr.conv cat_avg_conv = get_cat_avg_conv(item, cat_data) print 'camp_id=%s adg_id=%s qr.conv=%s cat.avg_conv=%s' % (local_camp.campaign_id, local_adg.adgroup_id, conv, cat_avg_conv) if cat_avg_conv and conv < cat_avg_conv * 1.0: csv_data_list.append([ local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, conv, cat_avg_conv]) export_to_file('(check_case_7)', csv_title, csv_data_list)
def check_case_6(): # 点击率低, 点击率低于市场点击率的70% csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', '7_day_ctr', 'cat_avg_ctr'] local_camp_list = Campaign.objects(Q(online_status = 'online')).order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(Q(online_status = 'online') & Q(campaign_id = local_camp.campaign_id)).sum_reports(rpt_days = 7) # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: item = local_adg.item_id cat_data = local_adg.cat_data ctr = local_adg.qr.ctr cat_avg_ctr = get_cat_avg_ctr(item, cat_data) print 'camp_id=%s adg_id=%s ctr=%s cat.avg_ctr=%s' % (local_camp.campaign_id, local_adg.adgroup_id, ctr, cat_avg_ctr) if cat_avg_ctr and local_adg.qr.ctr < cat_avg_ctr * 0.7: csv_data_list.append([ local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, ctr]) export_to_file('(check_case_6)', csv_title, csv_data_list)
def check_case_5(): # PPC高, 高于市场均价的1.2倍,大于 min(客单价*行业转化率/roi, 每个 关键词点击量*行业ppc 的和/所有点击, 日限额/50) csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', 'ppc', 'cat_avg_ppc', 'roi', 'cat_avg_conv', 'budget'] local_camp_list = Campaign.objects(Q(online_status = 'online')).order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(Q(online_status = 'online') & Q(campaign_id = local_camp.campaign_id)).sum_reports(rpt_days = 7) # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: item = local_adg.item cat_data = local_adg.cat_data ppc = local_adg.qr.cpc roi = local_adg.qr.roi cat_avg_ppc = get_cat_avg_cpc(item, cat_data) cat_avg_conv = get_cat_avg_conv(item, cat_data) result = calc_kw_1(local_adg) if local_adg.item and local_adg.item.price and cat_avg_ppc and cat_avg_conv and result and roi and ppc: print 'camp_id=%s adg_id=%s ppc=%s roi=%s cat_avg_ppc=%s cat_avg_conv=%s budget=%s' % (local_camp.campaign_id, local_adg.adgroup_id, ppc, roi, cat_avg_ppc, cat_avg_conv, local_camp.budget) if ppc > cat_avg_ppc * 1.2 and min(local_adg.item.price * cat_avg_conv / roi, result, local_camp.budget / 50): csv_data_list.append([ local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, ppc, cat_avg_ppc, roi, cat_avg_conv, local_camp.budget]) export_to_file('(check_case_5)', csv_title, csv_data_list)
def check_case_4(): # 点击少, 7日均点击少于 max(10,取某个行业点击做为参考值) example_cat_std_click = 100 example_cat_click = get_cat_click_8id(150704) csv_data_list = [] csv_title = ['shop_id', 'camp_id', 'item_id', 'adg_id', '7_day_avg_click', 'cat_click', 'example_cat_std_click', 'example_cat_click', 'current_cat_click', 'expression'] local_camp_list = Campaign.objects(Q(online_status = 'online')).order_by('+campaign_id') # 查询所有开启的计划 for temp_camp_list in genr_sublist(local_camp_list, 10): for local_camp in temp_camp_list: local_adg_list = Adgroup.objects(Q(online_status = 'online') & Q(campaign_id = local_camp.campaign_id)).sum_reports(rpt_days = 7) # 查询所有开启的推广组 for temp_adg_list in genr_sublist(local_adg_list, 10): for local_adg in temp_adg_list: item = local_adg.item cat_data = local_adg.cat_data click = local_adg.qr.click / 7 cat_click = get_cat_all_click(local_adg) if cat_click and example_cat_std_click and example_cat_click: expression = example_cat_std_click * cat_click / example_cat_click print 'camp_id=%s adg_id=%s qr.click=%s cat.click=%s example_cat_std_click=%s example_cat_click=%s expression=%s' % (local_camp.campaign_id, local_adg.adgroup_id, click, cat_click, example_cat_std_click, example_cat_click, expression) if click < max(10, expression): csv_data_list.append([ local_adg.shop_id, local_adg.campaign_id, local_adg.item_id, local_adg.adgroup_id, click, cat_click, example_cat_std_click, example_cat_click, cat_click, expression]) export_to_file('(check_case_4)', csv_title, csv_data_list)