Esempio n. 1
0
def create_line_item_configs(prices, order_id, placement_ids, ad_unit_ids,
                             bidder_code, sizes, hb_bidder_key_id,
                             hb_pb_key_id, currency_code, line_item_format,
                             HBBidderValueGetter, HBPBValueGetter,
                             creative_id):
    """
  Create a line item config for each price bucket.

  Args:
    prices (array)
    order_id (int)
    placement_ids (arr)
    ad_unit_ids (arr)
    bidder_code (str)
    hb_bidder_key_id (int)
    hb_pb_key_id (int)
    currency_code (str)
    line_item_format (str)
    HBBidderValueGetter (DFPValueIdGetter)
    HBPBValueGetter (DFPValueIdGetter)
  Returns:
    an array of objects: the array of DFP line item configurations
  """

    # The DFP targeting value ID for this `hb_bidder` code.
    hb_bidder_value_id = HBBidderValueGetter.get_value_id(bidder_code)

    line_items_config = []
    for price in prices:

        price_str = num_to_str(micro_amount_to_num(price))

        # Autogenerate the line item name.
        line_item_name = line_item_format.format(bidder_code=bidder_code,
                                                 price=price_str,
                                                 creative=creative_id)

        # The DFP targeting value ID for this `hb_pb` price value.
        hb_pb_value_id = HBPBValueGetter.get_value_id(price_str)

        line_item_exist = dfp.get_line_items.get_line_item_by_name(
            line_item_name)
        if line_item_exist is None:

            config = dfp.create_line_items.create_line_item_config(
                name=line_item_name,
                order_id=order_id,
                placement_ids=placement_ids,
                ad_unit_ids=ad_unit_ids,
                cpm_micro_amount=price,
                sizes=sizes,
                hb_bidder_key_id=hb_bidder_key_id,
                hb_pb_key_id=hb_pb_key_id,
                hb_bidder_value_id=hb_bidder_value_id,
                hb_pb_value_id=hb_pb_value_id,
                currency_code=currency_code)

            line_items_config.append(config)

    return line_items_config
Esempio n. 2
0
def create_line_item_configs(prices, order_id, placement_ids, ad_unit_ids,
                             bidder_code, sizes, hb_pb_key_id, currency_code,
                             hb_criteria, HBPBValueGetter,
                             creative_template_id):
    """
    Create a line item config for each price bucket.

    Args:
      prices (array)
      order_id (int)
      placement_ids (arr)
      ad_unit_ids (arr)
      bidder_code (str)
      hb_bidder_key_id (int)
      hb_pb_key_id (int)
      currency_code (str)
      hb_criteria (dict)
      HBPBValueGetter (DFPValueIdGetter)
      creative_template_id
    Returns:
      an array of objects: the array of DFP line item configurations
    """

    line_items_config = []
    for price in prices:
        price_str = num_to_str(micro_amount_to_num(price))

        # Autogenerate the line item name.
        line_item_name = u'{bidder_code}: HB ${price}'.format(
            bidder_code=bidder_code, price=price_str)

        # The DFP targeting value ID for this `hb_pb` price value.
        hb_pb_value_id = HBPBValueGetter.get_value_id(price_str)

        # Add the prebid key and price to the criteria
        hb_criteria[hb_pb_key_id] = hb_pb_value_id

        # Create the line item config
        config = dfp.create_line_items.create_line_item_config(
            name=line_item_name,
            order_id=order_id,
            placement_ids=placement_ids,
            ad_unit_ids=ad_unit_ids,
            cpm_micro_amount=price,
            sizes=sizes,
            hb_criteria=hb_criteria,
            currency_code=currency_code,
            creative_template_id=creative_template_id,
        )

        line_items_config.append(config)

    return line_items_config
Esempio n. 3
0
 def test_micro_amount_to_num(self):
     """
 It returns the expected conversion.
 """
     self.assertEqual(micro_amount_to_num(40000000), 40.0)
     self.assertEqual(micro_amount_to_num(5000000), 5.0)
     self.assertEqual(micro_amount_to_num(100000), 0.10)
     self.assertEqual(micro_amount_to_num(50000), 0.05)
     self.assertEqual(micro_amount_to_num(10000), 0.01)
     self.assertEqual(micro_amount_to_num(1000), 0.001)
     self.assertEqual(micro_amount_to_num(0), 0.0)
