Commit ccb38995 authored by Jacob Priddy's avatar Jacob Priddy 👌

Fix door failure query to only return doors with more than 4 entries and

failures
parent 51ee0176
Pipeline #12533 passed with stages
in 2 minutes and 36 seconds
......@@ -56,9 +56,9 @@ select S.id,
S.last_seen_at,
S.created_at,
S.updated_at,
(CASE (S.failures::float + S.entries::float)
(CASE (S.total::float)
WHEN 0 THEN 0::float
ELSE (S.failures::float / (S.failures::float + S.entries::float)) END) failure_ratio
ELSE (S.failures::float / (S.total::float)) END) failure_ratio
FROM (
SELECT D.id,
D.location,
......@@ -68,20 +68,34 @@ FROM (
D.last_seen_at,
D.created_at,
D.updated_at,
(
SELECT COUNT(*)
FROM attempts A
WHERE A.door_id = D.id
AND A.created_at BETWEEN :BEGIN AND :END
) failures,
(
SELECT COUNT(*)
FROM entries E
WHERE E.door_id = D.id
AND E.created_at BETWEEN :BEGIN AND :END
) entries
FROM doors as D
D.failures,
D.entries,
D.failures + D.entries as total
FROM (
SELECT D.id,
D.location,
D.name,
D.api_token,
D.version,
D.last_seen_at,
D.created_at,
D.updated_at,
(
SELECT COUNT(*)
FROM attempts A
WHERE A.door_id = D.id
AND A.created_at BETWEEN :BEGIN AND :END
) failures,
(
SELECT COUNT(*)
FROM entries E
WHERE E.door_id = D.id
AND E.created_at BETWEEN :BEGIN AND :END
) entries
FROM doors as D
) as D
) as S
WHERE S.total > 4
ORDER BY failure_ratio DESC
LIMIT :LIMIT
QUERY;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment