Open tahini opened 1 month ago
Here's the complete query to give the completion ratio for a survey (note that for person specific sections, completion is per person, so this query will return 0 for those sections. It does not mean they are not complete:
select section_name, count(id), sum(is_completed) from (
select i.id, s.key as section_name, (s.value::json->>'_startedAt') as started_at, case when (s.value::json->>'_isCompleted')::boolean is not true then 0 else 1 end as is_completed
from sv_interviews i
left join json_each_text(responses->'_sections') s on true
where s.key != '_actions'
) group by section_name
order by count(id) desc
To implement the widget, search for getStartedAndCompletedInterviewsByDay
and started-and-completed-interviews-by-day
in the code to get inspiration.
Such a graph exists in od_mtl, but we use an adminView to get the completion data. We could get it with a query directly, but it could be a long query for large surveys. The default implementation could be with a direct query to the responses and we can change to adminView when required.
Here's the query to get the section status:
We can then use a group by and sum/count to get started/completed