def test_config(self): shop_id = 71193535 campaign_id = 33162349 adgroup_id = 620645850 data = build_datarpt(shop_id=shop_id, campaign_id=campaign_id, adgroup_id=adgroup_id) data.init_report() analyze_result = AdgRptAnalyze().analyze(adg_wrapper=data) # data.analyze_result = analyze_result data.analyze_result.update(analyze_result) data.calc_kw_limitprice(kw_g_cpc=analyze_result.get('kw_g_ppc7', 500)) cmd_cfgs = CommandConfig.objects.filter() for kw in data.kw_list: kw.is_delete = False kw.new_price = None kw.new_match_scope = None kw.optm_reason = '' kw.cmd = '' kw_dryrun = KeywordDryRun(kw) item = data.item adg = data.adgroup camp = data.campaign mnt_camp = data.mnt_campaign cat = data.category kw_dryrun.test_run_cmd(cmd_cfgs, data)
def test_config(self): shop_id = 71193535 campaign_id = 33162349 adgroup_id = 620645850 CommandConfig.refresh_all_configs() StrategyConfig.refresh_all_configs() strat_cfgs = strat_cfg_coll.find({}, {'name': 1}) strat_name_list = [sc['name'] for sc in strat_cfgs] strat_name_list.append('undefine') data = build_datarpt(shop_id=shop_id, campaign_id=campaign_id, adgroup_id=adgroup_id) data.init_report() analyze_result = AdgRptAnalyze().analyze(adg_wrapper=data) # data.analyze_result = analyze_result data.analyze_result.update(analyze_result) data.calc_kw_limitprice(kw_g_cpc=analyze_result.get('kw_g_ppc7', 500)) for strat_name in strat_name_list: print '===================== start %s ====================' % strat_name strategy = StrategyFactory().get(name=strat_name) strategy.dry_run(data) print '===================== test ok: %s ====================' % strat_name
def custom_optimize(adg_wrapper, strategy_name): adg_wrapper.init_report() analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) strategy = StrategyFactory().get(name = strategy_name) strategy.execute(data = adg_wrapper)
def auto_optimize_dryrun(adg_wrapper, strategy_name = ''): adg_wrapper.init_report(force_sync_qscore = time_is_ndays_interval(adg_wrapper.adgroup.qscore_sync_time, 1)) analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) alg = Algorithm1() if not strategy_name: strategy_name, _ = alg.diagnose(adg_wrapper = adg_wrapper) strategy = StrategyFactory().get(name = strategy_name) strategy.dry_run(data = adg_wrapper) return
def temp_strategy_optimize_dryrun(adg_wrapper, strategy_name, kw_cmd_list, adg_cmd_list): adg_wrapper.init_report(force_sync_qscore = time_is_ndays_interval(adg_wrapper.adgroup.qscore_sync_time, 1)) analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) if strategy_name: strategy = StrategyFactory().get(name = strategy_name) else: adg_wrapper.can_add_kw = False strategy = CommandStrategy(cmd_cfg_name = 'temp') strategy.bind_temp_strategy(kw_cmd_list = kw_cmd_list, adg_cmd_list = adg_cmd_list) strategy.dry_run(data = adg_wrapper)
def optimize(self, adg_wrapper): # analyze adgroup report data analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) # check last optimize result # diagnose strategy_name, diag_result = self.diagnose(adg_wrapper = adg_wrapper) strategy = StrategyFactory().get(name = strategy_name) strategy.execute(data = adg_wrapper) save_opt_record(adg_wrapper, diag_result, strategy, opt_type = self.opt_type) return
def test_analyze_withcampaign(self): analyze_result = AdgRptAnalyze().analyze_with_campaign(adg_wrapper = self.datarpt) self.assertTrue('rpt7_roi_factor' in analyze_result, 'error analyze_withcampaign, missing key rpt7_roi_factor') self.assertTrue('rpt7_click_factor' in analyze_result, 'error analyze_withcampaign, missing key rpt7_click_factor') self.assertTrue('rpt3_roi_factor' in analyze_result, 'error analyze_withcampaign, missing key rpt3_roi_factor') self.assertTrue('rpt3_click_factor' in analyze_result, 'error analyze_withcampaign, missing key rpt3_click_factor') self.assertTrue('rel_bid_factor' in analyze_result, 'error analyze_withcampaign, missing key rel_bid_factor')
def test_analyze_kwppc(self): analyze_result = AdgRptAnalyze().analyze_kw_ppc(adg_wrapper = self.datarpt) self.assertTrue('kw_ppc' in analyze_result, 'error analyze_kwppc, missing key kw_ppc') self.assertTrue('kw_g_ppc' in analyze_result, 'error analyze_kwppc, missing key kw_g_ppc') self.assertTrue('kw_ppc_factor' in analyze_result, 'error analyze_kwppc, missing key kw_ppc_factor') self.assertTrue('topkw_ppc' in analyze_result, 'error analyze_kwppc, missing key topkw_ppc') self.assertTrue('topkw_g_ppc' in analyze_result, 'error analyze_kwppc, missing key topkw_g_ppc') self.assertTrue('topkw_ppc_factor' in analyze_result, 'error analyze_kwppc, missing key topkw_ppc_factor')
def test_analyze_cat_tendency(self): analyze_result = AdgRptAnalyze().analyze_cat_tendency(adg_wrapper = self.datarpt) self.assertTrue('catpv_k' in analyze_result, 'error analyze_cat_tendency, missing key catpv_k') self.assertTrue('catpv_offset' in analyze_result, 'error analyze_cat_tendency, missing key catpv_offset') self.assertTrue('catpv_tendency_ref' in analyze_result, 'error analyze_cat_tendency, missing key catpv_tendency_ref') self.assertTrue('catclick_k' in analyze_result, 'error analyze_cat_tendency, missing key catclick_k') self.assertTrue('catclick_offset' in analyze_result, 'error analyze_cat_tendency, missing key catclick_offset') self.assertTrue('catclick_tendency_ref' in analyze_result, 'error analyze_cat_tendency, missing key catclick_tendency_ref')
def test_analyze_kw3(self): analyze_result = AdgRptAnalyze().analyze_kw3(adg_wrapper = self.datarpt) self.assertTrue('kw_pv3' in analyze_result, 'error analyze_kw3, missing key kw_pv3') self.assertTrue('kw_click3' in analyze_result, 'error analyze_kw3, missing key kw_click3') self.assertTrue('kw_conv3' in analyze_result, 'error analyze_kw3, missing key kw_conv3') self.assertTrue('kw_cost3' in analyze_result, 'error analyze_kw3, missing key kw_cost3') self.assertTrue('kw_ctr3' in analyze_result, 'error analyze_kw3, missing key kw_ctr3') self.assertTrue('kw_g_ctr3' in analyze_result, 'error analyze_kw3, missing key kw_g_ctr3') self.assertTrue('kw_cvr3' in analyze_result, 'error analyze_kw3, missing key kw_cvr3') self.assertTrue('kw_g_cvr3' in analyze_result, 'error analyze_kw3, missing key kw_g_cvr3') self.assertTrue('kw_ppc3' in analyze_result, 'error analyze_kw3, missing key kw_ppc3') self.assertTrue('kw_g_ppc3' in analyze_result, 'error analyze_kw3, missing key kw_g_ppc3')
def test_analyze_kw7(self): analyze_result = AdgRptAnalyze().analyze_kw7(adg_wrapper = self.datarpt) self.assertTrue('kw_pv7' in analyze_result, 'error analyze_kw7, missing key kw_pv7') self.assertTrue('kw_click7' in analyze_result, 'error analyze_kw7, missing key kw_click7') self.assertTrue('kw_conv7' in analyze_result, 'error analyze_kw7, missing key kw_conv7') self.assertTrue('kw_cost7' in analyze_result, 'error analyze_kw7, missing key kw_cost7') self.assertTrue('kw_ctr7' in analyze_result, 'error analyze_kw7, missing key kw_ctr7') self.assertTrue('kw_g_ctr7' in analyze_result, 'error analyze_kw7, missing key kw_g_ctr7') self.assertTrue('kw_cvr7' in analyze_result, 'error analyze_kw7, missing key kw_cvr7') self.assertTrue('kw_g_cvr7' in analyze_result, 'error analyze_kw7, missing key kw_g_cvr7') self.assertTrue('kw_ppc7' in analyze_result, 'error analyze_kw7, missing key kw_ppc7') self.assertTrue('kw_g_ppc7' in analyze_result, 'error analyze_kw7, missing key kw_g_ppc7')
def auto_optimize_dryrun2(adg_wrapper, strategy_name = '', summary_rpt = -1): adg_wrapper.init_report(force_sync_qscore = time_is_ndays_interval(adg_wrapper.adgroup.qscore_sync_time, 1)) # adg_wrapper.prepare_data_4optimize_mobile() analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice_mobile(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) strategy_mobile_name = strategy_name if not strategy_name: if adg_wrapper.kw_list_valid: alg = Algorithm1() strategy_mobile_name, _ = alg.diagnose(adg_wrapper = adg_wrapper) else: strategy_mobile_name = DEFAULT_NO_CLICK_STRATEGY strategy_mobile = StrategyFactory().get(name = strategy_mobile_name) strategy_mobile.dry_run(data = adg_wrapper) adg_wrapper.prepare_data_4optimize_pc() analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice_pc(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) strategy_pc_name = strategy_name if not strategy_name: if adg_wrapper.kw_list_valid: alg = Algorithm1() strategy_pc_name, _ = alg.diagnose(adg_wrapper = adg_wrapper) else: strategy_pc_name = DEFAULT_NO_CLICK_STRATEGY strategy_pc = StrategyFactory().get(name = strategy_pc_name) strategy_pc.dry_run(data = adg_wrapper) adg_wrapper.summarize_report(rpt = summary_rpt) return
def custom_optimize2(adg_wrapper, strategy_name): adg_wrapper.init_report() # adg_wrapper.prepare_data_4optimize_mobile() analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice_mobile(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) strategy_mobile = StrategyFactory().get(name = strategy_name) strategy_mobile.dry_run(data = adg_wrapper) adg_wrapper.prepare_data_4optimize_pc() analyze_result = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result) adg_wrapper.calc_kw_limitprice_pc(kw_g_cpc = analyze_result.get('kw_g_ppc7', 500)) strategy_pc = StrategyFactory().get(name = strategy_name) strategy_pc.dry_run(data = adg_wrapper) adg_wrapper.summarize_report(rpt = -1) # submit changes upd_kw_list, del_kw_list, add_kw_list = KeywordSubmit.alg_dry_run(adg_wrapper = adg_wrapper) # 如果是系统或者全自动的话, 防止一次性删除太多的词 most_del_count = min(int(len(adg_wrapper.kw_list) * 0.2), 25) del_kw_list = del_kw_list[: most_del_count] KeywordSubmit.execute( shop_id = adg_wrapper.adgroup.shop_id, campaign_id = adg_wrapper.adgroup.campaign_id, adgroup_id = adg_wrapper.adgroup.adgroup_id, upd_kw_list = upd_kw_list, del_kw_list = del_kw_list, add_kw_list = add_kw_list, opter = 3, opter_name = '全自动优化' ) return
def test_analyze_qscore(self): analyze_result = AdgRptAnalyze().analyze_qscore(adg_wrapper = self.datarpt) self.assertTrue('kw_qscore' in analyze_result, 'error analyze_qscore, missing key kw_qscore') self.assertTrue('kw_score_rele' in analyze_result, 'error analyze_qscore, missing key kw_score_rele') self.assertTrue('kw_score_cvr' in analyze_result, 'error analyze_qscore, missing key kw_score_cvr') self.assertTrue('kw_score_cust' in analyze_result, 'error analyze_qscore, missing key kw_score_cust') self.assertTrue('kw_score_creative' in analyze_result, 'error analyze_qscore, missing key kw_score_creative') self.assertTrue('topkw_qscore' in analyze_result, 'error analyze_qscore, missing key topkw_qscore') self.assertTrue('topkw_score_rele' in analyze_result, 'error analyze_qscore, missing key topkw_score_rele') self.assertTrue('topkw_score_cvr' in analyze_result, 'error analyze_qscore, missing key topkw_score_cvr') self.assertTrue('topkw_score_cust' in analyze_result, 'error analyze_qscore, missing key topkw_score_cust') self.assertTrue('topkw_score_creative' in analyze_result, 'error analyze_qscore, missing key topkw_score_creative') self.assertTrue('topkw_ids' in analyze_result, 'error analyze_qscore, missing key topkw_ids')
def test_analyze(self): analyze_result = AdgRptAnalyze().analyze(adg_wrapper=self.datarpt) self.assertTrue(len(analyze_result)) pprint(analyze_result) self.datarpt.analyze_result = analyze_result pprint(self.datarpt.topkw_elementword(days=7))
def optimize2(self, adg_wrapper): # adg_wrapper.init_report() # optimize by mobile report adg_wrapper.prepare_data_4optimize_mobile() # analyze mobile data strategy_mobile = StrategyFactory().get(name = DEFAULT_NO_CLICK_STRATEGY) analyze_result_mobile = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result_mobile) adg_wrapper.calc_kw_limitprice_mobile(kw_g_cpc = analyze_result_mobile.get('kw_g_ppc7', 500)) diag_result_mobile = {} if adg_wrapper.kw_list_valid: # # diagnose strategy_name, diag_result_mobile = self.diagnose(adg_wrapper = adg_wrapper) strategy_mobile = StrategyFactory().get(name = strategy_name) strategy_mobile.dry_run(data = adg_wrapper) cmd_dict_mobile = copy.deepcopy(adg_wrapper.cmd_count_dict) # optimize by pc report adg_wrapper.prepare_data_4optimize_pc() # analyze pc data strategy_pc = StrategyFactory().get(name = DEFAULT_NO_CLICK_STRATEGY) analyze_result_pc = AdgRptAnalyze().analyze(adg_wrapper = adg_wrapper) adg_wrapper.analyze_result.update(analyze_result_pc) adg_wrapper.calc_kw_limitprice_pc(kw_g_cpc = analyze_result_pc.get('kw_g_ppc7', 500)) diag_result_pc = {} if adg_wrapper.kw_list_valid: # # diagnose strategy_name, diag_result_pc = self.diagnose(adg_wrapper = adg_wrapper) strategy_pc = StrategyFactory().get(name = strategy_name) strategy_pc.dry_run(data = adg_wrapper) cmd_dict_pc = copy.deepcopy(adg_wrapper.cmd_count_dict) # summary changes adg_wrapper.summarize_report() # submit changes upd_kw_list, del_kw_list, add_kw_list = KeywordSubmit.alg_dry_run(adg_wrapper = adg_wrapper) # 如果是系统或者全自动的话, 防止一次性删除太多的词 most_del_count = min(int(len(adg_wrapper.kw_list) * 0.2), 25) del_kw_list = del_kw_list[: most_del_count] KeywordSubmit.execute( shop_id = adg_wrapper.adgroup.shop_id, campaign_id = adg_wrapper.adgroup.campaign_id, adgroup_id = adg_wrapper.adgroup.adgroup_id, upd_kw_list = upd_kw_list, del_kw_list = del_kw_list, add_kw_list = add_kw_list, opter = 3, opter_name = '全自动优化' ) # TODO 保存优化记录 save_opt_record2(adg_wrapper = adg_wrapper, analyze_result = analyze_result_mobile, diag_result = diag_result_mobile, strategy = strategy_mobile, cmd_dict = cmd_dict_mobile, modify_dict = adg_wrapper.modify_kw_count_dict, opt_type = 1) save_opt_record2(adg_wrapper = adg_wrapper, analyze_result = analyze_result_pc, diag_result = diag_result_pc, strategy = strategy_pc, cmd_dict = cmd_dict_pc, modify_dict = adg_wrapper.modify_kw_count_dict, opt_type = 1) return
def test_analyze(self): analyze_result = AdgRptAnalyze().analyze(adg_wrapper = self.datarpt) self.assertTrue(len(analyze_result))