code: def calculate_scores_and_build_plots(
      input_dir: str, output_dir: str, automl_settings: Dict[str, Any]
  ):
      os.makedirs(output_dir, exist_ok=True)
      grains = automl_settings.get(
          constants.TimeSeries.GRAIN_COLUMN_NAMES
      )
      time_column_name = automl_settings.get(
          constants.TimeSeries.TIME_COLUMN_NAME
      )
      if grains is None:
          grains = []
      if isinstance(grains, str):
          grains = [grains]
      while BACKTEST_ITER in grains:
          grains.remove(BACKTEST_ITER)
  
      dfs = []
      for fle in os.listdir(input_dir):
          file_path = os.path.join(input_dir, fle)
          if os.path.isfile(file_path) and file_path.endswith(".csv"):
              df_iter = pd.read_csv(
                  file_path, parse_dates=[time_column_name]
              )
              for _, iteration in df_iter.groupby(BACKTEST_ITER):
                  dfs.append(iteration)
      forecast_df = pd.concat(dfs, sort=False, ignore_index=True)
      # To make sure plots are in order, sort the predictions by grain and iteration.
      ts_index = grains + [BACKTEST_ITER]
      forecast_df.sort_values(by=ts_index, inplace=True)
      pdf = PdfPages(os.path.join(output_dir, PLOTS_FILE))
      for _, one_forecast in forecast_df.groupby(ts_index):
          _draw_one_plot(one_forecast, time_column_name, grains, pdf)
      pdf.close()
      forecast_df.to_csv(
          os.path.join(output_dir, FORECASTS_FILE), index=False
      )
      # Remove np.NaN and np.inf from the prediction and actuals data.
      forecast_df.replace([np.inf, -np.inf], np.nan, inplace=True)
      forecast_df.dropna(subset=[ACTUALS, PREDICTIONS], inplace=True)
      metrics = compute_all_metrics(
          forecast_df, grains + [BACKTEST_ITER]
      )
      metrics.to_csv(os.path.join(output_dir, SCORES_FILE), index=False)
  
file_path: MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/forecasting-backtest-single-model/assets/score.py
imports: from typing import Any, Dict, Optional, List
  import argparse
  import json
  import os
  import re
  import numpy
  import pandas
  from matplotlib import pyplot
  from matplotlib.backends.backend_pdf import PdfPages
  from azureml.automl.core.shared import constants
  from azureml.automl.core.shared.types import GrainType
  from azureml.automl.runtime.shared.score import scoring
label_desc: Use image node_id 5 for calling a global function with example usage: calculate_scores_and_build_plots(input_dir, output_dir, automl_settings) without return types