Exemplo n.º 1
0
def transform_line_item_to_dfp(line_item):
    """
    Transform a LineItem delivery object into
    a dictionary that will be accepted by dfp,

    @param line_item: LineItem
    @return: dict
    """
    return {
        'id': line_item.id,
        'name': line_item.name,
        'orderId': line_item.campaign_id,
        'orderName': line_item.campaign_name,
        'lineItemType': _sell_type_reverse_lookup(line_item),
        'costType': line_item.cost_type,
        'startDateTime': datetime_to_dfp_date(line_item.start),
        'endDateTime': datetime_to_dfp_date(line_item.end),
        'lastModifiedDateTime': datetime_to_dfp_date(line_item.last_modified),
        'lastModifiedByApp': line_item.last_modified_by,
        'budget': {
            'microAmount': "%.0f" % line_item.budget.budget_micro_amount,
            'currencyCode': line_item.budget.budget_currency_code,
        },
        'valueCostPerUnit': {
            'microAmount':
            "%.0f" % line_item.value_cost_per_unit.budget_micro_amount,
            'currencyCode': line_item.value_cost_per_unit.budget_currency_code,
        },
        'costPerUnit': {
            'microAmount':
            "%.0f" % line_item.cost_per_unit.budget_micro_amount,
            'currencyCode': line_item.cost_per_unit.budget_currency_code,
        },
        'primaryGoal': {
            'goalType': line_item.primary_goal.goal_type,
            'unitType': line_item.primary_goal.unit_type,
            'units': "%.0f" % line_item.primary_goal.units,
        },
        'creativePlaceholders': line_item.creative_placeholder,
        'stats': {
            'impressionsDelivered':
            line_item.delivery.stats.impressions,
            'clicksDelivered':
            line_item.delivery.stats.clicks,
            'videoStartsDelivered':
            line_item.delivery.stats.video_starts,
            'videoCompletionsDelivered':
            line_item.delivery.stats.video_completions,
        },
        'deliveryRateType': line_item.delivery.delivery_rate_type,
        'targetPlatform': line_item.target_platform,
        'targeting': transform_targeting_data_to_dfp(line_item.targeting),
        'status': line_item.status,
    }
Exemplo n.º 2
0
def transform_line_item_to_dfp(line_item):
    """
    Transform a LineItem delivery object into
    a dictionary that will be accepted by dfp,

    @param line_item: LineItem
    @return: dict
    """
    return {
        "id": line_item.id,
        "name": line_item.name,
        "orderId": line_item.campaign_id,
        "orderName": line_item.campaign_name,
        "lineItemType": _sell_type_reverse_lookup(line_item),
        "costType": line_item.cost_type,
        "startDateTime": datetime_to_dfp_date(line_item.start),
        "endDateTime": datetime_to_dfp_date(line_item.end),
        "lastModifiedDateTime": datetime_to_dfp_date(line_item.last_modified),
        "lastModifiedByApp": line_item.last_modified_by,
        "budget": {
            "microAmount": "%.0f" % line_item.budget.budget_micro_amount,
            "currencyCode": line_item.budget.budget_currency_code,
        },
        "valueCostPerUnit": {
            "microAmount": "%.0f" % line_item.value_cost_per_unit.budget_micro_amount,
            "currencyCode": line_item.value_cost_per_unit.budget_currency_code,
        },
        "costPerUnit": {
            "microAmount": "%.0f" % line_item.cost_per_unit.budget_micro_amount,
            "currencyCode": line_item.cost_per_unit.budget_currency_code,
        },
        "primaryGoal": {
            "goalType": line_item.primary_goal.goal_type,
            "unitType": line_item.primary_goal.unit_type,
            "units": "%.0f" % line_item.primary_goal.units,
        },
        "creativePlaceholders": line_item.creative_placeholder,
        "stats": {
            "impressionsDelivered": line_item.delivery.stats.impressions,
            "clicksDelivered": line_item.delivery.stats.clicks,
            "videoStartsDelivered": line_item.delivery.stats.video_starts,
            "videoCompletionsDelivered": line_item.delivery.stats.video_completions,
        },
        "deliveryRateType": line_item.delivery.delivery_rate_type,
        "targetPlatform": line_item.target_platform,
        "targeting": transform_targeting_data_to_dfp(line_item.targeting),
        "status": line_item.status,
    }
Exemplo n.º 3
0
def transform_line_item_to_dfp(line_item):
    """
    Transform a LineItem delivery object into
    a dictionary that will be accepted by dfp,

    @param line_item: LineItem
    @return: dict
    """
    return {
        'id': line_item.id,
        'name': line_item.name,
        'orderId': line_item.campaign_id,
        'orderName': line_item.campaign_name,
        'lineItemType': _sell_type_reverse_lookup(line_item),
        'costType': line_item.cost_type,
        'startDateTime': datetime_to_dfp_date(line_item.start),
        'endDateTime': datetime_to_dfp_date(line_item.end),
        'lastModifiedDateTime': datetime_to_dfp_date(line_item.last_modified),
        'lastModifiedByApp': line_item.last_modified_by,
        'budget': {
            'microAmount': "%.0f" % line_item.budget.budget_micro_amount,
            'currencyCode': line_item.budget.budget_currency_code,
        },
        'valueCostPerUnit': {
            'microAmount': "%.0f" % line_item.value_cost_per_unit.budget_micro_amount,
            'currencyCode': line_item.value_cost_per_unit.budget_currency_code,
        },
        'costPerUnit': {
            'microAmount': "%.0f" % line_item.cost_per_unit.budget_micro_amount,
            'currencyCode': line_item.cost_per_unit.budget_currency_code,
        },
        'primaryGoal': {
            'goalType': line_item.primary_goal.goal_type,
            'unitType': line_item.primary_goal.unit_type,
            'units': "%.0f" % line_item.primary_goal.units,
        },
        'creativePlaceholders': line_item.creative_placeholder,
        'stats': {
            'impressionsDelivered': line_item.delivery.stats.impressions,
            'clicksDelivered': line_item.delivery.stats.clicks,
            'videoStartsDelivered': line_item.delivery.stats.video_starts,
            'videoCompletionsDelivered': line_item.delivery.stats.video_completions,
        },
        'deliveryRateType': line_item.delivery.delivery_rate_type,
        'targetPlatform': line_item.target_platform,
        'targeting': transform_targeting_data_to_dfp(line_item.targeting),
        'status': line_item.status,
    }
