Skip to content

Commit

Permalink
refactor: remove worst traffic light
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the `worst` entry will no long be present in the datastore
  • Loading branch information
sbrugman committed Jul 4, 2022
1 parent 4c99fa1 commit e2b9ef7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
3 changes: 0 additions & 3 deletions popmon/alerting/alerts_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def transform(self, data: dict) -> Optional[dict]:
tlv = pd.concat(df_list, axis=1)
dfc = pd.DataFrame(index=tlv.index)

# worst traffic light
cols = fnmatch.filter(tlv.columns, "*_worst")
dfc["worst"] = tlv[cols].values.max(axis=1) if len(cols) else 0
# colors of traffic lights
for color in ["green", "yellow", "red"]:
cols = fnmatch.filter(tlv.columns, f"*_n_{color}")
Expand Down
11 changes: 4 additions & 7 deletions popmon/alerting/compute_tl_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@
def traffic_light_summary(row, cols=None, prefix=""):
"""Make a summary of traffic light alerts present in the dataframe
Count number of green, yellow, red traffic lights and worst value.
Count number of green, yellow and red traffic lights.
Evaluate with df.apply(traffic_light_summary, axis=1)
:param pd.Series row: row to calculate traffic light summary of.
:param list cols: list of cols to calculate traffic light summary of (optional)
:param str prefix: prefix of traffic light columns, in case cols is empty. default is ``"tl_"``
"""
x = pd.Series(
{"worst": np.nan, "n_red": np.nan, "n_yellow": np.nan, "n_green": np.nan}
)
x = {"n_red": np.nan, "n_yellow": np.nan, "n_green": np.nan}

if cols is None or len(cols) == 0:
# if no columns are given, find traffic light columns for which summary is made.
Expand All @@ -53,14 +51,13 @@ def traffic_light_summary(row, cols=None, prefix=""):
else row.index.to_list()
)
if len(cols) == 0:
return x
return pd.Series(x)

traffic_lights = np.array([row[c] for c in cols])
x["worst"] = np.max(traffic_lights)
x["n_red"] = (traffic_lights == 2).sum()
x["n_yellow"] = (traffic_lights == 1).sum()
x["n_green"] = (traffic_lights == 0).sum()
return x
return pd.Series(x)


def traffic_light(value, red_high, yellow_high, yellow_low=0, red_low=0):
Expand Down

0 comments on commit e2b9ef7

Please sign in to comment.