code: def plot_traffic_lights_alerts_aggregate(
      feature,
      data,
      metrics: list[str],
      labels: list[str],
      tl_colors: dict[str, str],
  ):
      assert data.shape[0] == 3
  
      # Reorder metrics if needed
      pos_green = metrics.index("n_green")
      pos_yellow = metrics.index("n_yellow")
      pos_red = metrics.index("n_red")
  
      if [pos_green, pos_yellow, pos_red] != [0, 1, 2]:
          data[[0, 1, 2]] = data[[pos_green, pos_yellow, pos_red]]
  
      metrics = ["# green", "# yellow", "# red"]
      data = data.astype(int)
  
      green = hex_to_rgb(tl_colors["green"])
      yellow = hex_to_rgb(tl_colors["yellow"])
      red = hex_to_rgb(tl_colors["red"])
  
      colors: defaultdict[str, dict[str, list[str]]] = defaultdict(dict)
      for c1, metric in enumerate(metrics):
          row_max = np.max(data[c1])
          for c2, label in enumerate(labels):
              a = (
                  np.round(data[c1][c2] / row_max, 2)
                  if row_max and row_max != 0
                  else 0
              )
              if metric.endswith("green"):
                  background_rgba = (*green, a)
              elif metric.endswith("yellow"):
                  background_rgba = (*yellow, a)
              else:
                  background_rgba = (*red, a)
              background_rgba = (str(v) for v in background_rgba)
              text_color = "white" if a > 0.5 else "black"
              colors[metric][label] = (
                  text_color,
                  background_rgba,
                  data[c1][c2],
              )
  
      return templates_env(
          "table.html",
          feature=feature,
          metrics=metrics,
          labels=labels,
          data=colors,
          links=False,
      )
  
imports: from __future__ import annotations
  import datetime
  import json
  import logging
  import math
  import warnings
  from collections import defaultdict
  import numpy
  import pandas
  import plotly.express
  import plotly.graph_objects
  from popmon.resources import templates_env
label_desc: Use image node_id 8 for calling a global function with example usage: plot_traffic_lights_alerts_aggregate(feature, data, metrics, labels, tl_colors) and returns: templates_env