Script 157: Inventory Bidding Feed Integrity Check

Purpose

The script checks if the “IB Last Updated” date is two or more days old and flags such entries for alerting purposes.

To Elaborate

The Python script is designed to monitor the timeliness of inventory bidding feed updates. It identifies entries where the “IB Last Updated” date is two or more days old, indicating that the feed has not been processed recently. If such a condition is met, the script marks the “Stale Feed Alert” as “TRUE” for those entries. This alert is only triggered when certain conditions are met: both the Campaign Status and Group Status must be active, the Campaign must contain specific keywords (“RBA-Pro-SEM” or “RBA-Pro-BSEM”), and Inventory Bidding must be set to TRUE. The script filters the data to ensure that only relevant entries are flagged, which then feeds into another report serving as an alert mechanism for stale feeds.

Walking Through the Code

  1. Data Preparation: The script begins by copying the input DataFrame (inputDf) to a new DataFrame (outputDf). This ensures that the original data remains unchanged while modifications are made to the copy.

  2. Date Calculation: It calculates the time difference between the “IB Last Updated” date and the current date. This is done to identify entries where the feed has not been updated for two or more days.

  3. Boolean Mask Creation: A boolean mask is created to identify rows where the time difference is two or more days. This mask is used to determine which entries need to be flagged.

  4. Flagging Stale Feeds: Using the boolean mask, the script sets the “Stale Feed Alert” column to “TRUE” for entries that meet the criteria. If the condition is not met, the column remains blank.

  5. Output DataFrame Creation: Finally, the script filters the outputDf to include only the modified rows where the “Stale Feed Alert” is “TRUE”. This filtered DataFrame is used for further reporting and alerting purposes.

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-11-27 06:58:46 GMT

comments powered by Disqus