Beispiel #1
0
def compose_baby(country, father_ad, mother_ad, all_name, all_weight, geo_name, geo_weight, delt_name, creative_media):
    columns = ['behaviors', 'genders', 'wireless_carrier']
    if father_ad['platform'] == mother_ad['platform']:
        columns.append('user_device')
    father_pt = copy.deepcopy(father_ad['pt'])
    mother_pt = copy.deepcopy(mother_ad['pt'])
    random_dim = choice(columns, 1)[0]
    if common_prod.node_exist(mother_pt, random_dim) and common_prod.node_exist(father_pt, random_dim):
        tmp = copy.deepcopy(mother_pt['adset_spec']['targeting'][random_dim])
        mother_pt['adset_spec']['targeting'][random_dim] = copy.deepcopy(father_pt['adset_spec']['targeting'][random_dim])
        father_pt['adset_spec']['targeting'][random_dim] = copy.deepcopy(tmp)

    if common_prod.node_exist(father_pt, 'geo_locations') == False or \
            common_prod.node_exist_geolocation(father_pt, 'custom_locations') == False:
        father_pt['adset_spec']['targeting']['geo_locations'] = {'custom_locations': None}
    if common_prod.node_exist(mother_pt, 'geo_locations') == False or \
            common_prod.node_exist_geolocation(mother_pt, 'custom_locations') == False:
        mother_pt['adset_spec']['targeting']['geo_locations'] = {'custom_locations': None}
    if mother_ad['country'] == country and father_ad['country'] == country:
        tmp = copy.deepcopy(mother_pt['adset_spec']['targeting']['geo_locations']['custom_locations'])
        mother_pt['adset_spec']['targeting']['geo_locations']['custom_locations'] = \
            copy.deepcopy(father_pt['adset_spec']['targeting']['geo_locations']['custom_locations'])
        father_pt['adset_spec']['targeting']['geo_locations']['custom_locations'] = copy.deepcopy(tmp)

    if mother_ad['country'] != country or common_prod.node_exist_geolocation(mother_pt, 'custom_locations') == False:
        mother_pt['adset_spec']['targeting']['geo_locations']['custom_locations'] = choice_geolocation(geo_name, geo_weight)
    if father_ad['country'] != country or common_prod.node_exist_geolocation(father_pt, 'custom_locations') == False:
        father_pt['adset_spec']['targeting']['geo_locations']['custom_locations'] = choice_geolocation(geo_name, geo_weight)

    father_pt['adset_spec']['targeting']['geo_locations']['countries'] = [str(country)]
    mother_pt['adset_spec']['targeting']['geo_locations']['countries'] = [str(country)]
    if len(father_pt['adset_spec']['targeting']['geo_locations']['custom_locations']) > 0:
        del father_pt['adset_spec']['targeting']['geo_locations']['countries']
    father_pt['adset_spec']['targeting']['interests'] = choice_interest(father_pt, mother_pt, all_name, all_weight)
    if father_ad['platform'] == mother_ad['platform'] and mother_ad['country'] == country:
        mother_pt['adset_spec']['targeting']['interests'] = choice_interest(mother_pt, father_pt, all_name, all_weight)
        if len(mother_pt['adset_spec']['targeting']['geo_locations']['custom_locations']) > 0:
            del mother_pt['adset_spec']['targeting']['geo_locations']['countries']
        return [common_prod.modify_pt(pt=father_pt, delt_name=delt_name, sign='[GA3]', creative_medias=creative_media),
                common_prod.modify_pt(pt=mother_pt, delt_name=delt_name, sign='[GA3]', creative_medias=creative_media)]
    else:
        return [common_prod.modify_pt(pt=father_pt, delt_name=delt_name, sign='[GA3]', creative_medias=creative_media)]
