Skip to content

Commit 6f325fa

Browse files
authored
Merge pull request #618 from CodeForPhilly/605-aggregate-ids
aggregate all shelterluv and volgistics ids associated with one contact
2 parents 204744f + bcc23c3 commit 6f325fa

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- "5432:5432"
99
image: postgres:15.4-alpine
1010
volumes:
11-
- postgres15:/var/lib/postgresql15/data
11+
- postgres15:/var/lib/postgresql/data
1212
environment:
1313
POSTGRES_DB: paws
1414
POSTGRES_PASSWORD: thispasswordisverysecure

src/server/api/API_ingest/updated_data.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ def get_updated_contact_data():
1111
Session = sessionmaker(engine)
1212

1313
qry = """ -- Collect latest foster/volunteer dates
14-
select json_agg (upd) as "cd"
14+
select json_agg (upd) as "cd"
1515
from (
1616
select
1717
sf.source_id as "Id" , -- long salesforce string
18-
sle.person_id as "Person_Id__c", -- short PAWS-local shelterluv id
18+
array_agg(sl.source_id) filter (where sl.source_id is not null) as "Person_Id__c", -- short PAWS-local shelterluv id
1919
case
2020
when
21-
(extract(epoch from now())::bigint - foster_out < 365*86400) -- foster out in last year
22-
or (extract(epoch from now())::bigint - foster_return < 365*86400) -- foster return
21+
(extract(epoch from now())::bigint - max(foster_out) < 365*86400) -- foster out in last year
22+
or (extract(epoch from now())::bigint - max(foster_return) < 365*86400) -- foster return
2323
then 'Active'
2424
else 'Inactive'
2525
end as "Foster_Activity__c",
26-
foster_out as "Foster_Start_Date__c",
27-
foster_return as "Foster_End_Date__c",
28-
vol.first_date "First_volunteer_date__c",
29-
vol.last_date "Last_volunteer_date__c",
30-
vol.hours as "Total_volunteer_hours__c",
31-
vc.source_id::integer as "Volgistics_Id__c"
26+
max(foster_out) as "Foster_Start_Date__c",
27+
max(foster_return) as "Foster_End_Date__c",
28+
min(vol.first_date) "First_volunteer_date__c",
29+
max(vol.last_date) "Last_volunteer_date__c",
30+
sum(vol.hours) as "Total_volunteer_hours__c",
31+
array_agg(vc.source_id::integer) filter(where vc.source_id is not null) as "Volgistics_Id__c"
3232
from (
3333
select source_id, matching_id from pdp_contacts sf
3434
where sf.source_type = 'salesforcecontacts'
@@ -55,6 +55,7 @@ def get_updated_contact_data():
5555
group by volg_id
5656
) vol on vol.volg_id::text = vc.source_id
5757
where sl.matching_id is not null or vc.matching_id is not null
58+
group by sf.source_id
5859
) upd;
5960
"""
6061

0 commit comments

Comments
 (0)