source("modules/Loading/Loading.R")
source("modules/Saving/Saving.R")
source("modules/Units/Units.R")
source("modules/Visualization/Visualization.R")

# OPTION 1. If running on terminal, use this:
args = commandArgs(trailingOnly = TRUE)
recipe_file <- "recipes/examples/recipe_full_crossval_anomalies.yml"
recipe <- prepare_outputs(recipe_file)

# OPTION 2. If using launch_SUNSET.sh, use this:
# args = commandArgs(trailingOnly = TRUE)
# recipe_file <- args[1]
# recipe <- read_atomic_recipe(recipe_file)

# Load datasets
data <- Loading(recipe)
data <- Units(recipe, data)

# Compute anomalies and thresholds in full cross-validation
source("modules/Crossval/Crossval_anomalies.R")
data <- Crossval_anomalies(recipe = recipe, data = data)

# Skill metrics
source("modules/Crossval/Crossval_metrics.R")
skill_metrics <- Crossval_metrics(recipe = recipe, data_crossval = data,
                                  fair = FALSE, nmemb = NULL, nmemb_ref = NULL)

Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics,
              significance = TRUE, probabilities = data$probs)
