Skip to content

Commit

Permalink
reduce loops for summary calculation
Browse files Browse the repository at this point in the history
Change-Id: Ifc31f60ae543c97fa4d9a541607a7ede3c98ee3f
  • Loading branch information
otAAAh committed Feb 7, 2025
1 parent 5bc81f4 commit a08a179
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmk/gui/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a08a179

Please sign in to comment.