code: def calculate_metrics(
      timeseries,
      evaluator,
      ts_datastructure,
      has_nans=False,
      forecaster=naive_forecaster,
      input_type=iter,
  ):
      num_timeseries = timeseries.shape[0]
      num_timestamps = timeseries.shape[1]
  
      if has_nans:
          timeseries[0, 1] = np.nan
          timeseries[0, 7] = np.nan
  
      num_samples = 100
      prediction_length = 3
      freq = "1D"
  
      ts_start_dates = (
          []
      )  # starting date of each time series - can be different in general
      pd_timeseries = []  # list of pandas.DataFrame
      samples = []  # list of forecast samples
      start_dates = []  # start date of the prediction range
      for i in range(num_timeseries):
          ts_start_dates.append(
              pd.Period("2018-01-01 01:00:00", freq=freq)
          )
          index = pd.period_range(
              ts_start_dates[i], periods=num_timestamps, freq=freq
          )
  
          pd_timeseries.append(
              ts_datastructure(timeseries[i], index=index)
          )
          samples.append(
              forecaster(
                  pd_timeseries[i], prediction_length, num_samples
              )
          )
          start_dates.append(
              pd.period_range(
                  ts_start_dates[i], periods=num_timestamps, freq=freq
              )[-prediction_length]
          )
  
      # data iterator
      data_iter = input_type(data_iterator(pd_timeseries))
      fcst_iter = input_type(fcst_iterator(samples, start_dates))
  
      # evaluate
      agg_df, item_df = evaluator(data_iter, fcst_iter)
      return agg_df, item_df
  
file_path: gluonts/test/evaluation/test_evaluator.py
imports: import numpy
  import pandas
  import pytest
  from gluonts.evaluation import Evaluator, MultivariateEvaluator, aggregate_valid
  from gluonts.model.forecast import QuantileForecast, SampleForecast
label_desc: Use image node_id 5 for calling a global function with example usage: calculate_metrics(timeseries, evaluator, ts_datastructure, has_nans, forecaster, input_type) and returns: agg_df,  item_df