Script 227: sba pasue Date maintenance

Purpose

The script ensures that the SBA Pause Date remains within one month of the current date to allow the tool to unpause it.

To Elaborate

The Python script is designed to manage and update the pause dates for structured budget allocations (SBA) within a specified timeframe. The primary goal is to ensure that the SBA Pause Date is kept within one month of the current date, allowing the tool to have the option to unpause it if necessary. The script processes input data, checks the conditions related to the pause and end dates, and updates the pause dates accordingly. It filters out entries that do not meet the criteria and outputs the updated data for further use. This ensures that the budget allocations are managed efficiently and remain relevant to the current date.

Walking Through the Code

  1. Initialization and Setup
    • The script begins by defining constants for column names used in the data processing.
    • A temporary field is created in the input DataFrame to store new values for the campaign column.
  2. Date Calculations and Data Preparation
    • The current date is determined, and a date threshold is set to one week before the current date.
    • The script converts relevant columns to datetime format to facilitate date comparisons.
    • It extracts and formats the pause date to ensure consistency.
  3. Filtering and Updating Data
    • The script filters the input data to include only those entries where the bucket end date is greater than or equal to the current date and where the pause date is populated.
    • It updates the pause date for entries where the pause date is earlier than the date threshold, setting it to one day before the current date.
  4. Output Preparation
    • The script filters the data to include only those entries where the pause date has been updated.
    • It sets the new pause date in the output DataFrame and prepares it for further processing or export.

Vitals

  • Script ID : 227
  • Client ID / Customer ID: 1306923673 / 60269245
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, SBA Pause Date
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jonathan Reichl (jreichl@marinsoftware.com)
  • Created by Jonathan Reichl on 2023-06-29 14:03
  • Last Updated by Jonathan Reichl 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_SBA_BUCKETNAME = 'SBA Bucket Name'
RPT_COL_SBA_PAUSEDATE = 'SBA Pause Date'
RPT_COL_SBA_BUCKET_END_DATE = 'SBA Bucket End Date'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_SBA_PAUSEDATE = 'SBA Pause Date'

outputDf[BULK_COL_SBA_PAUSEDATE] = "<<YOUR VALUE>>"

TMP_FIELD = BULK_COL_CAMPAIGN + '_new'
# blank out tmp field
inputDf[TMP_FIELD] = np.nan

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

# Calculating the date threshold
date_threshold = today - datetime.timedelta(days=7)

print(tableize(inputDf))

# Convert 'RPT_COL_SBA_BUCKET_END_DATE' to date type
inputDf[RPT_COL_SBA_BUCKET_END_DATE] = pd.to_datetime(inputDf[RPT_COL_SBA_BUCKET_END_DATE])

# Extract first 10 characters from 'RPT_COL_SBA_PAUSEDATE'
inputDf[RPT_COL_SBA_PAUSEDATE] = inputDf[RPT_COL_SBA_PAUSEDATE].str[:10]

# Convert 'RPT_COL_SBA_PAUSEDATE' to datetime type
inputDf[RPT_COL_SBA_PAUSEDATE] = pd.to_datetime(inputDf[RPT_COL_SBA_PAUSEDATE])

column_types = inputDf.dtypes
print(column_types)

# Only update buckets where the end date is greater than or equal to today
inputDf = inputDf[inputDf[RPT_COL_SBA_BUCKET_END_DATE].dt.date >= today]

# Only update buckets where pause date is populated
inputDf = inputDf[inputDf[RPT_COL_SBA_PAUSEDATE].notna()]

# Update the pause date for buckets where the pause date is lessthan  than the date threshold
inputDf.loc[inputDf[RPT_COL_SBA_PAUSEDATE] < pd.Timestamp(date_threshold), TMP_FIELD] = today - datetime.timedelta(days=1)

print(column_types)
print(tableize(inputDf))




# only include where pasue date is updated 
outputDf = inputDf[ inputDf[TMP_FIELD].notnull() & (inputDf[RPT_COL_SBA_PAUSEDATE] != inputDf[TMP_FIELD]) ]

# set new pause date in output 
outputDf.loc[:,BULK_COL_SBA_PAUSEDATE] = inputDf.loc[:, TMP_FIELD]

print(column_types)
print(tableize(outputDf))

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

comments powered by Disqus