Script 627: Alert CCT groups paused (Anime)
Purpose
The Python script identifies and filters paused CCT groups based on a specific date range.
To Elaborate
The Python script is designed to process data related to CCT (Content Creation Tool) groups, specifically focusing on identifying groups that have been paused. It extracts relevant information from a data source, processes the pause date and reason, and filters the data to include only those groups that have been paused within the last five days. This allows users to quickly identify recent changes in the status of CCT groups, which can be crucial for maintaining up-to-date information and making informed decisions regarding resource allocation and management.
Walking Through the Code
- Data Preparation
- The script begins by defining the current date using the client’s timezone.
- It retrieves the primary data source and assigns it to
inputDf
. - Several column names are defined for use in data processing, such as ‘Group’, ‘Account’, ‘Campaign’, and others related to CCT groups.
- Data Extraction and Transformation
- The script extracts the ‘Pause Date’ and ‘Pause Reason’ from the ‘CCT_Group_pause_check’ column by splitting the string data.
- It converts the extracted ‘Pause Date’ strings into datetime objects for accurate date comparisons.
- Date Calculation and Filtering
- The script calculates the date five days prior to the current date.
- It filters the DataFrame to include only those entries where the ‘Pause Date’ is within the last five days, creating a new DataFrame
filtered_df
.
- Output Preparation
- The filtered DataFrame is assigned to
outputDf
, which contains the relevant paused CCT groups for further analysis or reporting.
- The filtered DataFrame is assigned to
Vitals
- Script ID : 627
- Client ID / Customer ID: 1306924347 / 69058
- Action Type: Email Report
- Item Changed: None
- Output Columns:
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jonathan Reichl (jreichl@marinsoftware.com)
- Created by Jonathan Reichl on 2023-12-22 16:15
- Last Updated by Jonathan Reichl on 2023-12-22 16:16
> 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
##
## name: alert_cct_group_pasued
## description:
##
##
## author:
## created: 2023-12-19
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CCT_SOURCETEMPLATE = 'CCT_sourcetemplate'
RPT_COL_PUB_ID = 'Pub. ID'
RPT_COL_STUDIO = 'Studio'
RPT_COL_CCT_SOURCETEMPLATE_BACKUP = 'CCT_SourceTemplate_Backup'
RPT_COL_CCT_GROUP_PAUSE_CHECK = 'CCT_Group_pause_check'
# output columns and initial values
# user code start here
print(tableize(inputDf))
# Splitting and extracting date
inputDf['Pause Date'] = inputDf[RPT_COL_CCT_GROUP_PAUSE_CHECK].str.split('|').str[2]
inputDf['Pause Reason'] = inputDf[RPT_COL_CCT_GROUP_PAUSE_CHECK].str.split('|').str[1]
# Convert strings to datetime objects
inputDf['Pause Date'] = pd.to_datetime(inputDf['Pause Date'])
# Calculating 5 days ago from today
five_days_ago = today - datetime.timedelta(days=5)
# Convert the 'five_days_ago' date object to a pandas Timestamp for comparison
five_days_ago = pd.Timestamp(five_days_ago)
# Filtering the DataFrame
filtered_df = inputDf[inputDf['Pause Date'] >= five_days_ago]
outputDf = filtered_df
Post generated on 2024-11-27 06:58:46 GMT