From 21c3df2256b310f534b0df57e11f9e134c0804c5 Mon Sep 17 00:00:00 2001 From: Shiloh Date: Thu, 27 Jun 2024 07:26:31 -0400 Subject: [PATCH 1/8] Joining tables --- .../modules/rcpt/update_descriptives_new.qy | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index 7ba384c0..a461cc68 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -9,7 +9,7 @@ update_descriptives_new "system/query" sql = " declare collection tmp_gift_items scope application; declare collection a_descriptives scope application; declare collection a_descriptives_hist scope application; - declare collection tmp_intermediate_vals; + declare collection tmp_intermediate_vals; --This is the main file for our donor analytics application --The donor analytics is meant to make a new table, a_descriptives_hist, that keeps track of donor giving patterns and such @@ -18,7 +18,7 @@ update_descriptives_new "system/query" --This organizes the data so that we can easily tell what kind of pattern a donor has, which can therefore be used when someone stops doing their normal pattern delete collection tmp_gift_items; - delete collection tmp_intermediate_vals; + delete collection tmp_intermediate_vals; print 'Working on descriptives' + isnull(' for fund ' + :parameters:fund + ',', '') + isnull(' for ledger ' + :parameters:ledger + ',', '') + isnull(' for donor ' + :parameters:donor + ',', '') - ','; @@ -148,8 +148,9 @@ update_descriptives_new "system/query" s_date_modified = getdate(), s_modified_by = user_name() from - collection tmp_gift_items - group by + collection tmp_gift_items t + left join collection a_pledge p on t.ledger = p.a_ledger_number and t.fund = p.a_fund and t.donor = p.p_donor_partner_id + group by :ledger, :fund, :donor @@ -290,7 +291,7 @@ update_descriptives_new "system/query" (:parameters:donor is null or :parameters:donor = :dh1:p_donor_partner_key) and not :dh1:a_is_extra ; - update + update collection a_descriptives_hist dh1 set :dh1:a_prev_end = (select :a_last_gift from collection a_descriptives_hist dh2 where :dh2:a_ledger_number = :dh1:a_ledger_number and :dh2:a_fund = :dh1:a_fund and :dh2:p_donor_partner_key = :dh1:p_donor_partner_key and :dh2:a_last_gift < :dh1:a_first_gift and :dh2:a_is_extra order by :dh2:a_last_gift desc limit 1), @@ -303,7 +304,7 @@ update_descriptives_new "system/query" -- Correct NTL Tracking print 'Fixing next-to-last tracking at ' + dateformat(getdate(), 'hh:mm:ss'); - update + update collection a_descriptives_hist dh1 set :dh1:a_ntl_gift = (select nth(:t:giftdate, 2) from collection tmp_gift_items t where :t:ledger = :dh1:a_ledger_number and :t:fund = :dh1:a_fund and :t:donor = :dh1:p_donor_partner_key and :t:giftdate <= :dh1:a_last_gift order by :t:giftdate desc) @@ -466,7 +467,7 @@ update_descriptives_new "system/query" -- if the interval is biannual or less, lookback slightly less than a year from the most recent gift -- the lookahead date is half an interval past the most recent gift print 'Setting general stats at ' + dateformat(getdate(), 'hh:mm:ss'); - update + update identity collection a_descriptives d set :a_act_lookahead_date = dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift), @@ -480,7 +481,7 @@ update_descriptives_new "system/query" (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; -- if the interval is greater than bi-annually, check back the last three intervals - update + update identity collection a_descriptives d set :a_act_lookahead_date = dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift), From fc866abdd1e9f1a21c18d6f0a5e4fb0210356979 Mon Sep 17 00:00:00 2001 From: Shiloh Date: Fri, 28 Jun 2024 11:14:45 -0400 Subject: [PATCH 2/8] Fixed Syntax & Moved Data Insertion --- kardia-app/modules/rcpt/update_descriptives_new.qy | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index a461cc68..8a30377c 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -149,7 +149,6 @@ update_descriptives_new "system/query" s_modified_by = user_name() from collection tmp_gift_items t - left join collection a_pledge p on t.ledger = p.a_ledger_number and t.fund = p.a_fund and t.donor = p.p_donor_partner_id group by :ledger, :fund, @@ -549,6 +548,17 @@ update_descriptives_new "system/query" :dh:is_approximate = 0 ; + -- Update pledge information for a_descriptives_hist + insert into + identity collection a_descriptives_hist dh + select + :p:a_is_active, :p:a_intent_type, :p:a_amount, :p:a_total_amount, :p:a_giving_interval, :p:a_gift_count, + :p:a_pledge_date, :p:a_start_date, :p:a_end_date + from + collection a_pledge p + where + :dh:ledger = :p:a_ledger_number and :dh:fund = :p:a_fund and :dh:p_donor_partner_key = :p:p_donor_partner_id + -- Update past/current flags on histories and on descriptives. For a history entry with -- more than one gift, we base the current/lapsed indicator on the gift interval compared to -- the most recent gift and current date. For a one-gift history entry, we look back 13 From 30a877fcac2adb80b6f776ae0f3f252251b962a6 Mon Sep 17 00:00:00 2001 From: Shiloh Date: Fri, 28 Jun 2024 13:05:53 -0400 Subject: [PATCH 3/8] Added Temporary Pledge Collection & Updated Descriptive Hist Table --- .../modules/rcpt/update_descriptives_new.qy | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index 8a30377c..21e80a6d 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -9,6 +9,7 @@ update_descriptives_new "system/query" sql = " declare collection tmp_gift_items scope application; declare collection a_descriptives scope application; declare collection a_descriptives_hist scope application; + declare collection a_pledge scope query; declare collection tmp_intermediate_vals; --This is the main file for our donor analytics application @@ -204,6 +205,35 @@ update_descriptives_new "system/query" :giftdate desc ; + -- Creating pledge collection + print 'Creating pledge collection at ' + dateformat(getdate(), 'hh:mm:ss'); + insert into + collection a_pledge + select + :a_ledger_number = :i:a_ledger_number, + :p_donor_partner_id = :i:p_donor_partner_id, + :a_fund = :i:a_fund, + :a_pledge_id = :i:a_pledge_id, + :a_is_active = i:a_is_active + :a_intent_type = i:a_intent_type + :a_amount = :i:a_amount, + :a_total_amount = :i:a_total_amount, + :a_giving_interval = :i:a_giving_interval, + :a_gift_count = :i:a_gift_count, + :a_pledge_date = :i:a_pledge_date, + :a_start_date = :i:a_start_date, + :a_end_date = :i:a:a_end_date + from + /apps/kardia/data/Kardia_DB/a_pledge/rows i + group by + :ledger + :fund, + :donor + order by + :ledger, + :fund, + :donor + -- Update previous/next interval start/end dates print 'Updating segment start/end dates at ' + dateformat(getdate(), 'hh:mm:ss'); update @@ -549,15 +579,27 @@ update_descriptives_new "system/query" ; -- Update pledge information for a_descriptives_hist - insert into - identity collection a_descriptives_hist dh - select - :p:a_is_active, :p:a_intent_type, :p:a_amount, :p:a_total_amount, :p:a_giving_interval, :p:a_gift_count, - :p:a_pledge_date, :p:a_start_date, :p:a_end_date - from + update + identity collection a_descriptives_hist dh, collection a_pledge p + set + :dh:a_ledger_number = :p:a_ledger_number, + :dh:p_donor_partner_id = :p:p_donor_partner_id, + :dh:a_fund = :p:a_fund, + :dh:a_pledge_id = :p:a_pledge_id, + :dh:a_is_active = :p:a_is_active, + :dh:a_intent_type = :p:a_intent_type, + :dh:a_amount = :p:a_amount, + :dh:a_total_amount = :p:a_total_amount, + :dh:a_giving_interval = :p:a_giving_interval, + :dh:a_gift_count = :p:a_gift_count, + :dh:a_pledge_date = :p:a_pledge_date, + :dh:a_start_date = :p:a_start_date, + :dh:a_end_date = :p:a_end_date where - :dh:ledger = :p:a_ledger_number and :dh:fund = :p:a_fund and :dh:p_donor_partner_key = :p:p_donor_partner_id + :dh:a_ledger_number *= :p:a_ledger_number + and :dh:a_fund *= :p:a_fund + and :dh:p_donor_partner_key *= :p:p_donor_partner_id -- Update past/current flags on histories and on descriptives. For a history entry with -- more than one gift, we base the current/lapsed indicator on the gift interval compared to From 809c737892ee8b09d31a04047f4b007c0215c189 Mon Sep 17 00:00:00 2001 From: Shiloh Date: Fri, 28 Jun 2024 13:40:17 -0400 Subject: [PATCH 4/8] Syntax Fixes --- .../modules/rcpt/update_descriptives_new.qy | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index 21e80a6d..c603e7ca 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -210,29 +210,21 @@ update_descriptives_new "system/query" insert into collection a_pledge select - :a_ledger_number = :i:a_ledger_number, - :p_donor_partner_id = :i:p_donor_partner_id, - :a_fund = :i:a_fund, - :a_pledge_id = :i:a_pledge_id, - :a_is_active = i:a_is_active - :a_intent_type = i:a_intent_type - :a_amount = :i:a_amount, - :a_total_amount = :i:a_total_amount, - :a_giving_interval = :i:a_giving_interval, - :a_gift_count = :i:a_gift_count, - :a_pledge_date = :i:a_pledge_date, - :a_start_date = :i:a_start_date, - :a_end_date = :i:a:a_end_date + a_ledger_number = :i:a_ledger_number, + p_donor_partner_id = :i:p_donor_partner_id, + a_fund = :i:a_fund, + a_pledge_id = :i:a_pledge_id, + a_is_active = i:a_is_active + a_intent_type = i:a_intent_type + a_amount = :i:a_amount, + a_total_amount = :i:a_total_amount, + a_giving_interval = :i:a_giving_interval, + a_gift_count = :i:a_gift_count, + a_pledge_date = :i:a_pledge_date, + a_start_date = :i:a_start_date, + a_end_date = :i:a:a_end_date from /apps/kardia/data/Kardia_DB/a_pledge/rows i - group by - :ledger - :fund, - :donor - order by - :ledger, - :fund, - :donor -- Update previous/next interval start/end dates print 'Updating segment start/end dates at ' + dateformat(getdate(), 'hh:mm:ss'); @@ -583,19 +575,16 @@ update_descriptives_new "system/query" identity collection a_descriptives_hist dh, collection a_pledge p set - :dh:a_ledger_number = :p:a_ledger_number, - :dh:p_donor_partner_id = :p:p_donor_partner_id, - :dh:a_fund = :p:a_fund, :dh:a_pledge_id = :p:a_pledge_id, - :dh:a_is_active = :p:a_is_active, - :dh:a_intent_type = :p:a_intent_type, - :dh:a_amount = :p:a_amount, - :dh:a_total_amount = :p:a_total_amount, - :dh:a_giving_interval = :p:a_giving_interval, - :dh:a_gift_count = :p:a_gift_count, - :dh:a_pledge_date = :p:a_pledge_date, - :dh:a_start_date = :p:a_start_date, - :dh:a_end_date = :p:a_end_date + :dh:a_pledge_is_active = :p:a_is_active, + :dh:a_pledge_intent_type = :p:a_intent_type, + :dh:a_pledge_amount = :p:a_amount, + :dh:a_pledge_total_amount = :p:a_total_amount, + :dh:a_pledge_giving_interval = :p:a_giving_interval, + :dh:a_pledge_gift_count = :p:a_gift_count, + :dh:a_pledge_made_date = :p:a_pledge_date, + :dh:a_pledge_start_date = :p:a_start_date, + :dh:a_pledge_end_date = :p:a_end_date where :dh:a_ledger_number *= :p:a_ledger_number and :dh:a_fund *= :p:a_fund From 112e5e1f81fa4fe87419010e11f57a5d61a9c9a7 Mon Sep 17 00:00:00 2001 From: David Hopkins Date: Thu, 18 Jul 2024 19:58:30 -0400 Subject: [PATCH 5/8] Added comments about descriptives --- kardia-app/modules/rcpt/update_descriptives_new.qy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index c603e7ca..5a030404 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -160,6 +160,8 @@ update_descriptives_new "system/query" :donor, :giftdate desc ; + + -- From David: Is this block of code is being used to pull the data, then have the 3 history data to update it? Thanks! -- Generate the amount history data, starting with the most recent gift amount. print 'Creating descriptives histories at ' + dateformat(getdate(), 'hh:mm:ss'); From c55a954aa3e2661cf1f8909bf23297b75543955c Mon Sep 17 00:00:00 2001 From: David Hopkins Date: Fri, 2 Aug 2024 21:02:57 -0400 Subject: [PATCH 6/8] David: Additional Code on Checks --- .../modules/rcpt/update_descriptives_new.qy | 117 ++++++++++++++---- 1 file changed, 91 insertions(+), 26 deletions(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index 5a030404..41cd2e54 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -486,6 +486,19 @@ update_descriptives_new "system/query" (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; + + + -- David: This is where the checks come in the code for the descriptives. And where I will try to give/insert ideas on the code + + -- add extra columns to the a_descriptives_hist and a_descriptives collections the first time data is inserted into them. + -- Just make each check a bit column (it may be easier to make it an int column as use it like a bit; bits tend to have more limitations), + -- and set everything to 0/false initially. Note that these collections are eventually inserted into corresponding database tables (of the same name), + -- which will not have the new columns you added to the collections. + -- Because of this, there is a need to use the information gained from your checks to update existing columns. + -- Also, I would like to add extra checks on this part of code. + + + -- Overall adjustments to a_act_average_xyz for a_descriptives -- if the interval is biannual or less, lookback slightly less than a year from the most recent gift -- the lookahead date is half an interval past the most recent gift @@ -503,7 +516,7 @@ update_descriptives_new "system/query" (:parameters:fund is null or :parameters:fund = :d:a_fund) and (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; - -- if the interval is greater than bi-annually, check back the last three intervals + -- if the interval is greater than bi-annually, check back the last three intervals (Question: Does it mean more than twice a year but still in the same year?) update identity collection a_descriptives d set @@ -517,7 +530,7 @@ update_descriptives_new "system/query" (:parameters:fund is null or :parameters:fund = :d:a_fund) and (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; - -- this handles one time gifts (and giving that falls all within half a month) + -- this handles one time gifts (and giving that falls all within half a month) ( Question: Figured out that in line around 628-634 that it is counting in/between a year. Am I right?) update identity collection a_descriptives d set @@ -551,6 +564,24 @@ update_descriptives_new "system/query" (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; + -- From the previous checks, thats why I made this to handle the pledges that are once every 1 year or more + -- (David): this handles pledges that are once every 1 year or more + update + identity collection a_descriptives d + set + :a_act_average_interval = convert(double, null), + :a_act_average_months = null, + :a_act_average_amount = convert(money, null), + :a_act_lookahead_date = condition(getdate() < dateadd(day, 366, :a_last_gift), getdate(), dateadd(day, 366, :a_last_gift)), + :a_act_lookback_date = :a_first_gift + where + :a_act_average_months >= 12 and + (:parameters:fund is null or :parameters:fund = :d:a_fund) and + (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) + ; + + + -- Update a_act_average_xyz for a_descriptives_hist update identity collection a_descriptives_hist dh @@ -648,41 +679,60 @@ update_descriptives_new "system/query" (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; - -- Identify increases in giving. An increase is when the history entry has a larger monthly - -- average than the immediately previous history entry that is not a one-time-extra gift. We - -- also require that the history entry and its predecessor both have at least two gifts, - -- unless the giving interval is greater than 7 (effectively yearly), in which case any - -- number of gifts for either produces useful results. - print 'Identifying increases at ' + dateformat(getdate(), 'hh:mm:ss'); - update + + -- (David) Below here I will try to add checks if the amount doubles. I hope that it makes sense. If it dosent, please let me know and correct me. + + + -- Identify increases in giving. An increase is when the history entry has a larger monthly + -- average than the immediately previous history entry that is not a one-time-extra gift. We + -- also require that the history entry and its predecessor both have at least two gifts, + -- unless the giving interval is greater than 7 (effectively yearly), in which case any + -- number of gifts for either produces useful results. + print 'Identifying increases at ' + dateformat(getdate(), 'hh:mm:ss'); + update identity collection a_descriptives_hist dh - set + set :dh:a_increase_pct = condition( - :dh:a_act_average_interval > 7 or (datediff(day, :dh:a_prev_end, :dh:a_first_gift) > 212 and :dh:a_count = 1), - convert(double, :dh:a_amount) / convert(double, isnull((select :dh2:a_amount from collection a_descriptives_hist dh2 where :dh2:a_ledger_number = :dh:a_ledger_number and :dh2:a_fund = :dh:a_fund and :dh2:p_donor_partner_key = :dh:p_donor_partner_key and isnull(:dh2:a_is_extra, 0) = 0 and :dh2:a_last_gift < :dh:a_first_gift order by :dh2:a_last_gift desc limit 1), :dh:a_amount)) - 1.0, - condition( - :dh:a_count > 1, - convert(double, :dh:a_amount) / condition(round(:dh:a_act_average_interval) < 1, 1, round(:dh:a_act_average_interval)) / convert(double, isnull((select :dh2:a_amount / condition(round(:dh2:a_act_average_interval) < 1, 1, round(:dh2:a_act_average_interval)) from collection a_descriptives_hist dh2 where :dh2:a_ledger_number = :dh:a_ledger_number and :dh2:a_fund = :dh:a_fund and :dh2:p_donor_partner_key = :dh:p_donor_partner_key and isnull(:dh2:a_is_extra, 0) = 0 and :dh2:a_last_gift < :dh:a_first_gift and :dh2:a_count > 1 order by :dh2:a_last_gift desc limit 1), :dh:a_amount / condition(round(:dh:a_act_average_interval) < 1, 1, round(:dh:a_act_average_interval)))) - 1.0, - null - ) - ) - where + :dh:a_act_average_interval > 7 or (datediff(day, :dh:a_prev_end, :dh:a_first_gift) > 212 and :dh:a_count = 1), + convert(double, :dh:a_amount) / convert(double, isnull((select :dh2:a_amount from collection a_descriptives_hist dh2 where :dh2:a_ledger_number = :dh:a_ledger_number and :dh2:a_fund = :dh:a_fund and :dh2:p_donor_partner_key = :dh:p_donor_partner_key and isnull(:dh2:a_is_extra, 0) = 0 and :dh2:a_last_gift < :dh:a_first_gift order by :dh2:a_last_gift desc limit 1), :dh:a_amount)) - 1.0, + condition( + :dh:a_count > 1, + convert(double, :dh:a_amount) / condition(round(:dh:a_act_average_interval) < 1, 1, round(:dh:a_act_average_interval)) / convert(double, isnull((select :dh2:a_amount / condition(round(:dh2:a_act_average_interval) < 1, 1, round(:dh2:a_act_average_interval)) from collection a_descriptives_hist dh2 where :dh2:a_ledger_number = :dh:a_ledger_number and :dh2:a_fund = :dh:a_fund and :dh2:p_donor_partner_key = :dh:p_donor_partner_key and isnull(:dh2:a_is_extra, 0) = 0 and :dh2:a_last_gift < :dh:a_first_gift and :dh2:a_count > 1 order by :dh2:a_last_gift desc limit 1), :dh:a_amount / condition(round(:dh:a_act_average_interval) < 1, 1, round(:dh:a_act_average_interval)))) - 1.0, + null + ) + ) + where (:parameters:fund is null or :parameters:fund = :dh:a_fund) and (:parameters:donor is null or :parameters:donor = :dh:p_donor_partner_key) and - not isnull(:dh:a_is_extra, 0) != 0 - ; - update + not isnull(:dh:a_is_extra, 0) != 0 + ; + update identity collection a_descriptives_hist dh, collection a_descriptives d - set + set :dh:a_increase_pct = condition((:dh:a_count > 1 or :d:a_act_average_interval > 1.8) and :dh:a_increase_pct > 0.001, :dh:a_increase_pct, null) - where + where :d:a_ledger_number = :dh:a_ledger_number and :d:a_fund = :dh:a_fund and :d:p_donor_partner_key = :dh:p_donor_partner_key and (:parameters:fund is null or :parameters:fund = :dh:a_fund) and (:parameters:donor is null or :parameters:donor = :dh:p_donor_partner_key) - ; + ; + + -- Check if the amount is doubled + print 'Checking if the amount is (at least) doubled at ' + dateformat(getdate(), 'hh:mm:ss'); + update + identity collection a_descriptives_hist dh + set + :dh:a_is_doubled = condition(:dh:a_increase_pct > 1.0, 1, 0) -- Using the dh:a_increase_pct to check if the amount is doubled or not (if the condition is wrong, should the first condition could be more than one and less than 2?) + where + (:parameters:fund is null or :parameters:fund = :dh:a_fund) and + (:parameters:donor is null or :parameters:donor = :dh:p_donor_partner_key) and + not isnull(:dh:a_is_extra, 0) != 0 + ; + + + -- (David) Below here I will try to add checks if the amount halves -- Identify decreases in giving. A decrease is when the history entry has a smaller monthly -- average than the immediately previous history entry that is not a one-time-extra gift. We @@ -716,7 +766,22 @@ update_descriptives_new "system/query" (:parameters:donor is null or :parameters:donor = :dh:p_donor_partner_key) ; - -- Propagate informational flags/data to the overall giving descriptives + + -- Check if the amount halves + print 'Checking if the amount (at least) halves at ' + dateformat(getdate(), 'hh:mm:ss'); + update + identity collection a_descriptives_hist dh + set + :dh:a_is_halved = condition(:dh:a_decrease_pct > 0.5, 1, 0) -- Using the dh:a_decrease_pct to check if the amount halves or not + where + (:parameters:fund is null or :parameters:fund = :dh:a_fund) and + (:parameters:donor is null or :parameters:donor = :dh:p_donor_partner_key) and + not isnull(:dh:a_is_extra, 0) != 0 + ; + (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) + ; + + -- Propagate informational flags/data to the overall giving descriptives print 'Setting informational flags at ' + dateformat(getdate(), 'hh:mm:ss'); update identity collection a_descriptives d From 3664ac37da3328f7b6ad031f0d410bc47e3dd0dd Mon Sep 17 00:00:00 2001 From: David Hopkins Date: Mon, 5 Aug 2024 17:59:27 -0400 Subject: [PATCH 7/8] Additional change on Pledges that are once every 1 year or more --- kardia-app/modules/rcpt/update_descriptives_new.qy | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index 41cd2e54..4addeaff 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -572,7 +572,12 @@ update_descriptives_new "system/query" :a_act_average_interval = convert(double, null), :a_act_average_months = null, :a_act_average_amount = convert(money, null), - :a_act_lookahead_date = condition(getdate() < dateadd(day, 366, :a_last_gift), getdate(), dateadd(day, 366, :a_last_gift)), + -- Can you please make sure my condition is correct for the lookback and lookahead dates? + :a_act_lookahead_date = condition( + getdate() < dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift), + getdate(), + dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift) + ), :a_act_lookback_date = :a_first_gift where :a_act_average_months >= 12 and From f42082ea26bdd482650e26109e7ad9f93450741a Mon Sep 17 00:00:00 2001 From: David Hopkins Date: Thu, 8 Aug 2024 21:33:31 -0400 Subject: [PATCH 8/8] Fixtures #1 and Adding extra columns to Descriptives Column (History too) --- .../modules/rcpt/update_descriptives_new.qy | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/kardia-app/modules/rcpt/update_descriptives_new.qy b/kardia-app/modules/rcpt/update_descriptives_new.qy index 4addeaff..27ad8697 100644 --- a/kardia-app/modules/rcpt/update_descriptives_new.qy +++ b/kardia-app/modules/rcpt/update_descriptives_new.qy @@ -498,6 +498,21 @@ update_descriptives_new "system/query" -- Also, I would like to add extra checks on this part of code. + -- Where should this block of code go? What is the best place? + -- Add extra columns to a_descriptives_hist collection + alter collection a_descriptives_hist + add column a_check_1 bit default 0, + add column a_check_2 bit default 0, + add column a_check_3 bit default 0; + + -- Add extra columns to a_descriptives collection + alter collection a_descriptives + add column a_check_1 bit default 0, + add column a_check_2 bit default 0, + add column a_check_3 bit default 0; + + + -- Overall adjustments to a_act_average_xyz for a_descriptives -- if the interval is biannual or less, lookback slightly less than a year from the most recent gift @@ -516,7 +531,7 @@ update_descriptives_new "system/query" (:parameters:fund is null or :parameters:fund = :d:a_fund) and (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; - -- if the interval is greater than bi-annually, check back the last three intervals (Question: Does it mean more than twice a year but still in the same year?) + -- if the interval is greater than bi-annually, check back the last three intervals update identity collection a_descriptives d set @@ -530,8 +545,7 @@ update_descriptives_new "system/query" (:parameters:fund is null or :parameters:fund = :d:a_fund) and (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; - -- this handles one time gifts (and giving that falls all within half a month) ( Question: Figured out that in line around 628-634 that it is counting in/between a year. Am I right?) - update + -- this handles one time gifts (and giving that falls all within half a month) identity collection a_descriptives d set :a_act_average_interval = convert(double, null), @@ -572,15 +586,19 @@ update_descriptives_new "system/query" :a_act_average_interval = convert(double, null), :a_act_average_months = null, :a_act_average_amount = convert(money, null), - -- Can you please make sure my condition is correct for the lookback and lookahead dates? + -- (David) Added the third condition which is about checking the future date :a_act_lookahead_date = condition( getdate() < dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift), getdate(), - dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift) + condition( + dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift) > getdate(), + getdate(), + dateadd(day, convert(integer, round(0.5 * 30.5 * :a_act_average_interval)), :a_last_gift) + ) ), :a_act_lookback_date = :a_first_gift where - :a_act_average_months >= 12 and + :a_act_average_interval >= 12 and -- Yes, it might be that it is interval. (:parameters:fund is null or :parameters:fund = :d:a_fund) and (:parameters:donor is null or :parameters:donor = :d:p_donor_partner_key) ; @@ -729,7 +747,7 @@ update_descriptives_new "system/query" update identity collection a_descriptives_hist dh set - :dh:a_is_doubled = condition(:dh:a_increase_pct > 1.0, 1, 0) -- Using the dh:a_increase_pct to check if the amount is doubled or not (if the condition is wrong, should the first condition could be more than one and less than 2?) + :dh:a_is_doubled = condition(:dh:a_increase_pct >= 1.0, 1, 0) -- Using the dh:a_increase_pct to check if the amount is doubled or not (if the condition is wrong, should the first condition could be more than one and less than 2?) where (:parameters:fund is null or :parameters:fund = :dh:a_fund) and (:parameters:donor is null or :parameters:donor = :dh:p_donor_partner_key) and