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_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 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