From a08a179340adf0d2bbc8655aaa8b5054bbd7c231 Mon Sep 17 00:00:00 2001 From: Benjamin Knapp Date: Thu, 6 Feb 2025 11:15:07 +0100 Subject: [PATCH] reduce loops for summary calculation Change-Id: Ifc31f60ae543c97fa4d9a541607a7ede3c98ee3f --- cmk/gui/availability.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmk/gui/availability.py b/cmk/gui/availability.py index 098c2da51b9..c1d21c9fd6a 100644 --- a/cmk/gui/availability.py +++ b/cmk/gui/availability.py @@ -1808,6 +1808,8 @@ def layout_availability_table( # pylint: disable=too-many-branches availability_columns, avoptions, os_aggrs, os_states, timeformats, what ) + summary["ok_level"] = 0 + # Actual rows for entry in availability_table: site = entry["site"] @@ -1888,18 +1890,17 @@ def layout_availability_table( # pylint: disable=too-many-branches statistics.append(("", "")) cells.extend(statistics) - # regardless of timeformat the percentage value should be taken for summary levels - # verification since the percentage value takes the considered duration as reference duration - if show_summary and av_levels: - summary["ok_level"] = sum( - float(entry["states"].get("ok", 0)) / entry["considered_duration"] - for entry in availability_table - if entry["considered_duration"] > 0 - ) # If timeline == [] and states == {} then this objects has complete unmonitored state if entry["timeline"] == [] and entry["states"] == {}: unmonitored_objects += 1 + # regardless of timeformat the percentage value should be taken for summary levels + # verification since the percentage value takes the considered duration as reference duration + if show_summary and av_levels: + summary["ok_level"] += ( + float(entry["states"].get("ok", 0)) / entry["considered_duration"] + ) + # Summary line. It has the same format as each entry in cells # We ignore unmonitored objects len_availability_table = len(availability_table) - unmonitored_objects