From 8286fe062449190ceca30c3682facd2168f9e8bb Mon Sep 17 00:00:00 2001 From: Khalid MOUTAOUAKIL Date: Mon, 6 Apr 2026 23:30:30 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20histogramme:=20cancelled=5Fweeks=20s?= =?UTF-8?q?=C3=A9par=C3=A9s,=20barres=20empil=C3=A9es=20vert+rouge=20par?= =?UTF-8?q?=20semaine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- app/routers/audit_full.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/routers/audit_full.py b/app/routers/audit_full.py index a3aef5e..b7c6e84 100644 --- a/app/routers/audit_full.py +++ b/app/routers/audit_full.py @@ -287,16 +287,19 @@ async def audit_full_patching(request: Request, db=Depends(get_db)): patch_weekly = [] if year == 2026: - patch_weekly = db.execute(text( - "SELECT pw.week, SUM(pw.patched) as patched, SUM(pw.cancelled) as cancelled FROM (" - " SELECT unnest(string_to_array(patch_weeks_2026, ',')) as week," - " CASE WHEN patch_status_2026 = 'patched' THEN 1 ELSE 0 END as patched," - " CASE WHEN patch_status_2026 IN ('cancelled','reported') THEN 1 ELSE 0 END as cancelled" - " FROM server_audit_full" - " WHERE status IN ('ok','partial') AND patch_weeks_2026 IS NOT NULL AND patch_weeks_2026 != ''" - " AND id IN (SELECT DISTINCT ON (hostname) id FROM server_audit_full WHERE status IN ('ok','partial') ORDER BY hostname, audit_date DESC)" - ") pw WHERE pw.week != '' GROUP BY pw.week ORDER BY pw.week" - )).fetchall() + patch_weekly = db.execute(text(""" + SELECT week, SUM(patched)::int as patched, SUM(cancelled)::int as cancelled FROM ( + SELECT unnest(string_to_array(patch_weeks_2026, ',')) as week, 1 as patched, 0 as cancelled + FROM server_audit_full + WHERE status IN ('ok','partial') AND patch_weeks_2026 IS NOT NULL AND patch_weeks_2026 != '' + AND id IN (SELECT DISTINCT ON (hostname) id FROM server_audit_full WHERE status IN ('ok','partial') ORDER BY hostname, audit_date DESC) + UNION ALL + SELECT unnest(string_to_array(cancelled_weeks_2026, ',')) as week, 0 as patched, 1 as cancelled + FROM server_audit_full + WHERE status IN ('ok','partial') AND cancelled_weeks_2026 IS NOT NULL AND cancelled_weeks_2026 != '' + AND id IN (SELECT DISTINCT ON (hostname) id FROM server_audit_full WHERE status IN ('ok','partial') ORDER BY hostname, audit_date DESC) + ) combined WHERE week != '' GROUP BY week ORDER BY week + """)).fetchall() all_domains = db.execute(text("SELECT code, name, 'domain' as type FROM domains ORDER BY name")).fetchall() all_zones = db.execute(text("SELECT name as code, name, 'zone' as type FROM zones ORDER BY name")).fetchall()