Script 1273: Pacing Daily Budget Alert Checked Status

Purpose

The script filters and processes campaign data to identify and update daily budget alerts for campaigns marked as “Checked.”

To Elaborate

The Python script is designed to manage and update daily budget alerts for advertising campaigns. It processes campaign data to filter out campaigns that have ended and those that do not have “Traffic” as their SBA Traffic status. The script then updates the daily budget for the remaining campaigns based on a recommended budget. Finally, it identifies campaigns where the daily budget alert status is marked as “Checked” and prepares this data for further use or display. This ensures that only active and relevant campaigns are considered for budget adjustments, streamlining the budget management process.

Walking Through the Code

  1. Data Filtering:
    • The script begins by filtering out campaigns that have ended, using the RPT_COL_AUTO_PACING_CYCLE_THRESHOLD column.
    • It further filters the data to include only campaigns with “Traffic” in the RPT_COL_SBA_TRAFFIC column.
  2. Budget Update:
    • For the filtered campaigns, the script updates the RPT_COL_DAILY_BUDGET column with values from the RPT_COL_RECOMMENDED_DAILY_BUDGET column.
  3. Final Filtering and Output Preparation:
    • The script then filters the campaigns to include only those where the RPT_COL_DAILY_BUDGET_ALERT is marked as “Checked.”
    • It prepares the final output by creating new columns for account, campaign, and daily budget, and sets the daily budget alert status to “Checked.”
    • The final output is a DataFrame containing only the relevant columns for further use or display.

Vitals

  • Script ID : 1273
  • Client ID / Customer ID: 1306927189 / 60270139
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget, Daily Budget Alert
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jesus Garza (jgarza@marinsoftware.com)
  • Created by Jesus Garza on 2024-07-09 01:06
  • Last Updated by ascott@marinsoftware.com on 2024-09-09 18:03
> See it in Action

Python Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
## 
## name: Daily Budget Alert "Checked" Status 
## description:
##  
## 
## author: Jesus A. Garza
## created: 2024-07-01
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_DATE = 'Date'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_AUTO_PACING_CYCLE_START_DATE = 'Auto. Pacing Cycle Start Date'
RPT_COL_AUTO_PACING_CYCLE_END_DATE = 'Auto. Pacing Cycle End Date'
RPT_COL_AUTO_PACING_CYCLE_DAYS_ELAPSED = 'Auto. Pacing Cycle Days Elapsed'
RPT_COL_AUTO_PACING_CYCLE_DAYS_REMAINING = 'Auto. Pacing Cycle Days Remaining'
RPT_COL_AUTO_PACING_CYCLE_PACING = 'Auto. Pacing Cycle Pacing'
RPT_COL_AUTO_PACING_CYCLE_THRESHOLD = 'Auto. Pacing Cycle Threshold'
RPT_COL_TOTAL_TARGET_SPEND_PER_IMPRVIEWS = 'Total Target (Spend/Impr./Views)'
RPT_COL_TOTAL_DAYS = 'Total Days'
RPT_COL_TOTAL_DAYS_ELAPSED = 'Total Days Elapsed'
RPT_COL_TOTAL_PACING = 'Total Pacing'
RPT_COL_DELIVERY_STATUS = 'Delivery Status'
RPT_COL_RECOMMENDED_DAILY_BUDGET = 'Recommended Daily Budget'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PACING_CALCULATION_DATE = 'Pacing Calculation Date'
RPT_COL_SOCIAL_BUDGET = 'Social Budget'
RPT_COL_SOCIAL_BUDGET_UPDATE_STATUS = 'Social Budget Update Status'
RPT_COL_AUTO_PACING_CYCLE_PUB_COST = 'Auto. Pacing Cycle Pub. Cost'
RPT_COL_AUTO_PACING_CYCLE_IMPR = 'Auto. Pacing Cycle Impr.'
RPT_COL_AUTO_PACING_CYCLE_CLICKS = 'Auto. Pacing Cycle Clicks'
RPT_COL_AUTO_PACING_CYCLE_VIEWS = 'Auto. Pacing Cycle Views'
RPT_COL_SBA_TRAFFIC = 'SBA Traffic'
RPT_COL_DAILY_BUDGET_ALERT = 'Daily Budget Alert'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_DAILY_BUDGET_ALERT = 'Bulk Daily Budget Alert'

# First filter: Exclude campaigns with 'Campaign Ended'
campaigns_not_ended = inputDf[inputDf[RPT_COL_AUTO_PACING_CYCLE_THRESHOLD] != 'Campaign Ended']

# Second filter: From the remaining, only include those where SBA Traffic is 'Traffic'
filteredDf = campaigns_not_ended[campaigns_not_ended[RPT_COL_SBA_TRAFFIC] == 'Traffic']

# Apply necessary operations on filteredDf
filteredDf.loc[:, RPT_COL_DAILY_BUDGET] = filteredDf[RPT_COL_RECOMMENDED_DAILY_BUDGET]


# Filter to include only campaigns where DAILY_BUDGET_ALERT is 'Checked'
outputDf = filteredDf[filteredDf[RPT_COL_DAILY_BUDGET_ALERT] == 'Checked'].copy()

# Create new columns for output and clear the 'Checked' value in 'Bulk Daily Budget Alert'
outputDf[BULK_COL_ACCOUNT] = outputDf[RPT_COL_ACCOUNT]
outputDf[BULK_COL_CAMPAIGN] = outputDf[RPT_COL_CAMPAIGN]
outputDf[BULK_COL_DAILY_BUDGET] = outputDf[RPT_COL_DAILY_BUDGET]
outputDf[RPT_COL_DAILY_BUDGET_ALERT] = 'Checked'

# Select only the new columns for the final output
outputDf = outputDf[[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_DAILY_BUDGET, RPT_COL_DAILY_BUDGET_ALERT]]

# Assuming you want to display or utilize outputDf
print(outputDf)

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus