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

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, ...@@ -56,9 +56,9 @@ select S.id,
S.last_seen_at, S.last_seen_at,
S.created_at, S.created_at,
S.updated_at, S.updated_at,
(CASE (S.failures::float + S.entries::float) (CASE (S.total::float)
WHEN 0 THEN 0::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 ( FROM (
SELECT D.id, SELECT D.id,
D.location, D.location,
...@@ -68,20 +68,34 @@ FROM ( ...@@ -68,20 +68,34 @@ FROM (
D.last_seen_at, D.last_seen_at,
D.created_at, D.created_at,
D.updated_at, D.updated_at,
( D.failures,
SELECT COUNT(*) D.entries,
FROM attempts A D.failures + D.entries as total
WHERE A.door_id = D.id FROM (
AND A.created_at BETWEEN :BEGIN AND :END SELECT D.id,
) failures, D.location,
( D.name,
SELECT COUNT(*) D.api_token,
FROM entries E D.version,
WHERE E.door_id = D.id D.last_seen_at,
AND E.created_at BETWEEN :BEGIN AND :END D.created_at,
) entries D.updated_at,
FROM doors as D (
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 ) as S
WHERE S.total > 4
ORDER BY failure_ratio DESC ORDER BY failure_ratio DESC
LIMIT :LIMIT LIMIT :LIMIT
QUERY; QUERY;
......
Supports Markdown
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