Skip to content
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
32 changes: 19 additions & 13 deletions DSL/Resql/analytics/POST/chat-count-only-chatbot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ FROM chat c
WHERE c.status = 'ENDED'
AND c.ended::timestamptz BETWEEN :start::timestamptz AND :end::timestamptz
ORDER BY c.base_id, c.updated DESC
),
csa_ids AS (
SELECT DISTINCT base_id
FROM latest_per_base lp
WHERE EXISTS (
SELECT 1 FROM message m
WHERE m.chat_base_id = lp.base_id
AND m.author_role = 'backoffice-user'
)
AND EXISTS (
SELECT 1 FROM message m
WHERE m.chat_base_id = lp.base_id
AND (m.event = 'taken-over' OR m.event = 'pending-assigned')
)
)
SELECT
DATE_TRUNC(:period, lp.ended) AS time,
Expand All @@ -12,19 +26,11 @@ FROM latest_per_base lp
WHERE (:showTest = TRUE OR lp.test = FALSE)
AND (
array_length(ARRAY[:urls]::TEXT[], 1) IS NULL
OR lp.end_user_url LIKE ANY(ARRAY[:urls]::TEXT[])
)
OR lp.end_user_url LIKE ANY(ARRAY[:urls]::TEXT[])
)
AND NOT EXISTS (
SELECT 1
FROM message m
WHERE m.chat_base_id = lp.base_id
AND m.author_role = 'backoffice-user'
)
AND NOT EXISTS (
SELECT 1
FROM message m
WHERE m.chat_base_id = lp.base_id
AND m.event = 'taken-over'
)
SELECT 1 FROM csa_ids c
WHERE c.base_id = lp.base_id
)
GROUP BY time
ORDER BY time ASC;
26 changes: 8 additions & 18 deletions DSL/Resql/analytics/POST/chat-count-with-csa-and-chatbot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ WHERE c.status = 'ENDED'
AND c.ended::timestamptz BETWEEN :start::timestamptz AND :end::timestamptz
ORDER BY c.base_id, c.updated DESC
),

chatbot_ids AS (
csa_ids AS (
SELECT DISTINCT time, base_id
FROM latest_per_base b
WHERE NOT EXISTS (
WHERE EXISTS (
SELECT 1 FROM message m
WHERE m.chat_base_id = b.base_id
AND m.author_role = 'backoffice-user'
)
AND NOT EXISTS (
AND EXISTS (
SELECT 1 FROM message m
WHERE m.chat_base_id = b.base_id
AND m.event = 'taken-over'
AND (m.event = 'taken-over' or m.event = 'pending-assigned')
)
AND (
:showTest = TRUE
Expand All @@ -34,19 +33,12 @@ chatbot_ids AS (
OR b.end_user_url LIKE ANY(ARRAY[:urls]::TEXT[])
)
),

csa_ids AS (
chatbot_ids AS (
SELECT DISTINCT time, base_id
FROM latest_per_base b
WHERE EXISTS (
SELECT 1 FROM message m
WHERE m.chat_base_id = b.base_id
AND m.author_role = 'backoffice-user'
)
AND EXISTS (
SELECT 1 FROM message m
WHERE m.chat_base_id = b.base_id
AND (m.event = 'taken-over' or m.event = 'pending-assigned' or m.event = 'forwarded_to_backoffice')
WHERE NOT EXISTS (
SELECT 1 FROM csa_ids c
WHERE c.base_id = b.base_id
)
AND (
:showTest = TRUE
Expand All @@ -57,13 +49,11 @@ csa_ids AS (
OR b.end_user_url LIKE ANY(ARRAY[:urls]::TEXT[])
)
),

combined AS (
SELECT time, base_id FROM chatbot_ids
UNION
SELECT time, base_id FROM csa_ids
)

SELECT time, COUNT(*) AS sum_count
FROM combined
GROUP BY time
Expand Down
8 changes: 4 additions & 4 deletions DSL/Resql/analytics/POST/chat-count-with-csa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ WHERE (:showTest = TRUE OR lp.test = FALSE)
SELECT 1
FROM message m
WHERE m.chat_base_id = lp.base_id
AND m.author_role = 'backoffice-user'
)
AND m.author_role = 'backoffice-user'
)
AND EXISTS (
SELECT 1
FROM message m
WHERE m.chat_base_id = lp.base_id
AND m.event = 'taken-over' or m.event = 'pending-assigned'
)
AND (m.event = 'taken-over' OR m.event = 'pending-assigned')
)
GROUP BY time
ORDER BY time ASC;
Loading