Skip to content

Commit

Permalink
refactor: use defaultdict in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Jun 14, 2022
1 parent bdc3768 commit 5539848
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions popmon/visualization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import logging
import math
from collections import defaultdict
from io import BytesIO, StringIO
from typing import List

Expand Down Expand Up @@ -162,10 +163,9 @@ def plot_bars_b64(data, labels=None, bounds=None, ylim=False, skip_empty=True):


def render_traffic_lights_table(feature, data, metrics: List[str], labels: List[str]):
colors = {}
color_map = ["green", "yellow", "red"]
colors = defaultdict(dict)
color_map = ["g", "y", "r"]
for c1, metric in enumerate(metrics):
colors[metric] = {}
for c2, label in enumerate(labels):
colors[metric][label] = [color_map[data[c1][c2]]]

Expand All @@ -184,9 +184,8 @@ def plot_traffic_lights_overview(feature, data, metrics=None, labels=None):


def render_alert_aggregate_table(feature, data, metrics: List[str], labels: List[str]):
colors = {}
colors = defaultdict(dict)
for c1, metric in enumerate(metrics):
colors[metric] = {}
row_max = np.max(data[c1])
for c2, label in enumerate(labels):
a = data[c1][c2] / row_max if row_max and row_max != 0 else 0
Expand Down

0 comments on commit 5539848

Please sign in to comment.