Exemplo n.º 4
0
def transform_forecast_line_item_to_dfp(line_item,
                                        use_start=False,
                                        preserve_id=False):
    """
    Transform a Line Item delivery object into
    a dictionary that will be accepted by dfp
    availability check

    @param line_item: LineItem
    @param use_start: bool
    @param preserve_id: bool, communicate the id of the line item being
        forecasted to DFP. This is used in the case where we want to get
        a forecast on a line item in flight. This way, a domain doesn't
        need to have enough spare inventory to accommodate the two line
        items simultaneously. NOTE: If this is true then use_start is
        necessarily true.
    @return: dict
    """
    assert line_item.type
    assert line_item.cost_type
    assert line_item.end
    # Inventory targeting is required for availability checks
    assert line_item.targeting.inventory

    dfp_doc = {
        'lineItemType': _sell_type_reverse_lookup(line_item),
        'costType': line_item.cost_type,
        'endDateTime': datetime_to_dfp_date(line_item.end),
        'targeting': transform_targeting_data_to_dfp(line_item.targeting),
    }

    if preserve_id:
        assert use_start
        if not line_item.id:
            logging.warning(
                ("This line item (%s) does not have an existing id to "
                 "query DFP with"), line_item.id)
        elif not line_item.campaign_id:
            logging.warning(
                ("This line item (%s) does not have an existing order "
                 "id to query DFP with"), line_item.id)
        else:
            # Set the existing DFP ids associating this line item object
            # with the line item and order already booked in DFP
            dfp_doc['id'] = line_item.id
            dfp_doc['orderId'] = line_item.campaign_id

    # indicate whether to check for immediate availability or not
    if use_start:
        assert line_item.start

        dfp_doc['startDateTimeType'] = 'USE_START_DATE_TIME'
        dfp_doc['startDateTime'] = datetime_to_dfp_date(line_item.start)
    else:
        dfp_doc['startDateTimeType'] = 'IMMEDIATELY'

    if line_item.creative_placeholder:
        dfp_doc['creativePlaceholders'] = line_item.creative_placeholder

    if line_item.primary_goal:
        dfp_doc['primaryGoal'] = {
            'goalType': line_item.primary_goal.goal_type,
            'unitType': line_item.primary_goal.unit_type,
            'units': line_item.primary_goal.units,
        }
    else:
        dfp_doc['primaryGoal'] = {'units': 100, 'unitType': 'IMPRESSIONS'}

    if line_item.target_platform:
        dfp_doc['targetPlatform'] = line_item.target_platform

    return dfp_doc
Exemplo n.º 5
0
def transform_forecast_line_item_to_dfp(line_item, use_start=False, preserve_id=False):
    """
    Transform a Line Item delivery object into
    a dictionary that will be accepted by dfp
    availability check

    @param line_item: LineItem
    @param use_start: bool
    @param preserve_id: bool, communicate the id of the line item being
        forecasted to DFP. This is used in the case where we want to get
        a forecast on a line item in flight. This way, a domain doesn't
        need to have enough spare inventory to accommodate the two line
        items simultaneously. NOTE: If this is true then use_start is
        necessarily true.
    @return: dict
    """
    assert line_item.type
    assert line_item.cost_type
    assert line_item.end
    # Inventory targeting is required for availability checks
    assert line_item.targeting.inventory

    dfp_doc = {
        "lineItemType": _sell_type_reverse_lookup(line_item),
        "costType": line_item.cost_type,
        "endDateTime": datetime_to_dfp_date(line_item.end),
        "targeting": transform_targeting_data_to_dfp(line_item.targeting),
    }

    if preserve_id:
        assert use_start
        if not line_item.id:
            logging.warning(("This line item (%s) does not have an existing id to " "query DFP with"), line_item.id)
        elif not line_item.campaign_id:
            logging.warning(
                ("This line item (%s) does not have an existing order " "id to query DFP with"), line_item.id
            )
        else:
            # Set the existing DFP ids associating this line item object
            # with the line item and order already booked in DFP
            dfp_doc["id"] = line_item.id
            dfp_doc["orderId"] = line_item.campaign_id

    # indicate whether to check for immediate availability or not
    if use_start:
        assert line_item.start

        dfp_doc["startDateTimeType"] = "USE_START_DATE_TIME"
        dfp_doc["startDateTime"] = datetime_to_dfp_date(line_item.start)
    else:
        dfp_doc["startDateTimeType"] = "IMMEDIATELY"

    if line_item.creative_placeholder:
        dfp_doc["creativePlaceholders"] = line_item.creative_placeholder

    if line_item.primary_goal:
        dfp_doc["primaryGoal"] = {
            "goalType": line_item.primary_goal.goal_type,
            "unitType": line_item.primary_goal.unit_type,
            "units": line_item.primary_goal.units,
        }
    else:
        dfp_doc["primaryGoal"] = {"units": 100, "unitType": "IMPRESSIONS"}

    if line_item.target_platform:
        dfp_doc["targetPlatform"] = line_item.target_platform

    return dfp_doc