code: def generate_forecasting_dataset(
      dataset_path: Path,
      dataset_name: str,
      dataset_writer: DatasetWriter,
      prediction_length: Optional[int] = None,
  ):
      dataset = datasets[dataset_name]
      dataset_path.mkdir(exist_ok=True)
  
      with TemporaryDirectory() as temp_dir:
          temp_path = Path(temp_dir)
  
          with ZipFile(dataset.download(temp_path)) as archive:
              archive.extractall(path=temp_path)
  
          # only one file is exptected
          reader = TSFReader(temp_path / archive.namelist()[0])
          meta, data = reader.read()
  
      freq = frequency_converter(meta.frequency)
      if prediction_length is None:
          if hasattr(meta, "forecast_horizon"):
              prediction_length = int(meta.forecast_horizon)
          else:
              prediction_length = (
                  default_prediction_length_from_frequency(freq)
              )
  
      # Impute missing start dates with unix epoch and remove time series whose
      # length is less than or equal to the prediction length
      data = [
          {
              **d,
              "start_timestamp": d.get("start_timestamp", "1970-01-01"),
          }
          for d in data
          if len(d[FieldName.TARGET]) > prediction_length
      ]
      train_data, test_data = convert_data(data, prediction_length)
  
      meta = MetaData(
          **metadata(
              cardinality=len(data),
              freq=freq,
              prediction_length=prediction_length,
          )
      )
  
      dataset = TrainDatasets(
          metadata=meta, train=train_data, test=test_data
      )
      dataset.save(
          path_str=str(dataset_path),
          writer=dataset_writer,
          overwrite=True,
      )
  
file_path: gluonts/src/gluonts/dataset/repository/_tsf_datasets.py
imports: from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import Dict, List, NamedTuple, Optional
  from urllib import request
  from zipfile import ZipFile
  from pandas.tseries.frequencies import to_offset
  from gluonts.dataset import DatasetWriter
  from gluonts.dataset.common import MetaData, TrainDatasets
  from gluonts.dataset.field_names import FieldName
  from gluonts.gluonts_tqdm import tqdm
  from ._tsf_reader import TSFReader, frequency_converter
  from ._util import metadata, request_retrieve_hook
label_desc: Use image node_id 2 for calling a global function with example usage: generate_forecasting_dataset(dataset_path, dataset_name, dataset_writer, prediction_length) without return types