code: def compute_stats(
      dataset: Optional[str], data_path: str, output_path: str
  ):
      """
      Computes simple dataset features either for a single dataset or all
      datasets in the registry.
      """
      source = Path(data_path)
      target = Path(output_path)
      target.mkdir(parents=True, exist_ok=True)
  
      if dataset is None:
          dataset_list = list(DATASET_REGISTRY.items())
      else:
          dataset_list = [(dataset, DATASET_REGISTRY[dataset])]
  
      for dataset_name, config in tqdm(dataset_list):
          file = target / f"{dataset_name}.json"
          if file.exists():
              continue
  
          stats = calculate_dataset_statistics(
              config(source).data.train(val=False).gluonts()
          )
          with file.open("w+") as f:
              json.dump(
                  {
                      "integer_dataset": stats.integer_dataset,
                      "mean_target_length": stats.mean_target_length,
                      "num_time_observations": stats.num_time_observations,
                      "num_time_series": stats.num_time_series,
                  },
                  f,
              )
  
file_path: gluonts/src/gluonts/nursery/tsbench/src/cli/datasets/compute_stats.py
imports: import json
  from pathlib import Path
  from typing import Optional
  import click
  from gluonts.dataset.stat import calculate_dataset_statistics
  from tqdm.auto import tqdm
  from tsbench.config import DATASET_REGISTRY
  from tsbench.constants import DEFAULT_DATA_PATH, DEFAULT_DATA_STATS_PATH
  from ._main import datasets
label_desc: Use image node_id 1 for calling a global function with example usage: compute_stats(dataset, data_path, output_path) without return types