def create_line_item_configs(prices, order_id, placement_ids, ad_unit_ids,
                             bidder_code, sizes, key_gen_obj, currency_code):
    """
  Create a line item config for each price bucket.

  Args:
    prices (array)
    order_id (int)
    placement_ids (arr)
    ad_unit_ids (arr)
    bidder_code (str)
    sizes (arr)
    key_gen_obj (obj)
    currency_code (str)
  Returns:
    an array of objects: the array of DFP line item configurations
  """

    # The DFP targeting value ID for this `hb_bidder` code.
    key_gen_obj.set_bidder_value(bidder_code)

    line_items_config = []
    for price in prices:

        price_str = num_to_str(micro_amount_to_num(price))

        # Autogenerate the line item name.
        line_item_name = u'{bidder_code}: HB ${price}'.format(
            bidder_code=bidder_code, price=price_str)

        # The DFP targeting value ID for this `hb_pb` price value.
        key_gen_obj.set_price_value(price_str)

        config = dfp.create_line_items.create_line_item_config(
            name=line_item_name,
            order_id=order_id,
            placement_ids=placement_ids,
            ad_unit_ids=ad_unit_ids,
            cpm_micro_amount=price,
            sizes=sizes,
            key_gen_obj=key_gen_obj,
            currency_code=currency_code,
        )

        line_items_config.append(config)

    return line_items_config
Esempio n. 5
0
def create_line_item_configs(prices, order_id, use_placements, placement_ids, ad_unit_ids,
  bidder_code, sizes, hb_bidder_key_id, hb_pb_key_id, hb_size_key_id, currency_code, HBBidderValueGetter,
  HBPBValueGetter, HBSizeValueGetter):
  """
  Create a line item config for each price bucket.

  Args:
    prices (array)
    order_id (int)
    use_placements (bool)
    placement_ids (arr)
    ad_unit_ids (arr)
    bidder_code (str)
    hb_bidder_key_id (int)
    hb_pb_key_id (int)
    hb_size_key_id (int)
    currency_code (str)
    HBBidderValueGetter (DFPValueIdGetter)
    HBPBValueGetter (DFPValueIdGetter)
    HBSizeValueGetter (DFPValueIdGetter)
  Returns:
    an array of objects: the array of DFP line item configurations
  """

  # The DFP targeting value ID for this `hb_bidder` code.
  hb_bidder_value_id = HBBidderValueGetter.get_value_id(bidder_code)

  line_items_config = []
  for price in prices:

    price_str = num_to_str(micro_amount_to_num(price))

    # Autogenerate the line item name.
    line_item_name = ''
    
    if getattr(settings, 'DFP_LINE_ITEM_PREFIX', None) is not None and settings.DFP_LINE_ITEM_PREFIX != '':
      line_item_name=u'{prefix}{price}'.format(
        prefix=settings.DFP_LINE_ITEM_PREFIX,
        price=price_str
      )
    else:
      line_item_name=u'{bidder_code}: HB ${price}'.format(
        bidder_code=bidder_code,
        price=price_str
      )

    # The DFP targeting value ID for this `hb_pb` price value.
    hb_pb_value_id = HBPBValueGetter.get_value_id(price_str)

    # The DFP targeting value ID for this `hb_size` price value.
    hb_size_value_ids = [HBSizeValueGetter.get_value_id(str(size['width'])+'x'+str(size['height'])) for size in sizes]

    config = dfp.create_line_items.create_line_item_config(
      name=line_item_name,
      order_id=order_id,
      use_placements=use_placements,
      placement_ids=placement_ids,
      ad_unit_ids=ad_unit_ids,
      cpm_micro_amount=price,
      sizes=sizes,
      hb_bidder_key_id=hb_bidder_key_id,
      hb_pb_key_id=hb_pb_key_id,
      hb_bidder_value_id=hb_bidder_value_id,
      hb_pb_value_id=hb_pb_value_id,
      hb_size_key_id=hb_size_key_id,
      hb_size_value_ids=hb_size_value_ids,
      currency_code=currency_code,
    )

    line_items_config.append(config)

  return line_items_config
