Creates timestamped dataset of all contributions and caches it. Adds creditee information, categorizes contributions based on campaign and NRR status, and associates with memberships, using contribution_membership_match.
Usage
contribution_stream(
type = "stream",
event_subtypes = list(TRUE ~ campaign_category_desc),
event_subtypes2 = list(seq(.N) == 1 ~ "New", !is.na(cust_memb_no) &
duplicated(cust_memb_no) | is.na(cust_memb_no) & duplicated(campaign_no) ~ "Upgrade",
timestamp - lag(timestamp) <= ddays(365) ~ "Renew", TRUE ~ "Reinstate"),
...
)
Arguments
- type
string, e.g. "tessi" or "stream", where to save the cache, passed to tessilake::write_cache
- event_subtypes
list of formulas to be used for coding
event_subtype
, as for dplyr::case_when. Can refer to any columns in thecontributions
table. See Note below- event_subtypes2
list of formulas to be used for coding
event_subtype2
, as for dplyr::case_when. Can refer to any columns in thecontributions
table. See Note below- ...
additional arguments passed on to tessilake::read_tessi and friends.
Details
Output Features are:
group_customer_no (donor or creditee)
timestamp : date of contribution
event_type : Contribution
event_subtype : Membership|Gala|Other
event_subtype2 : New|Renew|Reinstate|Upgrade
cont_amt
campaign_no (foreign key for campaign)
ref_no (primary key of contributions)
cust_memb_no (foreign key for memberships)
contribution_timestamp_min
contribution_timestamp_max
contribution_timestamp_last
contribution_SUBTYPE_count
contribution_amt
contribution_max
Note
This value for event_subtypes:
list( !is.na(cust_memb_no) ~ "Membership", grepl("BENE",campaign_desc) ~ "Gala", TRUE ~ campaign_category_desc )
Assigns event_subtype to
"Membership" for everything with a
cust_memb_no
"Gala" for everything else with "BENE" in
campaign_desc
andthe value of
campaign_category_desc
for everything else
This value for event_subtypes2, which is also the default:
list( 1:.N == 1 ~ "New", !is.na(cust_memb_no) & duplicated(cust_memb_no) | is.na(cust_memb_no) & duplicated(campaign_no) ~ "Upgrade", timestamp - lag(timestamp) <= ddays(365) ~ "Renew", TRUE ~ "Reinstate")
Assigns event_subtype2 by group of
group_customer_no
/event_subtype
to"New" for the first contribution per group
"Upgrade" for the second contribution per
cust_memb_no
orcampaign_no
"Renew" for a contribution that is within 365 days of the previous in the same group
"Reinstate" for everything else