source('tools/libs.R')
source('modules/Scorecards/Scorecards.R')

args = commandArgs(trailingOnly = TRUE)
recipe_file <- args[1]
output_dir <- args[2]

## TODO: Replace with function
# Read recipe and set outdir
recipe <- read_yaml(recipe_file)
recipe$Run$output_dir <- output_dir

## Loop over variables
datasets <- recipe$Analysis$Datasets
## TODO: Improve dependency system?
for (system in 1:length(datasets$System)) {
  for (reference in 1:length(datasets$Reference)) {
    for (variable in 1:length(recipe$Analysis$Variables)) {
      scorecard_recipe <- recipe 
      scorecard_recipe$Analysis$Datasets$System <- 
        recipe$Analysis$Datasets$System[[system]]
      scorecard_recipe$Analysis$Datasets$Reference <- 
        recipe$Analysis$Datasets$Reference[[reference]]
      scorecard_recipe$Analysis$Variables <-
        recipe$Analysis$Variables[[variable]]
      # Plot Scorecards
      Scorecards(scorecard_recipe)
    }
  }
}
print("##### SCORECARDS SAVED TO THE OUTPUT DIRECTORY #####")
