Ejemplo n.º 1
0
def create_pt(delt_name=None, create_amount=100, pre_dict=None):
    logger.info('delt_name:%s, create_amount:%d' % (delt_name, create_amount))
    if create_amount <= 0:
        return []
    if delt_name:
        key, country, roas_average_floor = mongo_prod.get_key_country(
            delt_name)
        logger.info('the platform: %s, the country: %s' % (key, country))
        if key is None or country is None:
            return []
    else:
        return []
    global_vars = DeliveryVars()
    global_vars.ads = pre_dict['ads']
    if len(global_vars.ads) < 1:
        return []
    ads_count = dict()
    ads_other = dict()
    for ad_id in global_vars.ads:
        ads_other[ad_id] = global_vars.ads[ad_id]['coef']
        if global_vars.ads[ad_id]['platform'] == key:
            ads_count[ad_id] = global_vars.ads[ad_id]['coef']
    if len(ads_count) == 0:
        return []
    global_vars.ads_count = common_prod.weighted(ads_count)
    global_vars.ads_other = ads_other
    if len(ads_count) == 0:
        return []
    pt_pool = list()
    while True:
        ''' 根据给定投放名称的平台随机获取一个父样本 '''
        father_ad_id = choice(list(global_vars.ads_count.keys()),
                              1,
                              p=list(global_vars.ads_count.values()))[0]
        copy_other = copy.deepcopy(global_vars.ads_other)
        ''' 在全部中删除获取的父样本,然后再剩下的样本中随机选取一个母样本'''
        del copy_other[father_ad_id]
        if len(copy_other) == 0:
            break
        copy_other = common_prod.weighted(copy_other)
        mother_ad_id = choice(list(copy_other.keys()),
                              1,
                              p=list(copy_other.values()))[0]
        pt_out = compose_baby(country, global_vars.ads[father_ad_id],
                              global_vars.ads[mother_ad_id], delt_name,
                              roas_average_floor, pre_dict)
        pt_pool.extend(pt_out)
        if len(pt_pool) >= create_amount:
            break
    mongo_prod.insert_baits(pt_pool)
    mongo_prod.close()
    logger.info('create amount is %d' % (len(pt_pool)))
    return {'size': len(pt_pool)}
Ejemplo n.º 2
0
def create_pt(delt_name=None, create_amount=10):

    logger.info('delt_name:%s, create_amount:%d' % (delt_name, create_amount))
    if create_amount <= 0:
        return []
    if delt_name:
        key, country = mongo_prod.get_key_country(delt_name)
        logger.info('the platform: %s, the country: %s' % (key, country))
        if key is None or country is None:
            return []
    else:
        return []
    global_vars = DeliveryVars()
    global_vars.ads = mongo_prod.select_ads(create_amount)
    if len(global_vars.ads) < 1:
        return []
    ads_count = dict()
    ads_other = dict()
    for ad_id in global_vars.ads:
        ads_other[ad_id] = global_vars.ads[ad_id]['coef']
        if global_vars.ads[ad_id]['platform'] == key:
            ads_count[ad_id] = global_vars.ads[ad_id]['coef']
    if len(ads_count) == 0:
        return []
    global_vars.ads_count = common_prod.weighted(ads_count)
    global_vars.ads_other = ads_other
    if len(ads_count) == 0:
        return []
    ''' 获取interests信息的属性值名称以及权重 '''
    all_name, all_weight = mysql_prod.select_weigth()
    ''' 根据国家获取坐标信息 '''
    geo_name, geo_weight = mysql_prod.select_geo_weigth(country)

    creative_media = mysql_prod.select_url()

    pts_size = 0
    while True:
        ''' 根据给定投放名称的平台随机获取一个父样本 '''
        father_ad_id = choice(list(global_vars.ads_count.keys()),
                              1,
                              p=list(global_vars.ads_count.values()))[0]
        copy_other = copy.deepcopy(global_vars.ads_other)
        ''' 在全部中删除获取的父样本,然后再剩下的样本中随机选取一个母样本'''
        del copy_other[father_ad_id]
        if len(copy_other) == 0:
            break
        copy_other = common_prod.weighted(copy_other)
        mother_ad_id = choice(list(copy_other.keys()),
                              1,
                              p=list(copy_other.values()))[0]
        pt_out = compose_baby(country, global_vars.ads[father_ad_id],
                              global_vars.ads[mother_ad_id], all_name,
                              all_weight, geo_name, geo_weight, delt_name,
                              creative_media)
        pts_size += mongo_prod.insert_baits(pt_out)
        if pts_size >= create_amount:
            break
    mongo_prod.close()
    logger.info('create amount is %d' % (pts_size))

    return {'size': pts_size}
