code: def generate_lstnet_dataset(
      dataset_path: Path,
      dataset_name: str,
      dataset_writer: DatasetWriter,
      prediction_length: Optional[int] = None,
  ):
      ds_info = datasets_info[dataset_name]
  
      time_index = pd.period_range(
          start=ds_info.start_date,
          freq=ds_info.freq,
          periods=ds_info.num_time_steps,
      )
  
      df = cast(
          pd.DataFrame,
          pd.read_csv(ds_info.url, header=None),  # type: ignore
      )
  
      assert df.shape == (
          ds_info.num_time_steps,
          ds_info.num_series,
      ), (
          "expected num_time_steps/num_series"
          f" {(ds_info.num_time_steps, ds_info.num_series)} but got {df.shape}"
      )
  
      timeseries = load_from_pandas(
          df=df, time_index=time_index, agg_freq=ds_info.agg_freq
      )
  
      # the last date seen during training
      ts_index = cast(pd.PeriodIndex, timeseries[0].index)
      training_end = ts_index[int(len(ts_index) * (8 / 10))]
  
      train_ts = []
      for cat, ts in enumerate(timeseries):
          sliced_ts = ts[:training_end]
          if len(sliced_ts) > 0:
              train_ts.append(
                  {
                      "target": sliced_ts.values,
                      "start": sliced_ts.index[0],
                      "feat_static_cat": [cat],
                      "item_id": cat,
                  }
              )
  
      assert len(train_ts) == ds_info.num_series
  
      # time of the first prediction
      prediction_dates = [
          training_end + i * ds_info.prediction_length
          for i in range(ds_info.rolling_evaluations)
      ]
  
      test_ts = []
      for prediction_start_date in prediction_dates:
          for cat, ts in enumerate(timeseries):
              # print(prediction_start_date)
              prediction_end_date = (
                  prediction_start_date + ds_info.prediction_length
              )
              sliced_ts = ts[:prediction_end_date]
              test_ts.append(
                  {
                      "target": sliced_ts.values,
                      "start": sliced_ts.index[0],
                      "feat_static_cat": [cat],
                      "item_id": cat,
                  }
              )
  
      assert (
          len(test_ts)
          == ds_info.num_series * ds_info.rolling_evaluations
      )
  
      meta = MetaData(
          **metadata(
              cardinality=ds_info.num_series,
              freq=ds_info.freq
              if ds_info.agg_freq is None
              else ds_info.agg_freq,
              prediction_length=prediction_length
              or ds_info.prediction_length,
          )
      )
  
      dataset = TrainDatasets(
          metadata=meta, train=train_ts, test=test_ts
      )
      dataset.save(
          path_str=str(dataset_path),
          writer=dataset_writer,
          overwrite=True,
      )
  
file_path: gluonts/src/gluonts/dataset/repository/_lstnet.py
imports: from pathlib import Path
  from typing import List, NamedTuple, Optional, cast
  import pandas
  from gluonts.dataset import DatasetWriter
  from gluonts.dataset.common import MetaData, TrainDatasets
  from gluonts.dataset.repository._util import metadata
label_desc: Use image node_id 2 for calling a global function with example usage: generate_lstnet_dataset(dataset_path, dataset_name, dataset_writer, prediction_length) without return types