Beispiel #2
0
def compose_baby(country, father_ad, mother_ad, delt_name, roas_average_floor,
                 pre_dict):
    columns = ['behaviors', 'genders', 'wireless_carrier']
    if father_ad['platform'] == mother_ad['platform']:
        columns.append('user_device')
    father_pt = copy.deepcopy(father_ad['pt'])
    mother_pt = copy.deepcopy(mother_ad['pt'])
    random_dim = choice(columns, 1)[0]
    if common_prod.node_exist(mother_pt,
                              random_dim) and common_prod.node_exist(
                                  father_pt, random_dim):
        tmp = copy.deepcopy(mother_pt['adset_spec']['targeting'][random_dim])
        mother_pt['adset_spec']['targeting'][random_dim] = copy.deepcopy(
            father_pt['adset_spec']['targeting'][random_dim])
        father_pt['adset_spec']['targeting'][random_dim] = copy.deepcopy(tmp)

    if not common_prod.node_exist(father_pt, 'geo_locations') or \
       not common_prod.node_exist_geolocation(father_pt, 'custom_locations'):
        father_pt['adset_spec']['targeting']['geo_locations'] = {
            'custom_locations': None
        }
    if not common_prod.node_exist(mother_pt, 'geo_locations') or \
       not common_prod.node_exist_geolocation(mother_pt, 'custom_locations'):
        mother_pt['adset_spec']['targeting']['geo_locations'] = {
            'custom_locations': None
        }
    if mother_ad['country'] == country and father_ad['country'] == country:
        tmp = copy.deepcopy(mother_pt['adset_spec']['targeting']
                            ['geo_locations']['custom_locations'])
        mother_pt['adset_spec']['targeting']['geo_locations']['custom_locations'] = \
            copy.deepcopy(father_pt['adset_spec']['targeting']['geo_locations']['custom_locations'])
        father_pt['adset_spec']['targeting']['geo_locations'][
            'custom_locations'] = copy.deepcopy(tmp)
    if mother_ad[
            'country'] != country or not common_prod.node_exist_geolocation(
                mother_pt, 'custom_locations'):
        mother_pt['adset_spec']['targeting']['geo_locations'][
            'custom_locations'] = choice_geolocation(
                pre_dict['geo_dict']['name'][mother_ad['country']],
                pre_dict['geo_dict']['weight'][mother_ad['country']])
    if father_ad[
            'country'] != country or not common_prod.node_exist_geolocation(
                father_pt, 'custom_locations'):
        father_pt['adset_spec']['targeting']['geo_locations'][
            'custom_locations'] = choice_geolocation(
                pre_dict['geo_dict']['name'][mother_ad['country']],
                pre_dict['geo_dict']['weight'][mother_ad['country']])

    father_pt['adset_spec']['targeting']['geo_locations']['countries'] = {
        '0': str(country)
    }
    mother_pt['adset_spec']['targeting']['geo_locations']['countries'] = {
        '0': str(country)
    }
    if len(father_pt['adset_spec']['targeting']['geo_locations']
           ['custom_locations']) > 0:
        del father_pt['adset_spec']['targeting']['geo_locations']['countries']
    father_pt['adset_spec']['targeting']['interests'] = choice_interest(
        father_pt, mother_pt, pre_dict['interests_name'],
        pre_dict['interests_weight'])
    if father_ad['platform'] == mother_ad['platform'] and mother_ad[
            'country'] == country:
        mother_pt['adset_spec']['targeting']['interests'] = choice_interest(
            mother_pt, father_pt, pre_dict['interests_name'],
            pre_dict['interests_weight'])
        if len(mother_pt['adset_spec']['targeting']['geo_locations']
               ['custom_locations']) > 0:
            del mother_pt['adset_spec']['targeting']['geo_locations'][
                'countries']
        return [
            common_prod.modify_pt(pt=father_pt,
                                  delt_name=delt_name,
                                  creative_medias=pre_dict['media_url'],
                                  country=country,
                                  platform=father_ad['platform'],
                                  roas_average_floor=roas_average_floor),
            common_prod.modify_pt(pt=mother_pt,
                                  delt_name=delt_name,
                                  creative_medias=pre_dict['media_url'],
                                  country=country,
                                  platform=mother_ad['platform'],
                                  roas_average_floor=roas_average_floor)
        ]
    else:
        return [
            common_prod.modify_pt(pt=father_pt,
                                  delt_name=delt_name,
                                  creative_medias=pre_dict['media_url'],
                                  country=country,
                                  platform=father_ad['platform'],
                                  roas_average_floor=roas_average_floor)
        ]