# Seasonal monthly data

# rm(list=ls())
# gc()
source("modules/Loading/Loading.R")
source("modules/Units/Units.R")
source("modules/Calibration/Calibration.R")
source("modules/Skill/Skill.R")
source("modules/Anomalies/Anomalies.R")
source("modules/Saving/Saving.R")
source("modules/Visualization/Visualization.R")

recipe_file <- "tests/recipes/recipe-seasonal_visualization.yml"
recipe <- prepare_outputs(recipe_file, disable_checks = F)

# Load datasets
suppressWarnings({invisible(capture.output(
  data <- Loading(recipe)
))})

# Units transformation
suppressWarnings({invisible(capture.output(
  data <- Units(recipe, data)
))})

# Calibrate data
suppressWarnings({invisible(capture.output(
  data <- Calibration(recipe, data)
))})

# Compute skill metrics
suppressWarnings({invisible(capture.output(
  skill_metrics <- Skill(recipe, data)
))})

# Compute percentiles and probability bins
suppressWarnings({invisible(capture.output(
  probs <- Probabilities(recipe, data)
))})


# ------- TESTS --------

# testthat::test_file("tests/testthat/test-seasonal_visualization.R")

recipe$Analysis$Workflow$Visualization$file_format <- 'PNG'
recipe$Analysis$Workflow$Visualization$projection <- 'Robinson'
recipe$Analysis$Workflow$Visualization$plots <- 'skill_metrics'

save_fun <- function(...) {
  path <- tempfile(fileext = ".png")
  do.call(Visualization, list(...))
  path
}


test_that("1. Output checks - prova", {

  expect_snapshot_file(
    save_fun(recipe = recipe, data = data, skill_metrics = skill_metrics,
             probabilities = probabilities, significance = 'dots'),
    name = 'rpss-june_ft01_dots.png'
  )

})
