code: def regrets(
      experiments,
      with_evc_tree=True,
      order_by="suggested",
      build_frame_fn=build_regrets_frame,
      return_var=False,
      title="Average Regret",
      **kwargs,
  ):
      """Plotly implementation of `orion.plotting.regrets`"""
  
      compute_average = bool(
          isinstance(experiments, dict)
          and isinstance(next(iter(experiments.values())), Iterable)
      )
  
      def build_groups():
          """Build dataframes for groups of experiments"""
          if compute_average:
              data_frames = dict()
              for name, group in experiments.items():
                  (
                      frames,
                      group_by,
                      average_keys,
                      x,
                      y,
                      x_title,
                  ) = build_frame_fn(
                      group,
                      with_evc_tree=with_evc_tree,
                      order_by=order_by,
                  )
  
                  df = orion.analysis.average(
                      frames,
                      group_by,
                      average_keys,
                      return_var=return_var,
                  )
  
                  if x in average_keys.split(","):
                      x = f"{x}_mean"
                  if y in average_keys.split(","):
                      y = f"{y}_mean"
  
                  df["name"] = [name] * len(df)
  
                  if "n_workers" not in df:
                      df["n_workers"] = [
                          group[0].executor.n_workers
                      ] * len(df)
  
                  data_frames[name] = df
              data_frames = pd.concat(data_frames)
          elif isinstance(experiments, dict):
              (
                  data_frames,
                  group,
                  average_keys,
                  x,
                  y,
                  x_title,
              ) = build_frame_fn(
                  experiments.values(),
                  list(experiments.keys()),
                  with_evc_tree=with_evc_tree,
                  order_by=order_by,
              )
          else:
              (
                  data_frames,
                  group,
                  average_keys,
                  x,
                  y,
                  x_title,
              ) = build_frame_fn(
                  experiments,
                  with_evc_tree=with_evc_tree,
                  order_by=order_by,
              )
  
          return data_frames, x, y, x_title
  
      def get_objective_name(experiments):
          """Infer name of objective based on trials of one experiment"""
          if compute_average and isinstance(experiments, dict):
              return get_objective_name(
                  sum(map(list, experiments.values()), [])
              )
  
          if isinstance(experiments, dict):
              experiments = experiments.values()
  
          for experiment in experiments:
              trials = experiment.fetch_trials_by_status("completed")
              if trials:
                  return trials[0].objective.name
          return "objective"
  
      ORDER_KEYS = ["suggested", "reserved", "completed", "objective"]
  
      if not experiments:
          raise ValueError("Parameter 'experiment' is None")
  
      if order_by not in ORDER_KEYS:
          raise ValueError(
              f"Parameter 'order_by' is not one of {ORDER_KEYS}"
          )
  
      df, x_col, y_col, x_title = build_groups()
      fig = go.Figure()
      if df.empty:
          return fig
  
      names = set(df["name"])
      for i, name in enumerate(sorted(names)):
          exp_data = df[df["name"] == name]
  
          y = exp_data[y_col]
          x = exp_data[x_col]
  
          duration, time_unit = infer_unit_time(exp_data, min_unit=3)
          if x_col in ["duration", "duration_mean"]:
              x = duration
              x_title = f"Experiment duration by {time_unit}"
  
          fig.add_scatter(
              x=x,
              y=y,
              mode="lines+markers",
              line=dict(color=px.colors.qualitative.G10[i]),
              name=name,
              legendgroup=name,
              customdata=list(zip(exp_data["n_workers"], duration)),
              hovertemplate=_template_regrets(name, time_unit),
          )
  
          if "best_var" in exp_data:
              dy = numpy.sqrt(exp_data["best_var"])
              fig.add_scatter(
                  x=list(x) + list(x)[::-1],
                  y=list(y - dy) + list(y + dy)[::-1],
                  fill="toself",
                  showlegend=False,
                  line=dict(color=px.colors.qualitative.G10[i]),
                  name=name,
                  legendgroup=name,
              )
  
      fig.update_layout(
          title=title,
          xaxis_title=x_title,
          yaxis_title=get_objective_name(experiments),
          hovermode="x",
      )
  
      return fig
  
imports: import functools
  from collections.abc import Iterable
  import numpy
  import pandas
  import plotly.express
  import plotly.graph_objects
  from plotly.subplots import make_subplots
  import orion.analysis
  import orion.analysis.base
  from orion.algo.space import Categorical, Fidelity
  from orion.core.worker.transformer import build_required_space
label_desc: Use image node_id 10 for calling a global function with example usage: regrets(experiments, with_evc_tree, order_by, build_frame_fn, return_var, title) and returns: fig, data_frames,  x,  y,  x_title, str, fig, get_objective_name, trials