Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create a submission_services_summary database view for analytics #2430

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,9 @@
- locked_at:
_is_null: true
check: null
- table:
schema: public
name: submission_services_summary
- table:
schema: public
name: team_members
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP VIEW public.submission_services_summary CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
CREATE OR REPLACE VIEW public.submission_services_summary AS
with resumes_per_session as (
select
session_id,
count(id) as number_times_resumed
from reconciliation_requests
group by session_id
)
select
ls.id as session_id,
t.slug as team_slug,
f.slug as service_slug,
ls.created_at,
ls.submitted_at,
(ls.submitted_at::date - ls.created_at::date) as session_length_days,
ls.has_user_saved as user_clicked_save,
rps.number_times_resumed,
case
when pr.id is null
then false
else true
end as user_invited_to_pay,
case
when ba.bops_id is null
then false
else true
end as sent_to_bops,
case
when ua.idox_submission_id is null
then false
else true
end as sent_to_uniform,
case
when ea.id is null
then false
else true
end as sent_to_email
from lowcal_sessions ls
left join flows f on f.id = ls.flow_id
left join teams t on t.id = f.team_id
left join resumes_per_session rps on rps.session_id = ls.id::text
left join payment_requests pr on pr.session_id = ls.id
left join bops_applications ba on ba.session_id = ls.id::text
left join uniform_applications ua on ua.submission_reference = ls.id::text
left join email_applications ea on ea.session_id = ls.id
where f.slug IS NOT NULL
and t.slug IS NOT NULL;