
source("modules/Loading/Loading.R")
source("modules/Saving/Saving.R")
source("modules/Units/Units.R")
source("modules/Visualization/Visualization.R")
#args = commandArgs(trailingOnly = TRUE)
#recipe_file <- args[1]
recipe_file <- "recipe_tas.yml"
# Will it work with a single job?
#recipe <- read_atomic_recipe(recipe_file)
original_recipe <- prepare_outputs(recipe_file, disable_checks = TRUE)
# Load datasets
models <- unlist(original_recipe$Analysis$Datasets$System)
recipe_aux <- original_recipe
datos <- list()
datos$hcst <- list()
datos$fcst <- list()
for (sys in models) {
  recipe_aux$Analysis$Datasets$System <- NULL
  recipe_aux$Analysis$Datasets$System$name <- as.vector(sys)
  data <- Loading(recipe = recipe_aux)
  data <- Units(recipe_aux, data)
  datos$hcst <- append(datos$hcst, list(data$hcst))
  datos$fcst <- append(datos$fcst, list(data$fcst))
  names(datos$hcst)[length(datos$hcst)] <- gsub('\\.','', sys)
  names(datos$fcst)[length(datos$fcst)] <- gsub('\\.','', sys)
}
datos$obs <- data$obs
data <- datos
rm(list=list('datos'))

source("modules/Crossval/Crossval_anomalies.R")
res <- Crossval_anomalies(recipe = recipe, data = data)

source("modules/Crossval/Crossval_skill.R")
skill_metrics <- Crossval_skill(recipe = recipe, data_crossval = res,
                                fair = FALSE, nmemb = NULL, nmemb_ref = NULL) 

Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics, significance = TRUE)

## Check logo size is appropiated for your maps:
source("tools/add_logo.R")
add_logo(recipe, "rsz_rsz_bsc_logo.png")

# scorecards computation:


