Пример #1
0
 def taobao_item_ItemPunishDownshelf(data):
     """
     data-->sample
     {
         u'topic': u'taobao_item_ItemPunishDownshelf',
         u'publish_time': 1450253827872,
         u'user_id': 38352809,
         u'publisher_appkey': u'12497914',
         u'user_nick': u'\u56fd\u7389\u4e4b\u4e61',
         u'content': u'{
             "num_iid": 525078200576
         }',
         u'outgoing_id': 4162901165157287277
     }
     """
     item_id = data.content.num_iid
     try:
         user = User.objects.get(user_id=data['user_id'])
     except User.DoesNotExist:
         pass
     Adgroup._get_collection().update(
         {
             'shop_id': user.shop_id,
             'item_id': item_id
         }, {
             '$set': {
                 'online_status': 'offline',
                 'offline_type': 'audit_offline'
             }
         },
         multi=True)
     return True
Пример #2
0
def delete_adgroups(shop_id, adgroup_id_list, record_flag = True, tapi = None, opter = 1, opter_name = ''):
    if not tapi:
        tapi = get_tapi(shop_id = shop_id)
    deleted_id_list, cant_del_list, ztc_del_count, record_list, error_msg = Adgroup.delete_adgroups_inner(shop_id = int(shop_id), adgroup_id_list = adgroup_id_list, tapi = tapi, opter = opter, opter_name = opter_name)
    if record_list and record_flag:
        rcd_list = [UploadRecord(**record) for record in record_list]
        UploadRecord.objects.insert(rcd_list)
    return deleted_id_list, cant_del_list, ztc_del_count, error_msg
Пример #3
0
def add_adgroups(shop_id, campaign_id, item_arg_list, tapi = None, opter = 1, opter_name = ''): # 这里的item_arg_list每个item是个字典,包含了标准的item键值,还有额外的adg_title这个键
    if not tapi:
        tapi = get_tapi(shop_id = shop_id)
    added_id_list, error_msg_dict, record_list = Adgroup.add_adgroups_inner(shop_id = int(shop_id), campaign_id = campaign_id, item_arg_list = item_arg_list, tapi = tapi, opter = opter, opter_name = opter_name)
    if record_list:
        rcd_list = [UploadRecord(**record) for record in record_list]
        UploadRecord.objects.insert(rcd_list)
    return added_id_list, error_msg_dict
Пример #4
0
def update_adgroups(shop_id, adg_arg_dict, record_flag = True, tapi = None, opter = 1, opter_name = ''): # adg_dict形如{123456:{'online_status':'online'},231654:{'online_status':'offline'}}
    if not tapi:
        tapi = get_tapi(shop_id = shop_id)
    updated_id_list, del_id_list, record_list = Adgroup.update_adgroups_inner(shop_id = int(shop_id), adg_arg_dict = adg_arg_dict, tapi = tapi, opter = opter, opter_name = opter_name)
    if record_list and record_flag:
        rcd_list = [UploadRecord(**record) for record in record_list]
        UploadRecord.objects.insert(rcd_list)
    return updated_id_list, del_id_list
Пример #5
0
 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)
Пример #6
0
def get_lastest_qscore():
    save_dict = {}
    today = str(datetime.date.today())
    for shop_id, adg_id_list in adg_data_dict.items():
        tapi = get_tapi(shop_id = shop_id)

        for adg_id in adg_id_list:
            qscore_dict = Adgroup.get_new_qscore_byadgid(shop_id, adg_id, [], tapi)
            for _, qscore_info in qscore_dict.items():
                qscore_info.update({'date':today})

            save_dict.update({adg_id:qscore_dict})
    print 'get %s\'s qscore OK' % today
    return save_dict
Пример #7
0
 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)
Пример #8
0
 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)
Пример #9
0
 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)
Пример #10
0
 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)
Пример #11
0
 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)
Пример #12
0
 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)
Пример #13
0
 def update_adgroups_byitem_id(cls, item_id, arg_dict):
     Adgroup._get_collection().update({'item_id': item_id},
                                      {'$set': arg_dict},
                                      multi=True)