Esempio n. 6
0
def create_line_item_configs(prices, order_id, placement_ids, bidder_code,
                             sizes, hb_bidder_key_id, hb_pb_key_id,
                             currency_code, HBBidderValueGetter,
                             HBPBValueGetter):
    """
  Create a line item config for each price bucket.

  Args:
    prices (array)
    order_id (int)
    placement_ids (arr)
    bidder_code (str)
    hb_bidder_key_id (int)
    hb_pb_key_id (int)
    currency_code (str)
    HBBidderValueGetter (DFPValueIdGetter)
    HBPBValueGetter (DFPValueIdGetter)
  Returns:
    an array of objects: the array of DFP line item configurations
  """

    # The DFP targeting value ID for this `hb_bidder` code.
    hb_bidder_value_id = HBBidderValueGetter.get_value_id(bidder_code)

    line_items_config = []
    root_ad_unit_id = None

    if not placement_ids:
        # Since the placement ids array is empty, it means we should target a run of network for the line item
        root_ad_unit_id = dfp.get_ad_units.get_root_ad_unit_id()

        if root_ad_unit_id is None:
            raise DFPObjectNotFound(
                'Could not find the root ad unit to target a run of network.')

    for price in prices:

        price_str = num_to_str(micro_amount_to_num(price))

        # Autogenerate the line item name.
        line_item_name = u'{bidder_code}: HB ${price}'.format(
            bidder_code=bidder_code, price=price_str)

        # The DFP targeting value ID for this `hb_pb` price value.
        hb_pb_value_id = HBPBValueGetter.get_value_id(price_str)

        config = dfp.create_line_items.create_line_item_config(
            name=line_item_name,
            order_id=order_id,
            placement_ids=placement_ids,
            cpm_micro_amount=price,
            sizes=sizes,
            hb_bidder_key_id=hb_bidder_key_id,
            hb_pb_key_id=hb_pb_key_id,
            hb_bidder_value_id=hb_bidder_value_id,
            hb_pb_value_id=hb_pb_value_id,
            currency_code=currency_code,
            root_ad_unit_id=root_ad_unit_id)

        line_items_config.append(config)

    return line_items_config
def create_line_item_configs(prices, order_id, placement_ids, ad_unit_ids,
                             bidder_code, sizes, hb_bidder_key_id,
                             hb_pb_key_id, currency_code, HBBidderValueGetter,
                             HBPBValueGetter):
    """
  Create a line item config for each price bucket.

  Args:
    prices (array)
    order_id (int)
    placement_ids (arr)
    ad_unit_ids (arr)
    bidder_code (str)
    hb_bidder_key_id (int)
    hb_pb_key_id (int)
    currency_code (str)
    HBBidderValueGetter (DFPValueIdGetter)
    HBPBValueGetter (DFPValueIdGetter)
  Returns:
    an array of objects: the array of DFP line item configurations
  """

    # The DFP targeting value ID for this `hb_bidder` code.
    hb_bidder_value_id = HBBidderValueGetter.get_value_id(
        bidder_code) if bidder_code else None

    line_items_config = []
    for price in prices:

        price_str = num_to_str(micro_amount_to_num(price))

        # Autogenerate the line item name.
        line_item_name = u'{bidder_code}: HB ${price}'.format(
            bidder_code=bidder_code if bidder_code else 'all_bidders',
            price=price_str)

        # If the settings allow modifying an existing order, do so. Otherwise,
        # throw an exception.
        skip_existing_line_items = getattr(settings,
                                           'DFP_SKIP_EXISTING_LINE_ITEMS',
                                           False)
        if skip_existing_line_items:
            existing_line_item_names = dfp.get_line_items.get_line_item_names_by_order_id(
                order_id)
        else:
            existing_line_item_names = []

        if line_item_name in existing_line_item_names:
            continue

        # The DFP targeting value ID for this `hb_pb` price value.
        hb_pb_value_id = HBPBValueGetter.get_value_id(price_str)

        config = dfp.create_line_items.create_line_item_config(
            name=line_item_name,
            order_id=order_id,
            placement_ids=placement_ids,
            ad_unit_ids=ad_unit_ids,
            cpm_micro_amount=price,
            sizes=sizes,
            hb_bidder_key_id=hb_bidder_key_id,
            hb_pb_key_id=hb_pb_key_id,
            hb_bidder_value_id=hb_bidder_value_id,
            hb_pb_value_id=hb_pb_value_id,
            currency_code=currency_code)

        line_items_config.append(config)

    return line_items_config