code: def get_experiments_history_best(label):
      with sql.connect(
          app.app.config["db_file"], check_same_thread=False
      ) as con:
          sortby = request.args.get("sortby", "jid")
          cur = con.cursor()
          eids = query_db(cur, "SELECT eid from experiment;")
          result = dict()
          for eid in eids:
              eid = eid["eid"]
              cur.execute(
                  "SELECT json_extract(exp_config, '$.target') from experiment where eid={eid};".format(
                      eid=eid
                  )
              )
              order = str(cur.fetchone()[0])
              order = fix_none_res(order, "max")
  
              list_mult_res_labels = None
              label_order = None
              if label is not None:
                  mult_res_labels = query_db(
                      cur,
                      "SELECT JSON_EXTRACT(exp_config, '$.resource_args.multi_res_labels') AS labels \
                                              FROM experiment WHERE eid=?",
                      (eid,),
                  )
                  mult_res_labels = mult_res_labels[0]
  
                  if (
                      mult_res_labels is not None
                      and mult_res_labels["labels"] is not None
                  ):
                      list_mult_res_labels = json.loads(
                          mult_res_labels["labels"]
                      )
                      try:
                          label_order = (
                              list_mult_res_labels.index(label) + 1
                          )
                      except ValueError:
                          continue
  
                  if list_mult_res_labels is None:
                      continue
  
              (start_job, num_jobs) = get_valid_jobs_interval(cur, eid)
  
              result[eid] = list()
              for i in range(1, num_jobs + 1):
                  best_job = None
                  if label is None:
                      best_job = query_db(
                          cur,
                          "SELECT jid, {order}(score) as score, job_config, start_time, end_time from \
                                  (SELECT * from job where eid={eid} and jid >= {start_job} order by {sortby} limit 0,{start}) \
                                  WHERE typeof(score) == 'real';".format(
                              order=order,
                              eid=eid,
                              start=i,
                              sortby=sortby,
                              start_job=start_job,
                          ),
                      )
                  elif (
                      list_mult_res_labels is not None
                      and label_order is not None
                  ):
                      if sortby == "end_time":
                          sortby = "receive_time"
                      best_job = query_db(
                          cur,
                          "SELECT jid, {order}(value) as score, (SELECT job_config FROM job WHERE jid=jidm) as job_config FROM \
                                          (SELECT *, jid AS jidm FROM multiple_result WHERE eid={eid} AND \
                                          jid >= {start_job} AND label_order={label_order} AND is_last_result=1 ORDER BY {sortby} LIMIT 0,{start})".format(
                              order=order,
                              eid=eid,
                              start=i,
                              start_job=start_job,
                              label_order=label_order,
                              sortby=sortby,
                          ),
                      )
                  if (
                      best_job is not None
                      and best_job[0]["jid"] is None
                  ):
                      continue
  
                  is_compression_exp = is_compression_experiment(
                      cur=cur, eid=eid
                  )
                  if is_compression_exp:
                      params = get_params_for_experiment(cur, eid)
                      display_names = get_display_names(
                          params, eid=eid, cur=cur
                      )
                      job_configs = fix_compression_job_config(
                          [
                              {"job_config": job["job_config"]}
                              for job in best_job
                          ],
                          params,
                          display_names,
                      )
                      best_job = [
                          {
                              "job_config": json.dumps(
                                  job_configs[idx]
                              ),
                              **{
                                  key: val
                                  for key, val in job.items()
                                  if key != "job_config"
                              },
                          }
                          for idx, job in enumerate(best_job)
                      ]
  
                  result[eid].append(best_job[0])
          return jsonify({"experiment_history_best": result})
      return None
  
imports: from flask import render_template, jsonify, request
  from flask_cors import CORS
  import connexion
  import click
  import logging
  import sys
  import sqlite3
  import os
  import os.path
  from six.moves.configparser import ConfigParser
  import json
  import signal
  import multiprocessing
  from aup.compression.utils import SERIALIZATION_SEPARATOR, run_non_automatic_experiment, verify_compression_config, adjust_compression_config
  from aup.setup import setup
  from aup.utils import get_default_username, set_default_keyvalue
  from ..ET.Connector.SQLiteConnector import SQLiteConnector
  from ..EE.Experiment import Experiment
  from ..aup import BasicConfig
  from aup.Proposer import get_proposer
  from threading import Lock
label_desc: Use image node_id 17 for calling a global function with example usage: get_experiments_history_best(label) and returns: None, jsonify