code: def get_merged_metric_tracking_util(
      track_data_list, preference_data, is_metric_summary
  ):
      if (
          is_metric_summary
          and len(track_data_list) > 0
          and len(preference_data) == len(track_data_list[0])
      ):
          for j in range(0, len(track_data_list)):
              track_data = track_data_list[j]
              filtered_track_data = []
              for i in range(len(track_data)):
                  filtered_track_data.append(track_data[i])
                  if preference_data[i] == -1:
                      filtered_track_data[-1][
                          "value"
                      ] = filtered_track_data[-1]["value"][-1:]
                      filtered_track_data[-1][
                          "step"
                      ] = filtered_track_data[-1]["step"][-1:]
                      filtered_track_data[-1][
                          "smoothed"
                      ] = filtered_track_data[-1]["smoothed"][-1:]
                      filtered_track_data[-1]["is_summary"] = True
                  else:
                      filtered_track_data[-1]["is_summary"] = False
              track_data_list[j] = filtered_track_data
      else:
          for j in range(0, len(track_data_list)):
              track_data = track_data_list[j]
              filtered_track_data = []
              for i in range(len(track_data)):
                  filtered_track_data.append(track_data[i])
                  filtered_track_data[-1]["is_summary"] = False
  
      series_list = {}
      for track_data in track_data_list:
          for track_item in track_data:
              if track_item["name"] not in series_list:
                  series_list[track_item["name"]] = {
                      "step": [],
                      "value": [],
                  }
  
              series_list[track_item["name"]]["step"].append(
                  track_item["step"]
              )
              series_list[track_item["name"]]["value"].append(
                  track_item["value"]
              )
  
      merged_list = []
  
      for key in series_list:
          step_list = series_list[key]["step"]
          value_list = series_list[key]["value"]
          length = max([len(v) for v in value_list if v is not None])
          num_series = len(step_list)
  
          steps = []
          values = []
          for i in range(length):
              value_sum = 0
              step_sum = 0
              count = 0
              for j in range(num_series):
                  if i >= len(value_list[j]):
                      continue
                  value_sum += value_list[j][i]
                  step_sum += step_list[j][i]
                  count += 1
              steps.append(step_sum / count)
              values.append(value_sum / count)
  
          s = Series()
          s.update(list(steps), list(values))
          details = s.detail
          details["name"] = key
          merged_list.append(details)
  
      is_metric_summary = (
          is_metric_summary
          and len(track_data_list) > 0
          and len(preference_data) == len(track_data_list[0])
      )
  
      for i in range(len(merged_list)):
          merged_list[i]["is_summary"] = (
              True
              if is_metric_summary and (preference_data[i] == -1)
              else False
          )
  
      return merged_list
  
file_path: labml/app/server/labml_app/analyses/experiments/distributed_metrics.py
imports: from typing import Any, Optional
  from fastapi import Request
  from fastapi.responses import JSONResponse
  from labml_db import Model, Index
  from labml_db.serializer.pickle import PickleSerializer
  from labml_db.serializer.yaml import YamlSerializer
  from ..analysis import Analysis
  from .None import metrics
  from ..preferences import Preferences
  from ..series import Series
  from ...logger import logger
  from ...db import run
  from ...utils import get_default_series_preference, fill_preferences
label_desc: Use image node_id 1 for calling a global function with example usage: get_merged_metric_tracking_util(track_data_list, preference_data, is_metric_summary) and returns: merged_list