diff --git a/app/data/cumul_2025_by_week.json b/app/data/cumul_2025_by_week.json new file mode 100644 index 0000000..db81756 --- /dev/null +++ b/app/data/cumul_2025_by_week.json @@ -0,0 +1 @@ +{"1": 319, "2": 321, "3": 339, "4": 352, "5": 359, "6": 380, "7": 388, "8": 477, "9": 521, "10": 581, "11": 598, "12": 648, "13": 674, "14": 681, "15": 710, "16": 776, "17": 810, "18": 835, "19": 850, "20": 851, "21": 864, "22": 868, "23": 872, "24": 873, "25": 878, "26": 879, "27": 882, "28": 882, "29": 882, "30": 882, "31": 882, "32": 882, "33": 882, "34": 882, "35": 883, "36": 883, "37": 883, "38": 886, "39": 887, "40": 888, "41": 888, "42": 893, "43": 898, "44": 910, "45": 915, "46": 915, "47": 924, "48": 929, "49": 934, "50": 943, "51": 956, "52": 956} \ No newline at end of file diff --git a/app/routers/audit_full.py b/app/routers/audit_full.py index 1932369..634a2de 100644 --- a/app/routers/audit_full.py +++ b/app/routers/audit_full.py @@ -272,11 +272,25 @@ async def audit_full_patching(request: Request, db=Depends(get_db)): f" AND saf.{_latest}" )).fetchone() - # Comparaison Y-1 + # Comparaison Y-1 a meme semaine compare = None from datetime import datetime as _dt current_week = _dt.now().isocalendar()[1] if year == 2026: + # Cumulatif 2025 a la meme semaine (pre-calcule) + import json as _json, os as _os + cumul_2025_path = _os.path.join(_os.path.dirname(_os.path.abspath(__file__)), "..", "data", "cumul_2025_by_week.json") + prev_at_same_week = 0 + prev_total = 1045 + prev_data_ok = False + try: + with open(cumul_2025_path) as f: + cumul_2025 = _json.load(f) + prev_at_same_week = cumul_2025.get(str(current_week - 1), cumul_2025.get(str(current_week), 0)) + prev_data_ok = True + except Exception: + pass + compare = db.execute(text( f"SELECT" f" COUNT(*) FILTER (WHERE patch_count_2026 >= 1) as current_patched," @@ -284,14 +298,15 @@ async def audit_full_patching(request: Request, db=Depends(get_db)): f" COUNT(*) as total" f" FROM server_audit_full WHERE status IN ('ok','partial') AND {_latest}" )).fetchone() - elif year == 2025: - compare = db.execute(text( - f"SELECT" - f" COUNT(*) FILTER (WHERE patch_count_2025 >= 1) as current_patched," - f" 0 as prev_year_total," - f" COUNT(*) as total" - f" FROM server_audit_full WHERE status IN ('ok','partial') AND {_latest}" - )).fetchone() + compare = { + "current_patched": compare.current_patched, + "current_total": compare.total, + "prev_year_total": compare.prev_year_total, + "prev_at_same_week": prev_at_same_week, + "prev_total": prev_total, + "prev_data_ok": prev_data_ok, + "compare_week": current_week - 1, + } patch_by_domain = db.execute(text( f"SELECT d.name as domain, d.code," diff --git a/app/templates/audit_full_patching.html b/app/templates/audit_full_patching.html index 30e5ce5..89daba6 100644 --- a/app/templates/audit_full_patching.html +++ b/app/templates/audit_full_patching.html @@ -57,41 +57,49 @@ {% if compare and year == 2026 %} -{% set pct_current = (compare.current_patched / compare.total * 100)|int if compare.total > 0 else 0 %} -{% set pct_prev = (compare.prev_year_total / compare.total * 100)|int if compare.total > 0 else 0 %} -{% set diff = compare.current_patched - compare.prev_year_total %} -{% set diff_pct = pct_current - pct_prev %} +{% set pct_current = (compare.current_patched / compare.current_total * 100)|int if compare.current_total > 0 else 0 %} +{% set pct_prev_same = (compare.prev_at_same_week / compare.prev_total * 100)|int if compare.prev_total > 0 else 0 %} +{% set pct_prev_total = (compare.prev_year_total / compare.current_total * 100)|int if compare.current_total > 0 else 0 %} +{% set diff_same = pct_current - pct_prev_same %}