Ejemplo n.º 3
0
                    'name': all_name[rid]
                })
    return interests


if __name__ == '__main__':
    out = mongo_prod.test_ga_maker()
    lst = list()
    for ot in set(out):
        if ot in [
                'bet3_hk_s2_android_tz_a00', 'bbt3_hk_s2_android_tz_a00',
                'cet1_hk_s2_ios_tz_a00', 'bbt4_hk_s2_android_tz_a00',
                'bbt3_hk_s2_ios_tz_a00', 'bet3_hk_s2_ios_tz_a00',
                'bbt2_hk_s2_ios_tz_a00', 'bbt4_hk_s2_ios_tz_a00',
                'cet2_hk_s2_ios_tz_a00', 'bbt2_hk_s2_android_tz_a00',
                'cet1_hk_s2_android_tz_a00', 'cet2_hk_s2_android_tz_a00'
        ]:
            print(ot)
            # try:
            t1 = time.time()
            pts_size = create_pt(delt_name=ot, create_amount=300)
            print(pts_size)
            print(time.time() - t1)
            # except:
            #     print(ot)
            #     lst.append(ot)
            # pass
    import pandas as pd
    pd.DataFrame({'delt_name': lst}).to_csv('no_successful.csv', index=False)
    mongo_prod.close()
Ejemplo n.º 4
0
def create_pt(delt_name=None, create_amount=10):
    # print(delt_name, create_amount)
    logger.info('start create pt, two parameters are delt_name:%s, create_amount:%d' % (delt_name, create_amount))
    if create_amount <= 0:
        return []
    if delt_name:
        key, country = mongo_prod.get_key_country(delt_name)
        logger.info('the platform: %s, the country: %s' % (key, country))
        if key is None or country is None:
            return []
    else:
        return []
    global_vars = DeliveryVars()
    cur_len = mongo_prod.get_income_logs_len()
    if global_vars.cur_income_logs_len != cur_len:
        global_vars.cur_income_logs_len = cur_len
        global_vars.ads = mongo_prod.select_ads(create_amount)
        logger.info('the size of global_vars.ads is  %d' % (len(global_vars.ads)))
        if len(global_vars.ads) == 0:
            return []
        ads_count = dict()
        ads_other = dict()
        for ad_id in global_vars.ads:
            ads_other[ad_id] = global_vars.ads[ad_id]['coef']
            if global_vars.ads[ad_id]['platform'] == key:
                ads_count[ad_id] = global_vars.ads[ad_id]['coef']
        if len(ads_count) == 0:
            return []
        global_vars.ads_count = common_prod.weighted(ads_count)
        global_vars.ads_other = ads_other
        logger.info('the size of same platform is %d, other platform is %d' % (len(ads_count), len(ads_other)))
        if len(ads_count) == 0:
            return []
    pt_pool = list()
    ''' 获取interests信息的属性值名称以及权重 '''
    all_name, all_weight = mysql_prod.select_weigth()
    logger.info('the size of interests in dw_dim_interests is  %d' % (len(all_name)))
    ''' 根据国家获取坐标信息 '''
    geo_name, geo_weight = mysql_prod.select_geo_weigth(country)
    logger.info('the size of coordinates in dw_dim_coordinate is  %d' % (len(geo_name)))

    creative_media = mysql_prod.select_url()
    logger.info('the size of creative_media is %d' % len(creative_media))
    while True:
        ''' 根据给定投放名称的平台随机获取一个父样本 '''
        father_ad_id = choice(list(global_vars.ads_count.keys()), 1, p=list(global_vars.ads_count.values()))[0]
        copy_other = copy.deepcopy(global_vars.ads_other)
        ''' 在全部中删除获取的父样本,然后再剩下的样本中随机选取一个母样本'''
        del copy_other[father_ad_id]
        if len(copy_other) == 0:
            break
        copy_other = common_prod.weighted(copy_other)
        mother_ad_id = choice(list(copy_other.keys()), 1, p=list(copy_other.values()))[0]
        pt_out = compose_baby(country, global_vars.ads[father_ad_id], global_vars.ads[mother_ad_id], all_name,
                              all_weight, geo_name, geo_weight, delt_name, creative_media)
        for pp in pt_out:
            pt_pool.append(pp)
        if len(pt_pool) >= create_amount:
            break
    mongo_prod.close()
    logger.info('create amount pt is  %d' % (len(pt_pool)))
    return pt_pool