C-Dash: Add multiple telemetry panels
[csit.git] / csit.infra.dash / app / cdash / trending / graphs.py
index 7d74775..7b14501 100644 (file)
@@ -389,8 +389,8 @@ def graph_tm_trending(
         :rtype: list
         """
         traces = list()
-        nr_of_metrics = len(data.tm_metric.unique())
-        for idx, metric in enumerate(data.tm_metric.unique()):
+        metrics = data.tm_metric.unique().tolist()
+        for idx, metric in enumerate(metrics):
             if "-pdr" in test and "='pdr'" not in metric:
                 continue
             if "-ndr" in test and "='ndr'" not in metric:
@@ -449,7 +449,7 @@ def graph_tm_trending(
             else:
                 anomalies = None
             if all_in_one:
-                color = get_color(color_index * nr_of_metrics + idx)
+                color = get_color(color_index * len(metrics) + idx)
                 metric_name = f"{test}<br>{metric}"
             else:
                 color = get_color(idx)
@@ -543,7 +543,10 @@ def graph_tm_trending(
                     )
                 )
 
-        return traces
+        unique_metrics = set()
+        for itm in metrics:
+            unique_metrics.add(itm.split("{", 1)[0])
+        return traces, unique_metrics
 
     tm_trending_graphs = list()
     graph_layout = layout.get("plot-trending-telemetry", dict())
@@ -551,22 +554,26 @@ def graph_tm_trending(
     if all_in_one:
         all_traces = list()
 
+    all_metrics = set()
+    all_tests = list()
     for idx, test in enumerate(data.test_name.unique()):
         df = data.loc[(data["test_name"] == test)]
-        traces = _generate_traces(df, test, all_in_one, idx)
+        traces, metrics = _generate_traces(df, test, all_in_one, idx)
         if traces:
+            all_metrics.update(metrics)
             if all_in_one:
                 all_traces.extend(traces)
+                all_tests.append(test)
             else:
                 graph = go.Figure()
                 graph.add_traces(traces)
                 graph.update_layout(graph_layout)
-                tm_trending_graphs.append((graph, test, ))
+                tm_trending_graphs.append((graph, [test, ], ))
 
     if all_in_one:
         graph = go.Figure()
         graph.add_traces(all_traces)
         graph.update_layout(graph_layout)
-        tm_trending_graphs.append((graph, str(), ))
+        tm_trending_graphs.append((graph, all_tests, ))
 
-    return tm_trending_graphs
+    return tm_trending_graphs, all_metrics