Script 157: Inventory Bidding Feed Integrity Check
Purpose
Checks whether the “IB Last Updated” date is 2 or more days in the past compared to the current date, and populates a “Stale Feed Alert” dimension as “TRUE” for those rows.
To Elaborate
The Python script checks if the “IB Last Updated” date in a report is 2 or more days in the past compared to the current date. If it is, it means that a feed hasn’t been processed in 2 or more days. In this case, a “Stale Feed Alert” dimension is populated as “TRUE” for those rows. This alert will be used in another report as an alert.
The script filters the report based on certain conditions:
- The Campaign Status and Group Status must be Active.
- The Campaign must contain “RBA-Pro-SEM” or “RBA-Pro-BSEM”.
- The Inventory Bidding must be TRUE.
- The “IB Last Updated” date must not be blank.
The script then modifies the report by adding a new column, “Stale Feed Alert”, to indicate if a feed is stale or not.
Walking Through the Code
- The column names used in the script are defined.
- The input DataFrame is copied to the output DataFrame.
- The current date is obtained using the
datetime.datetime.now()
function. - The time difference between the “IB Last Updated” date and the current date is calculated.
- A boolean mask is created to identify rows where the time difference is greater than or equal to 2 days.
- The “Stale Feed Alert” column in the output DataFrame is set to “TRUE” for rows where the mask is True, otherwise it is kept blank.
- The output DataFrame is updated to only include the modified rows based on the mask.
Vitals
- Script ID : 157
- Client ID / Customer ID: 1306913045 / 60268001
- Action Type: Bulk Upload
- Item Changed: AdGroup
- Output Columns: Account, Campaign, Group, Stale Feed Alert
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jeff Sands (jsands@marinsoftware.com)
- Created by Jeff Sands on 2023-05-31 20:20
- Last Updated by Jeff Sands on 2023-12-06 04:01
> 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
# Column Names
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_GROUP_STATUS = 'Group Status'
RPT_COL_INVENTORY_BIDDING = 'Inventory Bidding'
RPT_COL_IB_LASTUPDATED = 'IB Last Updated'
RPT_COL_AUCTIONBOOST = 'AuctionBoost'
RPT_COL_STALE_FEEDALERT = 'Stale Feed Alert'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_STATUS = 'Status'
BULK_COL_STALE_FEEDALERT = 'Stale Feed Alert'
# Copy inputDf to outputDf
outputDf = inputDf.copy()
# Get the current date
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# Calculate time difference between RPT_COL_IB_LASTUPDATED and today
time_difference = today - inputDf[RPT_COL_IB_LASTUPDATED].dt.date
# Create a boolean mask for rows with time difference >= 2 days
mask = time_difference >= datetime.timedelta(days=2)
# Set BULK_COL_STALE_FEEDALERT to "TRUE" where mask is True, otherwise keep it blank
outputDf[BULK_COL_STALE_FEEDALERT] = np.where(mask, "TRUE", "")
# Create outputDf with only modified rows based on the mask
outputDf = outputDf[mask].copy()
Post generated on 2024-05-15 07:44:05 GMT