code: def prepare_stats(start_ts, trainer, evaluator):
      def tensor_to_list(d):
          r = dict()
          for dk, dv in d.items():
              r[dk] = dv.tolist() if torch.is_tensor(dv) else dv
          return r
  
      stats: Dict[str, Any] = dict()
      stats.update(trainer.get_stats())
      stats["epoch"] = trainer.state.epoch
      stats["start_ts"] = int(start_ts)
  
      if trainer.state.epoch == trainer.state.max_epochs:
          stats["total_time"] = str(
              datetime.timedelta(seconds=int(time.time() - start_ts))
          )
      else:
          stats["current_time"] = str(
              datetime.timedelta(seconds=int(time.time() - start_ts))
          )
  
      for k, v in {"train": trainer, "eval": evaluator}.items():
          if not v:
              continue
  
          stats["best_metric"] = v.state.best_metric
          stats[k] = {
              "metrics": tensor_to_list(v.state.metrics),
              "key_metric_name": v.state.key_metric_name,
              "best_metric": v.state.best_metric,
              "best_metric_epoch": v.state.best_metric_epoch,
          }
      return stats
  
file_path: MONAILabel/monailabel/tasks/train/handler.py
imports: import datetime
  import filecmp
  import json
  import logging
  import os
  import shutil
  import time
  from typing import Any, Dict
  import torch
  from monai.engines.workflow import Engine, Events
label_desc: Use image node_id 1 for calling a global function with example usage: prepare_stats(start_ts, trainer, evaluator) and returns: stats, r